Budget

Tenant spend tracking, budget limits, spend forecasting, agent budgets, and budget alerts.

Endpoints

MethodPathAuthDescription
GET/v1/budget/statusAPI KeyCurrent spend, limits, and remaining
PUT/v1/budget/limitsAPI KeyUpdate daily/monthly spend limits
GET/v1/budget/forecastAPI KeySpend forecast with trend analysis and anomalies
GET/v1/budget/agentsAPI KeyList agent budgets and spend leaderboard
PUT/v1/budget/agents/:agentIdAPI KeySet agent budget config
GET/v1/budget/alerts/configAPI KeyGet alert threshold configuration
PUT/v1/budget/alerts/configAPI KeyUpdate alert thresholds and webhook
GET/v1/budget/alerts/historyAPI KeyRecent alert history

Dashboard bridge endpoints (JWT auth):

MethodPathAuthDescription
GET/auth/budget/statusJWTTenant budget status
GET/auth/budget/forecastJWTTenant budget forecast
GET/auth/budget/agentsJWTAgent budgets and leaderboard
PUT/auth/budget/agents/:agentIdJWTSet agent budget config
GET/auth/budget/alerts/configJWTAlert configuration
PUT/auth/budget/alerts/configJWTUpdate alert configuration
GET/auth/budget/alerts/historyJWTAlert history

> Note: Dashboard bridge endpoints return tenant-level data only. key_id and key_budget are always null because JWT auth has no API key context. Per-key budget data is only available through the API-key-authenticated /v1/budget/* endpoints.

Get budget status

Returns current spend against limits for the authenticated tenant.

curl "https://api.brainstormrouter.com/v1/budget/status" \
  -H "Authorization: Bearer br_live_..."

Response

{
  "tenant_id": "t_001",
  "key_id": "key_abc",
  "daily": {
    "spent_usd": 12.5,
    "limit_usd": 50.0,
    "remaining_usd": 37.5,
    "period_key": "2026-03-10"
  },
  "monthly": {
    "spent_usd": 120.0,
    "limit_usd": 500.0,
    "remaining_usd": 380.0,
    "period_key": "2026-03"
  },
  "key_budget": {
    "limit_usd": 10.0,
    "period": "daily",
    "spent_usd": 3.2,
    "remaining_usd": 6.8
  }
}

key_budget is null when the API key has no per-key budget configured.

Update budget limits

Set or clear tenant-level daily and monthly spend limits. Pass null to remove a limit.

curl -X PUT "https://api.brainstormrouter.com/v1/budget/limits" \
  -H "Authorization: Bearer br_live_..." \
  -H "Content-Type: application/json" \
  -d '{"daily_limit_usd": 50, "monthly_limit_usd": 500}'

Request body

FieldTypeDescription
daily_limit_usdnumber \nullDaily spend cap in USD
monthly_limit_usdnumber \nullMonthly spend cap in USD

Response

{
  "ok": true,
  "limits": {
    "dailyLimitUsd": 50,
    "monthlyLimitUsd": 500
  }
}

Get budget forecast

Returns spend forecast powered by BudgetForecaster with 30-day historical data, including trend analysis, anomaly detection, and confidence scoring.

curl "https://api.brainstormrouter.com/v1/budget/forecast" \
  -H "Authorization: Bearer br_live_..."

Response

{
  "tenant_id": "t_001",
  "forecast": {
    "avgDailySpendUsd": 15.2,
    "projectedPeriodSpendUsd": 456.0,
    "depletionDate": "2026-03-25",
    "daysRemaining": 14,
    "trend": "increasing",
    "confidence": 0.85
  },
  "anomalies": [],
  "daysOfData": 12,
  "daily_spent_usd": 18.5,
  "limits": {
    "daily_usd": 50,
    "monthly_usd": 500
  }
}

trend is one of: "increasing", "decreasing", "stable". anomalies lists days with abnormal spend.

Agent budgets

List agent budgets

Returns all configured agent budgets and a spend leaderboard.

curl "https://api.brainstormrouter.com/v1/budget/agents" \
  -H "Authorization: Bearer br_live_..."

Response

{
  "agents": [
    {
      "agentId": "agent-1",
      "config": {
        "perDayUsd": 5,
        "exhaustionAction": "stop"
      },
      "status": {
        "totalSpendUsd": 45.0,
        "activeConversations": 3,
        "downgradeCount": 2,
        "stopCount": 0
      }
    }
  ],
  "leaderboard": [
    {
      "agentId": "agent-1",
      "totalSpendUsd": 45.0,
      "totalRequests": 120,
      "successRate": 0.98,
      "avgCostPerRequest": 0.375,
      "avgLatencyMs": 1200,
      "efficiencyScore": 0.92
    }
  ]
}

Set agent budget

curl -X PUT "https://api.brainstormrouter.com/v1/budget/agents/agent-1" \
  -H "Authorization: Bearer br_live_..." \
  -H "Content-Type: application/json" \
  -d '{"perDayUsd": 10, "exhaustionAction": "downgrade"}'
FieldTypeDescription
perDayUsdnumberDaily spend cap for the agent
exhaustionActionstring"stop" or "downgrade" when exhausted

Budget alerts

Alerts fire when projected spend crosses configured threshold percentages. Thresholds are edge-triggered (fire once per crossing) and reset each budget period.

Get alert config

curl "https://api.brainstormrouter.com/v1/budget/alerts/config" \
  -H "Authorization: Bearer br_live_..."
{
  "thresholds": [80, 90, 95],
  "webhookUrl": null,
  "enabled": false
}

Update alert config

curl -X PUT "https://api.brainstormrouter.com/v1/budget/alerts/config" \
  -H "Authorization: Bearer br_live_..." \
  -H "Content-Type: application/json" \
  -d '{"thresholds": [70, 85, 95], "webhookUrl": "https://example.com/webhook", "enabled": true}'

Get alert history

curl "https://api.brainstormrouter.com/v1/budget/alerts/history?limit=10" \
  -H "Authorization: Bearer br_live_..."
{
  "alerts": [
    {
      "scope": "global",
      "ratioPercent": 95,
      "threshold": 95,
      "projectedUsd": 47.5,
      "limitUsd": 50.0,
      "tenantId": "t_001",
      "timestamp": "2026-03-11T12:00:00Z"
    }
  ],
  "count": 1
}

Enforcement

When a request would exceed the budget, the middleware returns 402 Payment Required with headers:

HeaderDescription
X-Budget-LimitConfigured limit in USD
X-Budget-SpentCurrent spend in USD
X-Budget-RemainingRemaining budget in USD

Budget-exempt paths (always allowed): /v1/budget/, /v1/killswitch/, /v1/security/, /v1/usage/, /v1/models, /v1/config, /health.