Skip to content

feat(k8s): alert on the daily Claude spend #4222

Closed

Description

@dan-petty

Problem

No alert fires on the Claude spend. On 2026-11-09 a stage task on claude-sonnet-5-5 spent about 21 USD per hour while every round failed, and nobody saw it until the owner read the cost page. The 24 h Anthropic costs of the owner for 2026-11-03 to 2026-11-09 were 1.65, 1.72, 3.74, 0.39, 0.13, 0 and 5.59 USD. The cost of 2026-11-09 was about 58 USD after the failed stage burst.

The budgets per item and per day (#3066) wait for the stage baseline (#3566). They count tokens and seconds, and they hold the Service rows. They do not alert on dollars, and they do not cover the CLI.

The counter devops_cli_ai_spend_usd_total also cannot carry the alert yet. A hosted agent run is recorded as local spend at 0 USD (#3665). In the ledger of 2026-11-05 these rows were two thirds of the hosted prompt tokens. An alert on the counter would stay quiet in a burst like that of 2026-11-09.

k8s/monitoring/prometheus-values.yaml has no rule group for spend.

Expected

  • A rule group ai-spend in k8s/monitoring/prometheus-values.yaml with two alerts of severity warning:
    • ClaudeSpendDailyHigh: sum(increase(devops_cli_ai_spend_usd_total{model="claude-sonnet-5-5"}[24h])) > 15.
    • HostedSpendDailyHigh: sum(increase(devops_cli_ai_spend_usd_total[24h])) > 25. A local request adds 0 to the counter, so this sums the hosted models.
  • The thresholds are above the highest normal day of the owner (5.59 USD) and under the burst (58 USD). The failed burst of 21 USD per hour passes 15 USD in under one hour. Change a threshold with the data of a month.
  • A promtool fixture, tests/fixtures/prometheus_rules/ai_spend_tests.yaml, run by tests/prometheus/test_k8s_monitoring_alerting.py.
  • A row for each alert in the alert table of k8s/README.md, with the first step: read the cost page of the AI spend dashboard, find the caller by the end_user label, and stop the job.
  • The work waits for fix(ai): an agent run on a hosted group is not local spend #3665, so that the counter prices hosted agent runs. The gateway series litellm_spend_metric_total (the LiteLLM prometheus callback, enabled in k8s/llm/gateway/config.yaml) is an option that needs no fix(ai): an agent run on a hosted group is not local spend #3665. Not verified: that the live scrape holds this series with a Claude cost. Check with a query before the work, and use the series that prices the calls. Do not use both.

Acceptance criteria

  1. The promtool fixture has a series that rises by 1 USD per hour for 24 hours with the label model="claude-sonnet-5-5", and asserts that ClaudeSpendDailyHigh fires. It fails today, because the rule group does not exist.
  2. The fixture has a normal series of 5.59 USD in 24 hours, and asserts that both alerts stay quiet. It fails today for the same reason.
  3. The fixture has a series that resets to 0 in the middle of the window (a pod restart), and asserts that the alert still fires on the sum of the increases. It fails today for the same reason.
  4. The fixture has a series of another hosted model of 30 USD in 24 hours, and asserts that HostedSpendDailyHigh fires and ClaudeSpendDailyHigh stays quiet.
  5. A test asserts that the alert table of k8s/README.md has a row for each alert of the group ai-spend. It fails today.
  6. A test asserts that the spend of a hosted agent run is above 0 USD in the counter (the test of fix(ai): an agent run on a hosted group is not local spend #3665). It is not part of this change. The change waits for it.

Existing tool considered

Prometheus alert rules and promtool cover this, and the repository uses them (research, roadmap-service). The LiteLLM budget feature (max_budget per key) can stop a key at a limit, but it does not alert, and the owner wants a signal and not a hard stop before the baseline (#3566). No new tool is built.

Cost

Tokens to build: about 50,000 (two rules, one fixture, one README row, one test). Tokens to keep: none. Tokens to fix a later fault: about 10,000 for a threshold change. Elapsed time: about 1 hour, after #3665.

Related

#3066 (budgets per item and per day), #3665 (hosted agent run is not local spend), #3658 (price the cache tokens of Claude), #3655 (dashboard and alerts for the pipeline).

Proposed design

Problem statement

No alert fires on the Claude spend. On 2026-11-09 a failed stage burst on claude-sonnet-5-5 cost about 58 USD in one day, and nobody saw it until the owner read the cost page. The change adds the rule group ai-spend to k8s/monitoring/prometheus-values.yaml with two warning alerts on the daily spend in USD. It also adds a promtool fixture and a README row for each alert. The alerts stay quiet for hosted agent runs until #3665 lands, because the counter now records such a run as 0 USD.

Acceptance criteria

Requirement: Claude daily spend alert fires

The rule ClaudeSpendDailyHigh of the group ai-spend SHALL fire with severity warning when the 24 hour increase of the spend of claude-sonnet-5-5 is above 15 USD.

Scenario: Claude spend rises 1 USD per hour

  • WHEN The promtool fixture feeds a series with model="claude-sonnet-5-5" that rises by 1 USD per hour for 24 hours.
  • THEN The alert ClaudeSpendDailyHigh fires at the end of the window.

Requirement: Normal day stays quiet

Both alerts of the group ai-spend MUST stay quiet on the highest normal day of the owner.

Scenario: Normal day of 5.59 USD

  • WHEN The promtool fixture feeds a series with model="claude-sonnet-5-5" that adds 5.59 USD in 24 hours.
  • THEN Neither ClaudeSpendDailyHigh nor HostedSpendDailyHigh fires.

Requirement: Counter reset keeps the sum

The alerts SHALL sum the increases of a series that resets to 0 in the middle of the window.

Scenario: Pod restart in the window

  • WHEN The promtool fixture feeds a Claude series that resets to 0 in the middle of the window and adds more than 15 USD in total.
  • THEN The alert ClaudeSpendDailyHigh still fires.

Requirement: Hosted alert counts every model

The rule HostedSpendDailyHigh SHALL fire when the 24 hour increase of the spend of all models is above 25 USD, and ClaudeSpendDailyHigh MUST count the model claude-sonnet-5-5 only.

Scenario: Another hosted model spends 30 USD

  • WHEN The promtool fixture feeds a series of another hosted model that adds 30 USD in 24 hours.
  • THEN The alert HostedSpendDailyHigh fires and ClaudeSpendDailyHigh stays quiet.

Requirement: Rules pass the existing rule tests

The two new rules SHALL carry severity warning, a wait, a summary and a description, and the test file MUST list the counter as a served series, the two alerts in the baseline rule set, and the group in the list of unit-tested groups.

Scenario: Rule file checks

  • WHEN The tests of tests/prometheus/test_k8s_monitoring_alerting.py run against the new group.
  • THEN The tests for served series, baseline rules, rule fields and promtool pass, and the fixture tests/fixtures/prometheus_rules/ai_spend_tests.yaml runs for the group ai-spend.

Requirement: README lists each alert

The alert table of k8s/README.md SHALL have a row for each alert of the group ai-spend, with the first step: read the cost page of the AI spend dashboard, find the caller by the end_user label, and stop the job.

Scenario: README rows present

  • WHEN A test reads the alert table of k8s/README.md and the alert names of the group ai-spend.
  • THEN Each alert name has a row in the table.

Existing Tool Considered

No alternatives check has run for this item. Prometheus alert rules and promtool cover the need, and the repository already uses them for roadmap-service and research. They need no new code beyond two rules, one fixture, two README rows and one test. The LiteLLM max_budget per key stops a key at a limit, but it sends no alert, so it lacks the signal that the owner wants. No tool is built. Cost of the change: about 50,000 tokens to build, no tokens to keep, about 10,000 tokens for each later threshold change, and about 1 hour of elapsed time after #3665.

Key questions

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/feature
    scope/k8s
    status/new
    value/medium
    effort/low
    on Nov 9, 2026
  2. dan-petty commented on Nov 9, 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/feature. The feat prefix of the title gives the type.
    • Scope: scope/k8s. The (k8s) scope of the title gives the scope.
    • Priority: P2-Medium. It prevents unnoticed financial loss (58 USD burst) but is a signal, not a hard stop, and depends on #3665.
    • Value: Medium. It catches a costly burst before the owner reads the cost page, but a dashboard already shows the spend.
    • Effort: Low. Two alert rules, one promtool fixture, one README row, and one test; the body estimates about 1 hour.
    • Related: feat(roadmap): cost and token budgets per item and per day #3066, which asks for a different change. Both bound AI spend, but #3066 adds budgets that hold rows (hard stop) while this adds Prometheus alerts that signal (no stop).
  3. added
    priority/p2-medium
    on Nov 9, 2026
  4. devops-cli-service commented on Nov 9, 2026

    @devops-cli-service
    Contributor

    Refine cannot set this item to Ready at 111adc5 while the items below stay open. The next refine round looks at the item again when they close, or when a person replies in a comment or edits the body.

    The next refine round also looks at the item again when a commit on the default branch changes one of these files: src/devops_cli/telemetry/instruments.py.

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

    @devops-cli-service
    Contributor

    Status set to Ready at c034509 (see proposed design in issue body).

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

    @devops-cli-service
    Contributor

    Live since 2026-11-09 17:57 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/lowpriority/p2-mediumscope/k8ssource/agenttype/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions