Repository navigation
Description
Problem Description
The AI spend dashboard (k8s/devops/dashboards/ai-spend.json, panels "Spend per Hour by Backend Server" and "Local Savings per Hour by Backend Server") names its series with the legend {{backend}} via {{server}} ({{provider}}). The series of hosted models have an empty backend label, so their legend reads " via ai.retric.click (gateway)" or " via llm-gateway.llm.svc.cluster.local:4000 (gateway)". The owner read these names as parse failures. The data is correct, but the series do not say which provider served the call.
Evidence (Prometheus, sum by (server, backend, provider, model) (increase(devops_cli_ai_requests_total{cached="false"}[24h])), 2026-11-13):
- Each Ollama series has a backend, for example
ollama-48gib-fastforqwen3.8:27b. deepseek-v4.1-flash-1017(gateway deploymentopenrouter/deepseek/deepseek-v4.1-flash-1017:floor) has nobackendlabel: about 4,400 requests in 24 hours on the two servers.- The Anthropic and Gemini groups have the same gap whenever they run.
Cause
record_requestinai/spend/ledger.pysets the metric labelbackendwithbackend_name(served_by)(telemetry/instruments.py).served_bycomes from the gateway headerx-litellm-model-api-base(CONST_AI_GATEWAY_SERVED_BY_HEADER, read byextract_served_byinai/client/network.py).- LiteLLM sends an API base only for a deployment that sets
api_base, such as an Ollama deployment. A hosted deployment uses the default base of its provider, so the header is missing andbackend_namereturns an empty string. - The same code already reads the deployment model of the reply from
x-litellm-model-name(served_model), for exampleopenrouter/deepseek/...oranthropic/claude-sonnet-5-5. Its LiteLLM provider prefix names the provider that served the call.
Proposed Fix
- When
served_bynames no backend andserved_modelhas a LiteLLM provider prefix (openrouter/,anthropic/,gemini/and the other prefixes of the pinned LiteLLM), setbackendto that prefix. - Use one helper for the metric labels and for the ledger row, so the two stay the same.
- Do not invent a backend when both headers are missing: keep the empty label.
- Check the legend of both dashboard panels after the change. A hosted series must read, for example,
openrouter via ai.retric.click (gateway).
Acceptance Criteria
- A test of
record_requestwithserved_by=Noneandserved_model="openrouter/deepseek/deepseek-v4.1-flash-1017:floor"gives the metric labelbackend="openrouter"(devops ci fail-to-pass). - A test with
served_model="anthropic/claude-sonnet-5-5"givesbackend="anthropic". A test with an Ollamaserved_bykeeps the host label, for exampleollama-48gib-fast. - A test with neither header keeps
backend="". - After the release, the Prometheus query above shows no hosted series with an empty
backendlabel.
Related
#2040, #2080, #3656 and #4907 set the local and hosted split of a gateway call. This issue only names the backend.
Alternatives check of 2026-11-23: in-use.
The repository already uses this tool.
Tool: litellm (https://pypi.org/project/litellm), MIT, last activity 2026-11-20, maintained.
Reason: Searches found only LiteLLM, which the project already runs as its gateway: it sends the provider-prefixed model name, but it sets no backend label, so the project still needs its own helper for metric and ledger.
Covers:
- Reply header carries the deployment model name
- Provider-prefixed model strings such as openrouter/ and anthropic/
- Model API base header for deployments that set api_base
Lacks:
- No backend label on the metric or the ledger row
- No mapping of a provider prefix into the project's label value
- No shared helper for metric label and ledger row
Proposed design
Problem statement
A gateway call to a hosted model has an empty backend label on devops_cli_ai_requests_total and an empty backend in the spend ledger. LiteLLM sends the x-litellm-model-api-base header only for a deployment that sets api_base, so backend_name(served_by) returns an empty string for the openrouter, anthropic and gemini deployments. The owner reads the empty name as a parse failure. The change names the LiteLLM provider of the x-litellm-model-name header when the host header is absent.
Acceptance criteria
Requirement: A hosted call names its provider on the metric
record_request SHALL set the backend label of devops_cli_ai_requests_total to the LiteLLM provider of served_model when served_by names no backend.
Scenario: OpenRouter deployment with no API base
- WHEN A test calls
record_requestwithserved_by=Noneandserved_model="openrouter/deepseek/deepseek-v4.1-flash-1017:floor". - THEN The test reads the metric and asserts the
backendlabel isopenrouter.
Requirement: The ledger row and the metric share one backend
record_request MUST take the backend of the ledger row and of the metric label from one helper, so the two values are equal.
Scenario: Ledger row of a hosted call
- WHEN A test calls
record_requestwithserved_by=Noneandserved_model="openrouter/deepseek/deepseek-v4.1-flash-1017:floor". - THEN The test asserts the ledger row backend is
openrouterand equals the metricbackendlabel.
Requirement: Each hosted provider prefix names that provider
The helper SHALL name the provider of every hosted prefix, such as anthropic and gemini, from the first segment of served_model.
Scenario: Anthropic deployment with no API base
- WHEN A test calls
record_requestwithserved_by=Noneandserved_model="anthropic/claude-sonnet-5-5". - THEN The test asserts the
backendlabel isanthropic.
Requirement: An Ollama call keeps its host label
The helper SHALL return the host of served_by before it reads the provider prefix of served_model.
Scenario: Ollama deployment that sets an API base
- WHEN A test calls
record_requestwithserved_by="http://ollama-48gib-fast.llm.svc.cluster.local:11434"andserved_model="ollama_chat/qwen3.8:27b". - THEN The test asserts the
backendlabel isollama-48gib-fast, notollama_chat.
Requirement: No header names no backend
The helper MUST return an empty backend when served_by is empty and served_model has no provider prefix.
Scenario: A reply with no host and no provider prefix
- WHEN A test calls
record_requestwithserved_by=Noneandserved_model="qwen3.8:27b". - THEN The test asserts the
backendlabel is the empty string.
Existing Tool Considered
litellm (https://pypi.org/project/litellm), MIT and maintained, has the verdict in-use in the alternatives check of 2026-11-17 in the issue body. The check there records what litellm covers and what it lacks. The proposal adds the part that litellm lacks. One helper in src/devops_cli/telemetry/instruments.py returns the served_by host first, else the provider prefix of served_model. record_request uses that helper for the metric label and for the ledger row. The change imports no new dependency and keeps the host label of an Ollama deployment.
Key questions
- Where does the
backendlabel ofdevops_cli_ai_requests_totalcome from?:record_requestinsrc/devops_cli/ai/spend/ledger.pysets it frombackend_name(served_by)insrc/devops_cli/telemetry/instruments.py.served_byis thex-litellm-model-api-baseheader,CONST_AI_GATEWAY_SERVED_BY_HEADERatsrc/devops_cli/config/constants.py:3160, whichextract_served_byinsrc/devops_cli/ai/client/network.py:103reads. A hosted deployment sets noapi_base, so the header is absent andbackend_namereturns the empty string. [sources: src/devops_cli/ai/spend/ledger.py, src/devops_cli/telemetry/instruments.py:1049, src/devops_cli/ai/client/network.py:103, src/devops_cli/config/constants.py:3160] - Which value names the provider of a hosted gateway call?: The first segment of
served_model, the deployment model thatx-litellm-model-namecarries:openrouterinopenrouter/deepseek/deepseek-v4.1-flash-1017:floor. The helper returns that segment whenserved_byis empty and the model holds a/. It returns the empty string when the model holds no/. The value is the provider name that the gateway'sapi_providerlabel holds, which the panelSpend by provider and model: USD per hourreads. (best practice) [sources: src/devops_cli/ai/client/network.py:103, k8s/devops/dashboards/ai-spend.json]- Chosen: The first segment of
served_model. It matches the<provider>/<model>form of a LiteLLM deployment, covers a new provider with no list to keep, and invents no label when the model has no prefix. - Rejected: A fixed list of the openrouter, anthropic and gemini prefixes. A new hosted provider gets the empty label again, which is the defect that this item fixes.
- Rejected:
litellm.utils.get_llm_provider. The alternatives check records the large dependency and no change to the label or the ledger row, and the CLI reads one header, so the mapping is one string split.
- Chosen: The first segment of
- Where does the one helper for the metric label and the ledger row live?:
backend_label(served_by, served_model)lives insrc/devops_cli/telemetry/instruments.py, besidebackend_name, whichsrc/devops_cli/ai/spend/ledger.pyalready calls.record_requestcalls it once and uses the result for the metric label and for the ledger row. The helper takes two strings and imports no module of the AI client. (best practice) [sources: src/devops_cli/telemetry/instruments.py:1049, src/devops_cli/ai/spend/ledger.py]- Chosen:
src/devops_cli/telemetry/instruments.py, besidebackend_name. The module holds the vocabulary of the metric label, and its caller in the ledger keeps one path to the value. - Rejected:
src/devops_cli/ai/spend/ledger.py. A second caller of the label would copy the rule, and the metric instrument already holdsbackend_name. - Rejected:
src/devops_cli/ai/client/network.py, besideextract_served_by. That module reads headers and holds no metric label, so the label rule does not belong there.
- Chosen:
- Do the two dashboard panels still read the
backendlabel ofdevops_cli_ai_requests_total?: No. The reply records that fix(monitoring): read AI spend from the gateway counter #5924 changed the first panel toSpend by provider and model: USD per hour, which readsapi_provideroflitellm_spend_metric_total. The reply also records that fix(monitoring): price local savings at the reference model #5931 for fix(monitoring): price local savings at the reference model #5914 changed the local savings panel to read the gateway token counters and to name each bar from theapi_baseservice.k8s/devops/dashboards/ai-spend.jsonholds both queries. The dashboard legend step is therefore out of this proposal, and it is not deferred, because no work remains there. [sources: k8s/devops/dashboards/ai-spend.json] - Does the post-release Prometheus query stay an acceptance criterion?: No. The query needs the release on the cluster and a person to read Prometheus, so it cannot pass before the merge. The tests of
record_requesthold the label of the metric and of the ledger row. The live query moves to a follow-up issue, and this item reaches Ready on the tests alone. (best practice) [sources: tests/ai/spend/test_ai_spend_ledger.py]- Rejected: Keep the Prometheus query as an acceptance criterion. No offline test checks it, and a criterion must pass before the merge.
- Chosen: Move the live query to a follow-up issue. The query waits on the release and on a person, and the offline tests already hold the label.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 13, 2026
The data is correct and only the dashboard legend is misleading, so this is a low-urgency fix.Both concern the backend label in the spend ledger, but #474 delivered the initial recording while this candidate fixes a gap where hosted models get an empty backend.dan-petty commentedon Nov 16, 2026
The two dashboard panels of this item no longer read devops-cli's
backendlabel. #5924 changed "Spend per Hour by Backend Server" to "Spend by provider and model: USD per hour", which readsapi_providerof the gateway'slitellm_spend_metric_total. Pull request #5931 (for #5914) changes "Local Savings per Hour by Backend Server" to read the gateway token counters, and names each bar by the service of itsapi_base. So the step "check the legend of both dashboard panels" does not apply after the merge. The fix ofrecord_requestand its criteria still apply todevops_cli_ai_requests_totaland the spend ledger.devops-cli-service commentedon Nov 17, 2026
Alternatives check: in-use
Reason: Searches found only LiteLLM: its provider map turns a served-model prefix into a provider name, covering the mapping but not the metric label, ledger row or dashboard.
The repository already uses this tool.
Tool: litellm (https://pypi.org/project/litellm), MIT, last activity 2026-11-12, maintained.
Covers:
Lacks:
Searches (10)
Tools considered:
Searches run:
Sources:
A person decides what this check of 2026-11-17 means for the item.
devops-cli-service commentedon Nov 20, 2026
Next step: the stage job writes the plan of the item. See Moved to new items in the section Proposed design of the body.
fix(ai): a hosted gateway call names its provider as backend (#5546)
chore(main): release 0.248.0 (#7763)
devops-cli-service commentedon Nov 29, 2026
Released in v0.248.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.248.0
devops-cli-service commentedon Nov 29, 2026
Live since 2026-11-29 16:50 UTC