Repository navigation
Description
Problem Description
A call to a hosted gateway group (claude-sonnet-5-5, claude-haiku-5-5, deepseek-v4.1-flash-1017) is recorded as a local call with a cost of $0 and the pricing source local. genai-prices is not the cause: it prices claude-sonnet-5-5 and claude-haiku-5-5. The ledger never asks it.
The hosted groups of k8s/llm/gateway/config.yaml set no api_base, so the gateway reply has no x-litellm-model-api-base header. devops_cli.ai.spend.pricing.is_local then has no served-by backend. It decides from the server that the call was sent to, and that server is the gateway (a tunnel host, or a port-forward on 127.0.0.1). So the call counts as local. The reply does name the deployment model in x-litellm-model-name (for example anthropic/claude-haiku-5-5), and is_local does not read it.
A second, separate gap: genai-prices holds no price for deepseek-v4.1-flash-1017. It holds only deepseek/deepseek-v4.1-flash under the provider openrouter. A call that is priced by name (for example RunUsage.spend_usd of the stage eval) logs the warning "genai-prices and the price overrides hold no price for model deepseek-v4.1-flash-1017 under provider (none)". The warning does not say how to set a price.
Reproduction Steps
- Make a call to the group
claude-haiku-5-5ordeepseek-v4.1-flash-1017through the gateway. - Read the ledger:
SELECT model, server, served_by, served_model, pricing_source, COUNT(*) FROM ai_spend_records WHERE served_model LIKE 'anthropic/%' OR served_model LIKE 'openrouter/%' GROUP BY 1,2,3,4,5. - Run
devops ai cost report --by all.
Expected vs Actual Behavior
Expected: the rows are hosted. Claude rows have the source genai_prices:anthropic and a cost above $0. DeepSeek rows have the source unknown and one warning that names the command to set a price, until a price exists.
Actual: on 2026-11-05 the local ledger holds 354 such rows (158 anthropic/claude-haiku-5-5, 83 anthropic/claude-sonnet-5-5, 113 openrouter/deepseek/deepseek-v4.1-flash-1017:floor). All have served_by NULL, the source local and a cost of $0. Their tokens count as local savings. Every local route has served_by set.
Environment Diagnostics
- DevOps CLI Version: 0.57.2 (log), 0.62.5 (main)
- Python Version: 3.14.10
- OS & Architecture: Linux 6.18 WSL2 x86_64
- Execution Environment: DevContainer
Logs, Traces, or Terminal Output
genai-prices and the price overrides hold no price for model deepseek-v4.1-flash-1017 under provider (none). Its requests are recorded at $0 with the pricing source unknown.
Proposed design
Problem statement
A call to a hosted gateway group is recorded as a local call at $0. The gateway reply carries no x-litellm-model-api-base header, because a hosted group sets no api_base. is_local then decides from the server, and that server is the gateway host or a port-forward on 127.0.0.1. So the ledger never asks genai-prices for the price. A second gap hides the missing price of deepseek-v4.1-flash-1017: the warning does not say how to set a price.
Acceptance criteria
Requirement: A hosted call is not local
The ledger SHALL treat a gateway call whose served model names a hosted provider as not local.
Scenario: A Claude call through the gateway
- WHEN The record's served model is
anthropic/claude-haiku-5-5and its served-by value isNone. - THEN
is_localreturnsFalsefor the record and the record keepsserved_byasNone.
Requirement: A local Ollama call stays local
The ledger SHALL keep the server rule for a call whose served model names a local backend or names no model.
Scenario: A call to an Ollama tier
- WHEN The record's served model is
ollama_chat/qwen3.8:27band its server ishttp://ollama-48gib-fast.llm.svc.cluster.local:11434. - THEN
is_localreturnsTrueand the pricing source islocal.
Requirement: A priced hosted call takes the price of its provider
The ledger MUST record a hosted call that genai-prices prices with the source genai_prices: and a cost above $0.
Scenario: A priced Claude call
- WHEN The ledger prices a record whose served model is
anthropic/claude-sonnet-5-5with 1000 input tokens and 0 output tokens. - THEN The record has the pricing source
genai_prices:anthropicand acost_usdabove 0.
Requirement: A hosted call with no price records the unknown source
The ledger MUST record a hosted call that has no price with the source unknown and a cost of $0.
Scenario: A DeepSeek call with no price
- WHEN The ledger prices a record whose served model is
openrouter/deepseek/deepseek-v4.1-flash-1017:floor. - THEN The record has the pricing source
unknownandcost_usdof 0.
Requirement: The warning names the command that sets a price
The missing-price warning SHALL name the command that sets a price for the model, with the model key filled in.
Scenario: A model with no price
- WHEN The ledger prices a call by name and genai-prices and the price overrides hold no price for it.
- THEN The warning text holds the price-override command with the model key, and it names the model and its provider.
Requirement: One warning for each unpriced model in a run
The ledger SHALL log the missing-price warning once for each model in one process run.
Scenario: Three calls to one unpriced model
- WHEN One process prices three calls to
deepseek-v4.1-flash-1017. - THEN The log holds exactly one missing-price warning for that model.
Requirement: Hosted tokens are no local savings
The cost report MUST leave the tokens of a hosted call out of the local savings.
Scenario: A report over a run that holds hosted rows
- WHEN
devops ai cost report --by alltallies a run that holds 158 hosted Claude rows and no local row. - THEN The local savings count only the rows whose pricing source is
local, so the hosted rows add nothing to it.
Existing Tool Considered
No alternatives check has run. genai-prices, already a dependency, prices claude-sonnet-5-5 and claude-haiku-5-5 and stays the price source. It holds no price for deepseek-v4.1-flash-1017, and no library can tell whether a call left the cluster. So the locality decision stays in devops-cli's own code, in src/devops_cli/ai/spend/pricing.py: about 30,000 tokens to build with its tests, about 10,000 tokens a year to keep and fix, and about 4 hours of elapsed time.
Key questions
- How does the ledger tell a hosted gateway call from a local one when the reply carries no
x-litellm-model-api-baseheader?: Read the deployment model that the record already holds (served_model, fromx-litellm-model-name) and take its provider prefix. A prefix ofanthropic,openrouterorgeminimakes the call hosted. A prefix ofollamaorollama_chat, or no model, keeps the server rule. (best practice) [sources: k8s/llm/gateway/config.yaml, SECURITY.md:40, k8s/README.md:116, src/devops_cli/ai/spend/models.py]- Chosen: Take the provider prefix of the served model. The reply names the deployment model, as in
anthropic/claude-haiku-5-5, and the four hosted groups are the only groups whose prefix is not Ollama. - Rejected: Set
api_baseon each hosted group. LiteLLM sends the request toapi_base. A hosted group has no local backend, so a set base would break the provider call. - Rejected: List the tunnel hosts and the port-forward addresses as not local. A port-forward on 127.0.0.1 still counts as local, and each client would need its own entry.
- Chosen: Take the provider prefix of the served model. The reply names the deployment model, as in
- Which provider and model name does the price lookup use for a hosted call?: Use the prefix as the provider and the rest as the model.
anthropic/claude-haiku-5-5is priced asclaude-haiku-5-5underanthropic, and the source readsgenai_prices:anthropic. The source readsunknownwhen genai-prices and the overrides hold no price. (best practice) [sources: k8s/llm/gateway/config.yaml:213, src/devops_cli/ai/spend/pricing.py]- Chosen: Split the prefix into provider and model. It gives the source
genai_prices:anthropicthat the issue expects, and the model name that genai-prices holds. - Rejected: Ask genai-prices with no provider. The issue states that genai-prices holds
deepseek/deepseek-v4.1-flashunderopenrouteronly, so a lookup with no provider misses a price that it holds. - Rejected: Strip the
:floorrouting suffix before the lookup. The issue expectsunknownfor the-1017snapshot, and a stripped suffix does not find that price. Keep the name as the gateway reports it. - Rejected: Take the cost that LiteLLM reports. The ledger's source vocabulary is
genai_prices:,unknownorlocal, and the gateway cost map sets no price for the-1017snapshot.
- Chosen: Split the prefix into provider and model. It gives the source
- How often does the ledger log the missing-price warning?: Once for each model in one process run. A second call to the same model writes no second line. (best practice) [sources: src/devops_cli/ai/spend/pricing.py]
- Chosen: Once for each model in one process run. One run prices many calls, and the message is the same for each call to one model.
- Rejected: Once for each call. 113 rows of one model would write 113 copies of the same line.
- Rejected: Once for each process start, for all models. A second unpriced model would then stay silent.
Open questions
- Which command does the warning name for a model that has no price? (missing verified source)
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 5, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
fixprefix of the title gives the type.(ai)scope of the title gives the scope.354 ledger rows show wrong cost and source, corrupting all financial reports.Users cannot trust any cost or savings figure for hosted models.The fix touches is_local() logic and the pricing lookup path, a bounded change.Both items fix is_local() misclassification of gateway calls, but 930 corrects local gateways marked external while this corrects hosted gateways marked local.devops-cli-service commentedon Nov 5, 2026
Refine cannot set this item to Ready at f6d57ec until a person answers the questions below. Reply in a comment or edit the body, and the next refine round looks at the item again.
devops-cli-service commentedon Nov 5, 2026
Released in v0.62.7: https://github.com/dan-petty/devops-cli/releases/tag/v0.62.7
devops-cli-service commentedon Nov 5, 2026
Live since 2026-11-05 19:48 UTC
fix(ai): the gateway group that answered decides the local label (#4907)