Skip to content

fix(ai): a hosted gateway call is recorded as a local call at $0 #3656

Closed

Description

@dan-petty

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

  1. Make a call to the group claude-haiku-5-5 or deepseek-v4.1-flash-1017 through the gateway.
  2. 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.
  3. 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-5 and its served-by value is None.
  • THEN is_local returns False for the record and the record keeps served_by as None.

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:27b and its server is http://ollama-48gib-fast.llm.svc.cluster.local:11434.
  • THEN is_local returns True and the pricing source is local.

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-5 with 1000 input tokens and 0 output tokens.
  • THEN The record has the pricing source genai_prices:anthropic and a cost_usd above 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 unknown and cost_usd of 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 all tallies 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-base header?: Read the deployment model that the record already holds (served_model, from x-litellm-model-name) and take its provider prefix. A prefix of anthropic, openrouter or gemini makes the call hosted. A prefix of ollama or ollama_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_base on each hosted group. LiteLLM sends the request to api_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.
  • 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-5 is priced as claude-haiku-5-5 under anthropic, and the source reads genai_prices:anthropic. The source reads unknown when 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:anthropic that 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-flash under openrouter only, so a lookup with no provider misses a price that it holds.
    • Rejected: Strip the :floor routing suffix before the lookup. The issue expects unknown for the -1017 snapshot, 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:, unknown or local, and the gateway cost map sets no price for the -1017 snapshot.
  • 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

  1. added
    source/agent
    type/bug
    scope/ai
    status/new
    value/high
    effort/medium
    on Nov 5, 2026
  2. dan-petty commented on Nov 5, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/bug. The fix prefix of the title gives the type.
    • Scope: scope/ai. The (ai) scope of the title gives the scope.
    • Priority: P1-High. 354 ledger rows show wrong cost and source, corrupting all financial reports.
    • Value: High. Users cannot trust any cost or savings figure for hosted models.
    • Effort: Medium. The fix touches is_local() logic and the pricing lookup path, a bounded change.
    • Related: feat(ai): track local llm usage against hardware spend and recognize cluster gateways #930, which asks for a different change. Both items fix is_local() misclassification of gateway calls, but 930 corrects local gateways marked external while this corrects hosted gateways marked local.
  3. added
    priority/p1-high
    on Nov 5, 2026
  4. devops-cli-service commented on Nov 5, 2026

    @devops-cli-service
    Contributor

    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.

    • Which command does the warning name for a model that has no price? (missing verified source)
  5. added
    status/in-progress
    status/in-review
    and removed
    status/new
    status/in-progress
    on Nov 5, 2026
  6. removed
    status/in-review
    on Nov 5, 2026
  7. devops-cli-service commented on Nov 5, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-05 19:48 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p1-highscope/aisource/agenttype/bugvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions