Spend logs and exports
The spend log is the gateway's record of every request: who made it, which model answered, how many tokens it used and what it cost. Daily activity rollups total those rows per day and per user, team, tag, organization, customer and agent, which is what the Usage page draws. This page shows how to get both out of the gateway, as rows your scripts can read, as a CSV or JSON file for a spreadsheet or a data warehouse, and how to reset the running spend counters that budgets are checked against without losing the log itself. Everything here is free on every gateway and needs a database.
A real-world scenario
A data team loads the company's AI usage into its warehouse every night. A job calls the daily activity export for the previous day per team and per model and lands the CSV next to the cloud billing data. A separate support job pulls the raw rows of one customer when the customer disputes a charge. At the end of the quarter the platform admin resets the running spend counters so the new quarter's budgets start from zero, and the spend log keeps every row for the auditors.
Download daily activity as a file
-
In the Admin UI open Usage, set the date range, and click Export Data. In Export Usage Data pick an Export type, Day-by-day breakdown by user, Day-by-day breakdown by user and key or Day-by-day by user and model, pick Format (CSV, or JSON (includes metadata)) and click Export CSV. In the Team Usage, Tag Usage, Organization Usage, Customer Usage and Agent Usage views the same button exports per entity and adds Day-by-day breakdown by
<entity>and user.Expected result: a file named like
team-usage-2026-10-01-2026-10-07-daily_with_models.csvdownloads, and a toast confirms the export. -
The same download from a script, for every team over a week, broken down by model:
curl "http://localhost:4000/team/daily/activity/export?start_date=2026-10-01&end_date=2026-10-07&export_type=daily_with_models&format=csv" \-H "Authorization: Bearer $SPANWAY_API_KEY" -o team-usage.csvExpected result: a CSV with one row per day, team and model.
date,entity_id,entity_alias,api_key,key_alias,user_id,user_email,model,spend,flat_cost,prompt_tokens,completion_tokens,api_requests,successful_requests,failed_requests,cache_read_input_tokens,cache_creation_input_tokens2026-10-01,team-nlp,NLP team,,,,,claude-sonnet-5-5,41.2,0.0,2100000,410000,1840,1835,5,300000,0export_typeisdaily,daily_with_keys,daily_with_modelsordaily_with_users, andformatiscsv(the default) orjson. The route exists for/user,/team,/tag,/organization,/customerand/agent, and each one takes the filters of its Usage view, such asteam_idsortags. Proxy admins and admin viewers can export everything, other roles only what they can see on the Usage page. Every download writes anexportedaudit row onSpanway_DailySpendwith who downloaded it, the entity, the range, the breakdown and the format, so you can tell who took a copy of the spend data.
Read the raw rows
-
Page through the spend log with filters.
start_dateandend_dateare required, asYYYY-MM-DDorYYYY-MM-DD HH:MM:SSin UTC:curl "http://localhost:4000/spend/logs/v2?start_date=2026-10-14&end_date=2026-10-14&end_user=customer-42&page_size=50" \-H "Authorization: Bearer $SPANWAY_API_KEY"Expected result: a page of rows with the paging counts.
{"data": [{"request_id": "chatcmpl-6dcb2540-d3d7-4e49-bb27-291f863f112e","call_type": "acompletion","api_key": "88dc28d0f030c55ed4ab77ed8faf098196cb1c05df778539800c9f1243fe6b4b","spend": 0.0042,"total_tokens": 1400,"prompt_tokens": 1200,"completion_tokens": 200,"startTime": "2026-10-14T09:12:03.120000Z","endTime": "2026-10-14T09:12:04.890000Z","model": "claude-sonnet-5-5","custom_llm_provider": "anthropic","user": "customer-42","team_id": "team-nlp","end_user": "customer-42","request_tags": ["support-bot"],"cache_hit": "False","status": "success"}],"total": 1840,"page": 1,"page_size": 50,"total_pages": 37}Filters include
api_key(the sha256 hash),user_id,team_id,end_user,model,model_group,key_alias,status_filter,cache_hit_filter,min_spend,max_spend,error_codeandsort_by.page_sizegoes up to 1000 andtotalis capped at 10000 rows, so narrow the range for busy gateways. Internal users only ever see their own rows. Request and response bodies are present only whengeneral_settings.store_prompts_in_spend_logsis on. The Admin UI shows the same rows on the Logs page. -
For one day at a time without paging, the older
GET /spend/logsreturns up to 10000 rows, or one total per day with the defaultsummarize=true:curl "http://localhost:4000/spend/logs?start_date=2026-10-01&end_date=2026-10-07" \-H "Authorization: Bearer $SPANWAY_API_KEY"Expected result: one entry per day with
spend,prompt_tokens,completion_tokensand the count of requests. Add&summarize=falsefor the rows themselves, or?request_id=<id>for a single request. -
Total spend by tag with
GET /spend/tags?start_date=...&end_date=..., which returnsindividual_request_tag,log_countandtotal_spendper tag, or per tag and day withGET /global/spend/tags. These are the queries behind the Tag Usage view.
Reset the running spend counters
Every key and team carries a running spend that max_budget is checked against. To start a new budget period for all of them at once, call this with the master key. A proxy admin's own key is refused with a 401, because a reset clears every budget counter on the gateway:
curl -X POST http://localhost:4000/global/spend/reset -H "Authorization: Bearer $SPANWAY_MASTER_KEY"
Expected result: {"message": "Spend for all API Keys and Teams reset successfully", "status": "success"}. The spend log and the daily activity rollups keep every row, so reports and exports are unchanged. Only the counters on the keys and teams go back to 0, and two audit rows record the reset, one for keys and one for teams, each with the total spend and the number of rows before the reset.
Routes
| Route | Who | What |
|---|---|---|
GET /{user,team,tag,organization,customer,agent}/daily/activity/export | role dependent | The daily activity rollups as CSV or JSON. |
GET /{user,team,tag,organization,customer,agent}/daily/activity/aggregated | role dependent | The same rollups as JSON with a breakdown per model, provider, endpoint and key. |
GET /spend/logs/v2 | any key, scoped by role | Spend log rows, paged and filtered. |
GET /spend/logs | any key, scoped by role | Spend log rows or daily totals, unpaginated, up to 10000 rows. |
GET /spend/tags, GET /global/spend/tags | any key | Spend per tag, and per tag and day. |
GET /global/spend/report | proxy admin, admin viewer, get_spend_routes | Gateway-wide spend per day grouped by team, customer or key, see spend reports. |
POST /global/spend/reset | master key only | Sets every key and team spend to 0. |
Errors
| Status | Route | Meaning | Fix |
|---|---|---|---|
400 Start date and end date are required. | /spend/logs/v2 | The range is missing. | Send both dates. |
400 Invalid sort_by or Invalid cache_hit_filter. | /spend/logs/v2 | A filter value is not one the route accepts. | Use the values named in the message. |
500 DB not connected. This endpoint needs a database. | /spend/logs/v2, /spend/logs | The gateway has no database. | Set DATABASE_URL. |
403 A key with no user can read spend logs only as a proxy admin. | /spend/logs | A key that belongs to no user and is not a proxy admin asked for rows. | Use a key that belongs to a user, or a proxy admin key. |
400 Invalid date format: <date>. Expected: 'YYYY-MM-DD'. | /spend/logs | A date is not in YYYY-MM-DD form. | Send YYYY-MM-DD. |
403 Not authorized to view team spend for team_id=<id> or Not authorized to view spend log for request_id=<id>. | /spend/logs/v2 | A caller who is not a proxy admin asked for a team or a request they may not read. | Ask a team admin for the /spend/logs permission, or use your own requests. |
500 DB not connected. This endpoint needs a database. | /global/spend/reset | The gateway has no database. | Set DATABASE_URL. |
400 wrapping Database not connected. | /spend/tags | The gateway has no database. | Set DATABASE_URL. |
400 Please provide start_date and end_date. | /global/spend/tags | The range is missing. | Send both dates. |
401 Authentication Error, Tried to access route=/global/spend/reset, which is only for MASTER KEY. | /global/spend/reset | The key is not the master key, even if it belongs to a proxy admin. | Use the master key. |
500 Failed to fetch analytics. The gateway log has the cause. | export routes | Reading the rollups failed. The gateway logs Daily activity export failed: <reason>. | Check the database, then retry. |
| 403 naming the scope | export routes | The caller asked for an entity outside what their role can see. | Ask an admin, or export your own scope. |
| 422 | export routes | export_type or format is not one of the allowed values, or a date is malformed. | Use daily, daily_with_keys, daily_with_models or daily_with_users, csv or json, and YYYY-MM-DD. |
An empty file or []. | export routes | No activity in the range for the scope. | Widen the range or check the entity filter. |
| The Admin UI shows Failed to export data. | Export Data dialog | The export route failed, usually for one of the reasons above. | Retry, then check the gateway log. |
Logs
| Level | Message | Meaning | Action |
|---|---|---|---|
| ERROR | Daily activity export failed: <reason> | An export could not read the rollups and the caller got a 500. | Check the database. |
| INFO | Two audit rows per POST /global/spend/reset | Every reset is recorded with the spend it cleared. | Normal. |
Related
- Cost tracking for what each row contains and how its cost is calculated.
- Spend reports for totals per key, user, team or organization with a license.
- Cost exports for sending the same rollups to a cost management tool on a schedule.
- Usage page for the Export Data dialog and every view it exports from.
- Logs page for browsing the spend log in the Admin UI.
- What Spanway stores for the retention of spend log rows.