Skip to content

fix(monitoring): read AI spend from the gateway counter - #5924

Merged
dan-petty merged 2 commits into
mainfrom
fix/4724-spend-from-gateway-counter
Nov 16, 2026
Merged

dan-petty merged 2 commits into
mainfrom
fix/4724-spend-from-gateway-counter

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

The spend panels of ai-spend.json read devops_cli_ai_spend_usd_total. A Job pod sends it a few times an hour, so rate([5m]) missed it and rate([1h]) drew spikes. For 6 h to 2026-11-16 02:00Z the panel gave $0.67 and the gateway counter $1.23.

  • Cloud Spend in Range, the spend of the three projections, Spend: USD per hour and Spend by model: USD per hour read litellm_spend_metric_total for gateway calls and devops_cli_ai_spend_usd_total{provider!="gateway"} for direct calls.
  • Hourly bars use increase([$__interval]), Min interval 1h. Projections read the last 7 days.
  • The coverage stat shows devops-cli gateway spend over gateway spend (0.775 for 7 d).
  • promtool cases: tests/fixtures/dashboard_queries/ai-spend.yaml.

The savings queries do not change (#5914, #5784). Request, token and slot-wait panels: #5922.

Closes #4724

Change: openspec/changes/archive/2026-11-16-4724-spend-from-gateway-counter/

The spend panels of ai-spend.json take a gateway call from the gateway's
spend counter litellm_spend_metric_total, and devops-cli's own spend
series only for a call that did not go through the gateway. Hourly spend
bars use increase([$__interval]) with a Min interval of 1h, the spend
projections read the last 7 days, and the coverage stat shows the spend
coverage. promtool cases in tests/fixtures/dashboard_queries/ai-spend.yaml
hold the new queries.
@dan-petty dan-petty added type/bug Type bug: the code does not do what it must scope/monitoring Grafana, Prometheus, Loki, alerts and dashboards labels Nov 16, 2026
@dan-petty
dan-petty marked this pull request as ready for review November 16, 2026 02:44
@dan-petty

Copy link
Copy Markdown
Owner Author

Vet: SAFE. The spend panels read litellm_spend_metric_total for gateway calls and devops_cli_ai_spend_usd_total{provider!="gateway"} for direct calls, so the sparse series of the Job pods no longer drive them. The projections use a fixed rate([7d]) baseline, the hourly bars use increase([$__interval]) with a 1 h minimum (no rolling line, so no extrapolation spikes), and live checks match the gateway counter (7 d: bars $142.44 against an increase of $142.04). The coverage panel (devops-cli gateway spend / gateway spend, 0.54 at 6 h) also shows the loss that #5916 fixes. The savings half of the projections is unchanged; #5914 fixes it.

@dan-petty
dan-petty merged commit f391129 into main Nov 16, 2026
23 checks passed
@dan-petty
dan-petty deleted the fix/4724-spend-from-gateway-counter branch November 16, 2026 02:50
dan-petty pushed a commit that referenced this pull request Nov 16, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.160.1](v0.160.0...v0.160.1)
(2026-11-16)


### Bug Fixes

* **monitoring:** read AI spend from the gateway counter
([#5924](#5924))
([f391129](f391129))
* **telemetry:** a Job pod exports its metrics while it runs
([#5926](#5926))
([00bfc49](00bfc49))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/monitoring Grafana, Prometheus, Loki, alerts and dashboards type/bug Type bug: the code does not do what it must

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(monitoring): read AI spend from the gateway counter

1 participant