Skip to content

[SECURITY] Per-org LLM token and cost budgets to stop runaway spend #226

Backlog

Description

@OkiriGabriel

Problem

Nothing limits how many LLM tokens, or how much money, the agent spends per org. Every incident runs a reasoning loop of up to MAX_AGENT_STEPS, and every tool result goes back to the model. Possible causes of runaway spend:

When an org has no LLM key of its own, the platform pays. services/metrics.py already counts tokens, but nothing acts on the count.

Proposed fix

  • Per-org budgets in org config or env: LLM_MAX_TOKENS_PER_INCIDENT, LLM_MAX_TOKENS_PER_DAY, LLM_MAX_TOKENS_PER_MONTH, plus optional LLM_COST_PER_1K_INPUT/_OUTPUT to report estimated spend.
  • Track usage in storage per org and day ({org}/usage/<yyyy>/<mm>/<dd>.json) from the provider's usage fields (agent/llm.py).
  • Per-incident cap: stop the loop, set partial_result, and escalate with reason token_budget.
  • Daily or monthly cap: new incidents go to suggest_fix-only or straight to escalation, with one Slack warning at 80% and at 100%.
  • GET /orgs/{org}/usage (viewer) and a Prometheus metric devops_agent_llm_tokens_total{org}.
  • Tests: the loop stops at the cap; counters persist; the 80% warning is sent once.

Files

agent/core.py, agent/llm.py, services/metrics.py, services/org_config.py, api/server.py

Activity

  1. added
    enhancement
    security
    on Nov 27, 2026
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

    enhancementsecurity

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions