Skip to content

fix(roadmap): the spend pair of the review compares different calls #6660

Done

Description

@dan-petty

Problem

The disagreement pair spend of the project review (src/devops_cli/roadmap/project_review/catalog.yaml) compares prometheus.cli_spend, sum(increase(devops_cli_ai_spend_usd_total[{range}])), with prometheus.gateway_spend, sum(increase(litellm_spend_metric_total[{range}])). Its definition says "devops-cli and the gateway count the same model calls through the gateway". The two counters do not count the same calls, so the pair gives a disagreement in each window and tells nothing.

Read-only queries of the live Prometheus, windows of one day:

Window end cli_spend gateway_spend Difference
2026-11-07T00:00Z 0.32 USD 1.85 USD (anthropic 0.21, openrouter 1.64) 83%
2026-11-17T12:00Z 7.55 USD (refine 3.41, stage 3.06, implement 0.75, alternatives 0.34) 5.61 USD (openrouter 5.59, health check 0.02) 26%
  • Every series of devops_cli_ai_spend_usd_total in the second window has provider="gateway", so each call that devops-cli counted went through the gateway.
  • litellm_spend_metric_total gives api_key_alias="None" and team_alias="None" for every client call. The gateway counter thus has no label that selects the calls of devops-cli. In the first window, other clients of the gateway (not devops-cli) spent most of the 1.85 USD.
  • In the second window, devops-cli counted 35% more than the gateway counted for all clients together. fix(llm): Pass the OpenRouter cost of a streamed call through #6165 (the gateway under-counts a streamed OpenRouter call by about 15%) explains only a part. fix(ai): Price each gateway call at the deployment that answered #6002 makes the client price lower, not higher.

The difference changes direction between the windows, so a fix of #6165 or #6002 alone does not make the pair agree.

Expected

The pair compares the same set of calls, or the review does not show it:

  • Give each gateway client its own virtual key with an alias (LiteLLM virtual keys, api_key_alias label), and read litellm_spend_metric_total{api_key_alias="<alias of devops-cli>"} on the gateway side. Or
  • Remove the pair, and keep the two facts as separate values.

Then find the cause of the remaining gap of the second window (client price of a cached or streamed call against the gateway price), and comment it on #6165 or #6002, or file it.

Acceptance criteria

  • The definition of the pair names the set of calls that both sides count.
  • A live read-only review of one day after the change shows the pair within its tolerance, or the PR names the cause that remains, with its issue.

Dependencies

None. Related: #6165, #6002, #6612.

Alternatives check of 2026-11-21: in-use.
The repository already uses this tool.
Tool: BerriAI/litellm (https://github.com/BerriAI/litellm), NOASSERTION, last activity 2026-11-21, maintained.
Reason: Searches found LiteLLM, the gateway the review already reads; its virtual keys with an api_key_alias give the gateway side the same call set, but the client counter and the streamed-call and price gaps remain.

Covers:

  • A virtual key and alias for each gateway client
  • Spend metric labelled by api_key_alias to select one client
  • Per-key spend and budget records in the gateway database

Lacks:

Proposed design

Problem statement

The spend disagreement pair in the project review compares prometheus.cli_spend with prometheus.gateway_spend. The gateway spend counter counts every caller, while the stage Job, the runner Jobs and the CLI send the gateway master key, so api_key_alias is None for their calls and no label selects the same call set as devops_cli_ai_spend_usd_total. The pair therefore disagrees in each window and tells nothing. Remove the pair and keep both spend facts as separate values, and record the cause that remains on #6165 or #6002, or file it.

Acceptance criteria

Requirement: No spend disagreement pair

The project review catalog SHALL define no disagreement pair named spend.

Scenario: Live review omits the spend pair

  • WHEN I run the live read-only review with uv run devops roadmap review run --since 2026-11-16T12:00Z --until 2026-11-17T12:00Z.
  • THEN The review lists no spend disagreement.

Requirement: Both spend facts stay separate

The project review catalog MUST keep prometheus.cli_spend and prometheus.gateway_spend as separate facts.

Scenario: Dry run lists both spend facts

  • WHEN I run uv run devops roadmap review run --dry-run --since 2026-11-16T12:00Z --until 2026-11-17T12:00Z.
  • THEN The command exits 0 and prints a line for prometheus.cli_spend and a line for prometheus.gateway_spend.

Existing Tool Considered

LiteLLM (BerriAI/litellm) is in use. The alternatives block of the issue body records what it lacks. This proposal does not add a virtual-key alias path: it removes the spend disagreement pair and keeps prometheus.cli_spend and prometheus.gateway_spend as separate facts, so the review compares no different call sets and the open gaps stay on their issues.

Key questions

  • What does the spend disagreement pair compare today?: It compares prometheus.cli_spend, sum(increase(devops_cli_ai_spend_usd_total[{range}])), with prometheus.gateway_spend, sum(increase(litellm_spend_metric_total[{range}])). [sources: src/devops_cli/roadmap/project_review/catalog.yaml:891, src/devops_cli/roadmap/project_review/catalog.yaml:899, src/devops_cli/roadmap/project_review/catalog.yaml:922]
  • Should the project review use a LiteLLM virtual-key alias for the spend pair or remove the pair?: Remove the spend disagreement pair from src/devops_cli/roadmap/project_review/catalog.yaml and keep prometheus.cli_spend and prometheus.gateway_spend as separate facts. (best practice) [sources: src/devops_cli/roadmap/project_review/catalog.yaml:922, k8s/devops/cronjob-stage.yaml:110, k8s/devops/cronjob-runner.yaml:167, k8s/devops/roadmap-service/deployment.yaml:89, src/devops_cli/commands/k8s/roadmap_key_bootstrap.py:58]
    • Rejected: Add a virtual key and alias for each gateway client and filter litellm_spend_metric_total by api_key_alias. The stage Job, the runner Jobs and the CLI send the master key, so their calls read api_key_alias=None; only the roadmap Service Deployment uses a virtual key with the alias roadmap-service. Giving every client its own key and wiring it through the Jobs, the CLI and the secrets is a larger change, and the streamed-call and price gaps remain.
    • Chosen: Remove the spend disagreement pair and keep the two spend facts separate. The review stops comparing different call sets. The two facts stay visible, and the open gaps stay on their issues.
  • Which label selects devops-cli calls in litellm_spend_metric_total today?: None selects all devops-cli calls. The gateway spend counter counts every caller (k8s/README.md:364). The stage Job and the runner Jobs read DEVOPS_CLI_AI_API_KEY from Secret devops-cli, which holds the gateway master key (k8s/devops/cronjob-stage.yaml:110, k8s/devops/cronjob-runner.yaml:167, k8s/README.md:777), so their calls read api_key_alias=None. The roadmap Service Deployment is the only workload that reads its own virtual key (k8s/devops/roadmap-service/deployment.yaml:89), and devops k8s bootstrap-roadmap-key mints that key with the alias roadmap-service (src/devops_cli/commands/k8s/roadmap_key_bootstrap.py:58), so api_key_alias selects that pod's calls alone. The gateway's end_user label names callers on the request and token series, not on the spend series (k8s/llm/gateway/config.yaml:301). [sources: k8s/README.md:364, k8s/README.md:777, k8s/devops/cronjob-stage.yaml:110, k8s/devops/cronjob-runner.yaml:167, k8s/devops/roadmap-service/deployment.yaml:89, src/devops_cli/commands/k8s/roadmap_key_bootstrap.py:58, k8s/llm/gateway/config.yaml:301]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/bug
    source/agent
    scope/roadmap
    status/new
    value/medium
    on Nov 21, 2026
  2. dan-petty commented on Nov 21, 2026

    @dan-petty
    OwnerAuthor
  3. added
    effort/medium
    priority/p2-medium
    on Nov 21, 2026
  4. devops-cli-service commented on Nov 21, 2026

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.

    Searches (10)

    Tools considered:

    Searches run:

    • LiteLLM virtual key api_key_alias prometheus spend metric, results: 5
    • litellm_spend_metric_total labels team_alias api_key_alias, results: 5
    • docs.litellm.ai virtual keys spend tracking, results: 5
    • litellm prometheus metrics virtual key spend per key label, results: 5
    • BerriAI litellm virtual keys documentation, results: 5
    • github litellm prometheus metrics spend per virtual key, results: 5
    • litellm proxy prometheus /metrics spend metric labels, results: 5
    • litellm prometheus, results: 5
    • litellm virtual keys, results: 5
    • litellm budget spend tracking per key database, results: 5

    Sources:

  5. added
    status/ready
    and removed
    status/new
    on Nov 22, 2026
  6. devops-cli-service commented on Nov 22, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  7. added
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 25, 2026
  8. removed
    status/in-review
    on Nov 25, 2026
  9. devops-cli-service commented on Nov 25, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-25 08:43 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/p2-mediumscope/roadmapsource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions