Skip to main content

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​

  1. In the Admin UI open Settings, then Logging & Alerts, then the CloudZero Cost Tracking tab. Click Add CloudZero Integration.

  2. 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.

  3. 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-run with {"limit": 10} returns the same.

  4. 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.

RouteWhoWhat it does
POST /cloudzero/initproxy adminSaves api_key, connection_id and an optional timezone.
GET /cloudzero/settingsproxy admin, admin viewerShows the settings with the key masked.
PUT /cloudzero/settingsproxy adminChanges the fields sent.
POST /cloudzero/dry-runproxy adminReturns the rows the next export would send, without sending them.
POST /cloudzero/exportproxy adminSends the rows now. operation is replace_hourly by default or sum, and any other value is a 422.
DELETE /cloudzero/deleteproxy adminRemoves 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.

  1. 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"}.

  2. 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_data object with the raw usage rows and their FOCUS form, and a summary with the total cost and record count.

  3. Send the rows with POST /vantage/export, which takes optional start_time_utc, end_time_utc and limit. 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_..."}'
StatusMessageCause and fix
400Changing base_url needs api_key and integration_token in the same requestThe request changed the base URL alone. Send both secrets with it.
400base_url must be an https URLThe address uses http:// or has no host. Use the https:// address of the Vantage API.
400base_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.
400base_url host '...' does not resolveThe 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 variableDefaultWhat it does
FOCUS_PROVIDERs3Where files go: s3, gcs or vantage.
FOCUS_FORMATparquetparquet or csv. CSV opens in a spreadsheet, Parquet is smaller and loads faster into a warehouse.
FOCUS_FREQUENCYhourlyhourly, daily or interval.
FOCUS_INTERVAL_SECONDSunsetSeconds between runs when FOCUS_FREQUENCY is interval.
FOCUS_CRON_OFFSET5Minutes past the hour (or past midnight for daily) the export runs, so it starts after the hour's spend is written.
FOCUS_PREFIXfocus_exportsThe folder the files are written under.
FOCUS_S3_BUCKET_NAME, FOCUS_S3_REGION_NAMEunsetThe bucket and its region. The bucket is required for s3.
FOCUS_S3_ACCESS_KEY, FOCUS_S3_SECRET_KEY, FOCUS_S3_SESSION_TOKENunsetCredentials for the bucket. Leave them out to use the gateway's own AWS role.
FOCUS_S3_ENDPOINT_URLunsetAn S3 compatible store other than AWS.
FOCUS_GCS_BUCKET_NAMEunsetThe bucket, required for gcs.
FOCUS_GCS_PATH_SERVICE_ACCOUNTunsetPath to the service account file. Leave it out to use the gateway's own Google identity.
VANTAGE_API_KEY, VANTAGE_INTEGRATION_TOKENunsetVantage credentials when they are not saved in the Admin UI.
VANTAGE_BASE_URLhttps://api.vantage.shThe Vantage API address.
VANTAGE_EXPORT_FREQUENCYhourlyHow often the Vantage export runs.
VANTAGE_EXPORT_INTERVAL_SECONDSunsetSeconds between Vantage runs for an interval schedule.
CLOUDZERO_API_KEY, CLOUDZERO_CONNECTION_ID, CLOUDZERO_TIMEZONEunset, unset, UTCCloudZero settings when they are not saved in the Admin UI.
CLOUDZERO_EXPORT_INTERVAL_MINUTES60Minutes between CloudZero runs.
MAVVRIK_API_KEY, MAVVRIK_API_ENDPOINT, MAVVRIK_CONNECTION_IDunsetMavvrik connection.
MAVVRIK_FOCUS_FREQUENCYdailyOnly daily is allowed, because Mavvrik keeps one file per day.
MAVVRIK_FOCUS_MAX_ROWS500000Most 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​

StatusMeaningFix
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​

LevelMessageMeaningAction
INFOCloudZero export completed successfully or Vantage export completed successfullyA manual export finished.Normal.
INFOCloudZero settings updated successfully, Vantage settings updated successfully, ... deleted successfullyThe settings changed.Normal.
ERRORError 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.
WARNINGInvalid FOCUS_INTERVAL_SECONDS value: <value>, ignoring or Invalid VANTAGE_EXPORT_INTERVAL_SECONDS value: <value>, ignoringThe interval is not a whole number.Fix the variable and restart.