Cost exports
Cost exports copy the spend the gateway already records into the cost management tool your finance team uses, so AI spend is reported, allocated and forecast in the same place as compute and storage. Each export reads the daily spend rollups, turns them into rows in the FOCUS billing format (the open standard for cloud cost data) and sends them on a schedule or on demand. Exports are free on every Spanway gateway and need a database, since they read the spend tables.
The exported rows carry the model, provider, team, key alias, tags, token counts and cost of each day, never prompts or responses, so store_prompts_in_spend_logs and zero data retention do not change what is sent. The receiving tool keeps the rows under its own retention, and a data subject erasure in Spanway does not reach copies already exported.
A real-world scenario
A FinOps analyst already allocates the company's cloud bill to departments in CloudZero and is asked to add the AI spend that runs through the gateway. The platform admin opens the Admin UI, pastes the CloudZero API key and connection id into the CloudZero tab, runs a dry run to see the first rows, and clicks export. From then on the gateway sends the previous day's spend by team and model every day, and the analyst allocates it with the same tags and team names the rest of the bill uses.
Connect CloudZero
-
In the Admin UI open Settings, then Logging & Alerts, then the CloudZero Cost Tracking tab. Click Add CloudZero Integration.
-
Fill in CloudZero API Key and Connection ID, leave Timezone empty for UTC or enter the timezone your bill is cut in, and click Create. The key is encrypted with the salt key before it is stored. The same step from a script, as a proxy admin:
curl -X POST http://localhost:4000/cloudzero/init \-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \-d '{"api_key": "czk_...", "connection_id": "conn-12345", "timezone": "UTC"}'Expected result:
{"message": "CloudZero settings initialized successfully", "status": "success"}, and the tab now shows CloudZero Configuration with the key masked. -
Click Run Dry Run Simulation. The output under Dry Run Results shows up to 10 rows exactly as they would be sent, with a summary of cost, tokens and record count. From a script,
POST /cloudzero/dry-runwith{"limit": 10}returns the same. -
Click Export Data Now and confirm. The gateway sends the accumulated rows and replaces the matching hours in CloudZero, so running it twice does not double count. From a script:
curl -X POST http://localhost:4000/cloudzero/export \-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \-d '{"start_time_utc": "2026-10-01T00:00:00Z", "end_time_utc": "2026-10-08T00:00:00Z"}'Expected result:
{"message": "CloudZero export completed successfully.", "status": "success"}, and the rows appear in CloudZero under the connection within its ingestion delay.
Once set up, the export also runs on its own schedule, every CLOUDZERO_EXPORT_INTERVAL_MINUTES minutes (60 by default), and each run sends the last two intervals so a late row is not missed. Edit changes the connection (leave the key empty to keep the saved one), and Delete removes it and stops the export. Data already sent stays in CloudZero.
| Route | Who | What it does |
|---|---|---|
POST /cloudzero/init | proxy admin | Saves api_key, connection_id and an optional timezone. |
GET /cloudzero/settings | proxy admin, admin viewer | Shows the settings with the key masked. |
PUT /cloudzero/settings | proxy admin | Changes the fields sent. |
POST /cloudzero/dry-run | proxy admin | Returns the rows the next export would send, without sending them. |
POST /cloudzero/export | proxy admin | Sends the rows now. operation is replace_hourly by default or sum, and any other value is a 422. |
DELETE /cloudzero/delete | proxy admin | Removes the settings and stops the export. |
Connect Vantage
Vantage is set up from the Admin UI or the API, by a proxy admin only. In the Admin UI open Logging & Alerts, then the Vantage Cost Export tab, click Connect Vantage and enter the API key, the integration token and, when you use a private Vantage deployment, its base URL. The same tab shows the stored settings with the secrets masked, previews the rows the next export would send, sends them now, and removes the export. A proxy admin viewer sees the settings but none of the buttons that change them.
-
Create an API key and a cost integration token in Vantage, then save them on the gateway:
curl -X POST http://localhost:4000/vantage/init \-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \-d '{"api_key": "vntg_...", "integration_token": "accss_crdntl_..."}'Expected result:
{"message": "Vantage settings initialized successfully", "status": "success"}. -
Preview the rows with a dry run:
curl -X POST http://localhost:4000/vantage/dry-run \-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" -d '{"limit": 20}'Expected result: a
dry_run_dataobject with the raw usage rows and their FOCUS form, and asummarywith the total cost and record count. -
Send the rows with
POST /vantage/export, which takes optionalstart_time_utc,end_time_utcandlimit. Without them every row goes.
Without a manual export, Vantage receives the rows on the schedule set by VANTAGE_EXPORT_FREQUENCY, hourly by default. GET /vantage/settings shows the settings with the key and token masked, PUT /vantage/settings changes the fields sent, and DELETE /vantage/delete removes the settings. Secrets are encrypted before they are stored.
The base URL decides where the gateway sends those two secrets, so it is guarded. It must be an https:// address on the public internet, and a change to it must carry the API key and the integration token again in the same request, so nobody can point the stored secrets at another server by changing the address alone. In the Edit Vantage export dialog the two secret fields become required as soon as the base URL differs from the saved one. A private Vantage deployment on an internal address is allowed once its host is listed in user_url_allowed_hosts.
curl -X PUT http://localhost:4000/vantage/settings \
-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
-d '{"base_url": "https://vantage.example.com", "api_key": "vntg_...", "integration_token": "accss_crdntl_..."}'
| Status | Message | Cause and fix |
|---|---|---|
| 400 | Changing base_url needs api_key and integration_token in the same request | The request changed the base URL alone. Send both secrets with it. |
| 400 | base_url must be an https URL | The address uses http:// or has no host. Use the https:// address of the Vantage API. |
| 400 | base_url points at a private, loopback or link-local address or carries credentials... | The host resolves to an internal address, or the URL holds a user name or password. Add a trusted internal host to user_url_allowed_hosts, or use the public address. |
| 400 | base_url host '...' does not resolve | The host name has no DNS record from the gateway. Check the spelling and the gateway's DNS. |
FOCUS files and Mavvrik
The focus and mavvrik callbacks run from the config file, because their jobs are scheduled when the gateway starts.
spanway_settings:
callbacks: ["focus"]
focus writes FOCUS files on a schedule to an S3 bucket, a Google Cloud Storage bucket or Vantage, and mavvrik sends the same rows to Mavvrik once a day. Each is set with environment variables.
| Environment variable | Default | What it does |
|---|---|---|
FOCUS_PROVIDER | s3 | Where files go: s3, gcs or vantage. |
FOCUS_FORMAT | parquet | parquet or csv. CSV opens in a spreadsheet, Parquet is smaller and loads faster into a warehouse. |
FOCUS_FREQUENCY | hourly | hourly, daily or interval. |
FOCUS_INTERVAL_SECONDS | unset | Seconds between runs when FOCUS_FREQUENCY is interval. |
FOCUS_CRON_OFFSET | 5 | Minutes past the hour (or past midnight for daily) the export runs, so it starts after the hour's spend is written. |
FOCUS_PREFIX | focus_exports | The folder the files are written under. |
FOCUS_S3_BUCKET_NAME, FOCUS_S3_REGION_NAME | unset | The bucket and its region. The bucket is required for s3. |
FOCUS_S3_ACCESS_KEY, FOCUS_S3_SECRET_KEY, FOCUS_S3_SESSION_TOKEN | unset | Credentials for the bucket. Leave them out to use the gateway's own AWS role. |
FOCUS_S3_ENDPOINT_URL | unset | An S3 compatible store other than AWS. |
FOCUS_GCS_BUCKET_NAME | unset | The bucket, required for gcs. |
FOCUS_GCS_PATH_SERVICE_ACCOUNT | unset | Path to the service account file. Leave it out to use the gateway's own Google identity. |
VANTAGE_API_KEY, VANTAGE_INTEGRATION_TOKEN | unset | Vantage credentials when they are not saved in the Admin UI. |
VANTAGE_BASE_URL | https://api.vantage.sh | The Vantage API address. |
VANTAGE_EXPORT_FREQUENCY | hourly | How often the Vantage export runs. |
VANTAGE_EXPORT_INTERVAL_SECONDS | unset | Seconds between Vantage runs for an interval schedule. |
CLOUDZERO_API_KEY, CLOUDZERO_CONNECTION_ID, CLOUDZERO_TIMEZONE | unset, unset, UTC | CloudZero settings when they are not saved in the Admin UI. |
CLOUDZERO_EXPORT_INTERVAL_MINUTES | 60 | Minutes between CloudZero runs. |
MAVVRIK_API_KEY, MAVVRIK_API_ENDPOINT, MAVVRIK_CONNECTION_ID | unset | Mavvrik connection. |
MAVVRIK_FOCUS_FREQUENCY | daily | Only daily is allowed, because Mavvrik keeps one file per day. |
MAVVRIK_FOCUS_MAX_ROWS | 500000 | Most rows sent per daily run. |
Expected result: a new object in the bucket every hour named after the export window, and the rows visible in the destination tool after its own ingestion delay.
Errors
| Status | Meaning | Fix |
|---|---|---|
403 Admin-only endpoint. Not allowed to access this. on an export route. | The key is not a proxy admin (reading the settings also allows admin viewers). | Use a proxy admin key. |
404 on PUT /cloudzero/settings, DELETE /cloudzero/delete, DELETE /vantage/delete or POST /vantage/export. | Nothing is set up yet. | Call the init route, or Add CloudZero Integration in the Admin UI. |
200 with status: null and empty fields from GET /cloudzero/settings or GET /vantage/settings. | Nothing is set up yet. This is not an error. | Call the init route. |
422 on POST /cloudzero/export. | operation is not replace_hourly or sum. | Fix the spelling. |
422 on POST /vantage/init. | api_key or integration_token is empty. | Send both values. |
500 Failed to initialize CloudZero settings or Failed to perform CloudZero dry run export. | The database write failed, or the export job could not read the spend tables or reach the destination. The message carries the cause. | Check DATABASE_URL, the key and connection id, and the destination's status. |
| The Admin UI shows Failed to perform dry run or Failed to export data. | The same failures surfaced by the tab. | Read the toast, then fix the cause named above. |
| Rows arrive with cost 0. | The models were not priced when the spend was recorded. | Add custom pricing. Exports send the recorded cost and never reprice. |
Audit
Saving, changing and deleting CloudZero or Vantage settings writes an audit row on Spanway_Config (cloudzero_settings or vantage_settings) with who did it and the non-secret fields before and after. A rotated key or token shows as api_key_changed: true or, for the Vantage integration token, integration_changed: true, never as the secret. A deletion records the connection or base URL that was removed. Every manual export writes an exported row with the window and row limit, so you can see who sent spend data to a third party and when.
Logs
| Level | Message | Meaning | Action |
|---|---|---|---|
| INFO | CloudZero export completed successfully or Vantage export completed successfully | A manual export finished. | Normal. |
| INFO | CloudZero settings updated successfully, Vantage settings updated successfully, ... deleted successfully | The settings changed. | Normal. |
| ERROR | Error performing Vantage export: <reason> or Error initializing CloudZero settings: <reason> | An export or a save failed and the caller got a 500. | Read the reason, usually a wrong key or an unreachable destination. |
| WARNING | Invalid FOCUS_INTERVAL_SECONDS value: <value>, ignoring or Invalid VANTAGE_EXPORT_INTERVAL_SECONDS value: <value>, ignoring | The interval is not a whole number. | Fix the variable and restart. |
Related
- Cost tracking for how each row's cost is calculated.
- Spend logs and exports for downloading the same daily rollups as CSV or JSON without a third-party tool.
- Spend reports for totals inside Spanway.
- Cost Tracking page for every control of the CloudZero tab.
- Logging for the other callbacks the gateway can run.