Repository navigation
Description
Problem or Motivation
devops_cli_ai_spend_usd_total is 41 % of the gateway spend for the same caller: 24 h, job roadmap-service $1.48 against litellm_spend_metric_total{end_user='roadmap-service'} $3.59; 7 d, $77.33 against $118.57. The requests (4,198 against 4,187) and the tokens (258.2 M against 252.0 M) agree, so devops-cli prices the same tokens lower. src/devops_cli/ai/spend/ledger.py:1066 emits the cost that devops-cli computes; the gateway prices from k8s/llm/gateway/config.yaml:195-197. The spend report and the Service spend panels are low by the same share.
Proposed Solution & Architectural Design
Check the premise first: confirm that the LiteLLM proxy of the pinned gateway version returns the cost of each call in the x-litellm-response-cost response header (LiteLLM proxy documentation), for chat and embeddings, with and without streaming. If it does, the ledger records that cost for each call through the gateway, and computes a price only for a direct provider call. If the header is absent in a case, take the gateway model price from one shared source (the gateway config) for that case. The price that OpenRouter bills is a separate person check (#4422).
Target Subsystem
AI & Agentic Review Pipeline (AI spend ledger and its telemetry).
Existing Tool Considered
The LiteLLM proxy response header x-litellm-response-cost (an open tool's standard output). The ledger reads it; no new price table.
Acceptance Criteria
- A test with the HTTP fake: a gateway answer with x-litellm-response-cost 0.0123 adds 0.0123 USD to the ledger and to devops_cli_ai_spend_usd_total.
- A test: a direct provider call still uses the price table.
- Live, 24 h after the rollout: sum(increase(devops_cli_ai_spend_usd_total{provider='gateway'}[24h])) divided by sum(increase(litellm_spend_metric_total{end_user=~'devops-cli|devops-cli-job|roadmap-service'}[24h])) is between 0.95 and 1.05 (today 0.41).
Files
src/devops_cli/ai/spend/ledger.pysrc/devops_cli/ai/client/network.pytests/ai/spend/test_ai_spend_ledger.pytests/ai/spend/test_ai_spend_prometheus.py
Dependencies
None.
Related
#4296 (cost of the Jev pass-through calls, the same header), #4422 (a person confirms the OpenRouter price).
Source: #4675
Activity
dan-petty commentedon Nov 11, 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.The spend report is wrong by a factor of two, which misleads budgeting, but the system still functions.AI spend tracking is the primary cost-visibility tool for the project and its users.The change touches two source files and two test files with a clear header-reading approach and a fallback path.Both record the cost of gateway calls, but #4296 targets Jev pass-through calls via usage.cost in the body while the candidate targets all gateway chat and embedding calls via the x-litellm-response-cost header.dan-petty commentedon Nov 12, 2026
Closed as not planned. Newer code fixed the gap that this item reports, and the header design does not cover a streamed call. No pull request.
Premise check (2026-11-12)
The gap is gone. fix(ai): price the DeepSeek group and its cached input #4454 (merged 2026-11-11, first released in v0.111.0 at 05:38Z) gives the group
deepseek-v4.1-flash-1017the price of the gateway config. Before fix(ai): price the DeepSeek group and its cached input #4454, each call of that group recorded 0 USD with the sourceunknown. The ratio of acceptance criterion 3,sum(increase(devops_cli_ai_spend_usd_total{provider="gateway"}[1h])) / sum(increase(litellm_spend_metric_total{end_user=~"devops-cli|devops-cli-job|roadmap-service"}[1h])):roadmap-service)The 24 h and 7 d values in this item (0.41) include the hours before the rollout. Criterion 3 (0.95 to 1.05) is true now.
One price source is in place. The gateway config sets the price of each hosted group in
model_info, and_HOSTED_GROUP_PRICESinsrc/devops_cli/ai/spend/pricing.pyholds the same rates.test_the_client_price_of_a_hosted_group_is_the_price_in_the_gateway_configintests/ai/spend/test_hosted_group_prices.pyfails when the two differ. This is the fallback that the item asks for.The header is absent on a streamed reply. In LiteLLM 1.103.10 (the pinned image),
litellm/proxy/common_request_processing.pysends the headers of a stream with its first chunk (_stream_response_headers, line 2312:response_cost=hidden_params.get("response_cost") or ""). The cost is not known at that time, andget_custom_headersdrops an empty value (exclude_values, lines 1676 and 1781). Only a reply that does not stream getsx-litellm-response-cost. The CLI streams each chat call (comment ofsse_keepalive_ping_interval_secondsink8s/llm/gateway/config.yaml). Thus the header cannot give the cost of each gateway call, as the item asks.The header also gives no new fact: the gateway calculates it from the same config price. The price that OpenRouter bills stays the person check of #4422. The cost of the Jev pass-through calls stays #4296. The spend coverage stat that #4724 adds shows about 1.0 now, not 0.41.