Skip to main content
GET
/
api
/
spend
curl -X GET 'https://localhost:3100/api/spend?days=7' \
  -H 'Authorization: Bearer fn_sess_abc123def456'
{
  "enabled": true,
  "config": {
    "track_spend": true,
    "spend_history_days": 30
  },
  "daily": [
    {
      "service": "openai",
      "date": "2026-03-03",
      "cost_usd": 15.50,
      "amount": 15.50,
      "request_count": 120
    },
    {
      "service": "anthropic",
      "date": "2026-03-03",
      "cost_usd": 8.25,
      "amount": 8.25,
      "request_count": 45
    },
    {
      "service": "openai",
      "date": "2026-03-02",
      "cost_usd": 22.10,
      "amount": 22.10,
      "request_count": 180
    }
  ],
  "budgets": {
    "openai": {
      "daily_limit": 50.0,
      "spent_today": 15.50,
      "warning_pct": 80,
      "warning_active": false
    },
    "anthropic": {
      "daily_limit": 30.0,
      "spent_today": 8.25,
      "warning_pct": 80,
      "warning_active": false
    }
  }
}

Authentication

Requires a valid session token in the Authorization header:
Authorization: Bearer <session_token>

Query Parameters

days
integer
Number of days of spend history to retrieve. Defaults to spend_history_days from config. Maximum value is capped by the config setting.

Response

enabled
boolean
Whether spend tracking is enabled (true) or disabled (false)
config
object
Spend tracking configuration settings (only present if enabled)
daily
array
Array of daily spend records aggregated by service and date (only present if enabled)
budgets
object
Budget configuration and current spend by service (only present if enabled). Object keys are service names.

Error Responses

  • 401 Unauthorized: Missing or invalid session token
  • 500 Internal Server Error: Database error
If spend tracking is disabled in the configuration (track_spend: false), the response will only contain {"enabled": false}.
curl -X GET 'https://localhost:3100/api/spend?days=7' \
  -H 'Authorization: Bearer fn_sess_abc123def456'
{
  "enabled": true,
  "config": {
    "track_spend": true,
    "spend_history_days": 30
  },
  "daily": [
    {
      "service": "openai",
      "date": "2026-03-03",
      "cost_usd": 15.50,
      "amount": 15.50,
      "request_count": 120
    },
    {
      "service": "anthropic",
      "date": "2026-03-03",
      "cost_usd": 8.25,
      "amount": 8.25,
      "request_count": 45
    },
    {
      "service": "openai",
      "date": "2026-03-02",
      "cost_usd": 22.10,
      "amount": 22.10,
      "request_count": 180
    }
  ],
  "budgets": {
    "openai": {
      "daily_limit": 50.0,
      "spent_today": 15.50,
      "warning_pct": 80,
      "warning_active": false
    },
    "anthropic": {
      "daily_limit": 30.0,
      "spent_today": 8.25,
      "warning_pct": 80,
      "warning_active": false
    }
  }
}

Build docs developers (and LLMs) love