Skip to main content

Spend reports

A spend report tells you what one key, one user, one team, one organization or the whole gateway spent between two dates, and which models the money went to. It is the number you hand to finance at the end of the month, or the answer when a team asks why its bill doubled. Reports read the spend log, so a database is required, and they need a Spanway license that includes the spend_reports feature. The Usage page charts, the spend log itself and the daily activity endpoints stay free on every gateway.

A real-world scenario​

At the start of October, finance asks the platform team for September's AI spend per team and per model, so each department can be charged back. The team lead of the NLP team opens the Usage page, picks Team as the scope and September as the range, and runs the report. The result shows the team spent 41.20 dollars, almost all of it on one model through one key. Finance pulls the same numbers for every team with one curl per team, and the organization admin pulls one organization-wide report to check that the team totals add up.

Run a report​

  1. Check the license. In the Admin UI open Usage and the Spend reports tab. If the tab says Spend reports needs a Spanway Enterprise license, the license does not include spend_reports, see enterprise.

  2. Pick the scope. Under Report on choose Key, User or Team, or Organization if you are a proxy admin, admin viewer or org admin. Leave the id field empty to report on your own key, user, team or organization. Admins can paste another key's sha256 hash, or any user, team or organization id.

  3. Set From and To (both days are included, in UTC, at most 366 days apart) and click Run report.

    Expected result: a line reading Total $41.20 across 1 keys above a table with one row per key, its spend, input and output tokens, and each model with its spend. When nothing was logged, the tab says no spend was logged for this scope in the range.

  4. Run the same report from a script. Any key can report on itself:

    curl "http://localhost:4000/team/spend/report?start_date=2026-09-01&end_date=2026-09-30" \
    -H "Authorization: Bearer sk-team-key"

    Expected result:

    [
    {
    "api_key": "88dc28d0f030c55ed4ab77ed8faf098196cb1c05df778539800c9f1243fe6b4b",
    "total_cost": 41.2,
    "total_input_tokens": 1830000,
    "total_output_tokens": 412000,
    "model_details": [
    {"model": "claude-sonnet-5-5", "total_cost": 39.9, "total_input_tokens": 1700000, "total_output_tokens": 400000}
    ]
    }
    ]
  5. Report on another scope as an admin by adding its id, for example &team_id=team-nlp or &api_key=<sha256 hash>. Pass a key's sha256 hash rather than the raw key so it stays out of URLs and access logs. A value that starts with sk- is hashed for you.

Routes​

RouteWho can call itScope
GET /key/spend/reportany keyThe calling key. A proxy admin or admin viewer may pass api_key to report on any key.
GET /user/spend/reportany keyThe calling key's user. A proxy admin or admin viewer may pass internal_user_id.
GET /team/spend/reportany key that belongs to a teamThe calling key's team. A proxy admin or admin viewer may pass team_id.
GET /organization/spend/reportproxy admins, admin viewers and org adminsThe calling key's organization, or organization_id. Org admins only see organizations they administer. It covers spend logged against the organization and against every team in it.
GET /global/spend/reportproxy admins, admin viewers and keys with the get_spend_routes permissionThe whole gateway, grouped by team, customer or api_key per day.

Every route takes start_date and end_date as YYYY-MM-DD, both included and at most 366 days apart. The whole-gateway report is API only.

Scheduled spend summaries​

When alerting is set up, the gateway also posts a spend summary to the alerting channels every general_settings.spend_report_frequency, 7d by default. Use 1d for a daily summary. One gateway instance sends each summary, and it needs a database. See the spend_reports alert type in alerting and the settings reference.

Spend capture rate​

Proxy admins and admin viewers also see a Spend capture rate card on the Spend reports tab. It compares the OpenAI spend Spanway recorded with OpenAI's own bill for the same days, which shows whether traffic is reaching the provider outside the gateway. It needs OPENAI_ADMIN_KEY on the gateway, see spend capture rate.

Errors​

StatusMeaningFix
403 Your Spanway license does not include the 'spend_reports' feature. Contact sales@spanway.ai to add it., or the same with no license set.The report routes are licensed.Add a license that includes spend_reports. The Usage page shows the same message on the tab.
403 Not authorized to view spend for a team_id other than your own (or api_key, internal_user_id).A non-admin key asked for a scope that is not its own.Leave the id out, or run the report with a proxy admin key.
403 You do not have access to this organization.An org admin asked for an organization they do not administer.Pass one of your organizations, or ask a proxy admin.
400 Please provide start_date and end_date.One of the dates is missing.Send both as YYYY-MM-DD.
400 start_date and end_date must be in YYYY-MM-DD format.A date is not YYYY-MM-DD.Send dates such as 2026-10-01.
400 start_date must be on or before end_date.The range is reversed.Swap the dates.
400 Date range too large; maximum is 366 days.The range is longer than a year.Split the range. The Usage page disables Run report for such a range.
400 No team_id associated with this API key; pass a team_id query param (or api_key, internal_user_id, organization_id).The key has no team (or user, or organization) to report on.Pass the id, or use a key that belongs to the scope.
500 DB not connected. This endpoint needs a database.The gateway has no database.Set DATABASE_URL.
An empty array.Nothing was logged for the scope in the range.Check the range and the scope id, and check cost tracking if requests should have been logged.

Logs​

LevelLineMeaningAction
ERRORDatabase not connected. Connect a database to your proxy for weekly, monthly spend reportsA scheduled spend summary was due but the gateway has no database, so none was sent.Set DATABASE_URL.
ERRORException in _get_daily_spend_reports <error>The query behind a scheduled spend summary failed, so that summary was skipped.Check the database. The next summary runs on schedule.
ERRORDaily activity aggregation failed: <reason> or Daily activity export failed: <reason>A report or its download failed and the caller got a 500.Read the reason, usually the database.
INFOSpend capture-rate check: <result>The daily capture rate check ran.None. Act on the alert when the rate is low.

Every spend report and export line is in the log reference.