Cost Tracking page
The Cost Tracking page holds the settings that change how the gateway prices requests. Use it when your provider gives you a negotiated discount that the recorded cost should reflect, when you charge internal teams a fee on top of provider cost, when you want requests for models without a price refused rather than logged at 0, or when you want to estimate what a planned workload will cost before anyone sends it. A proxy admin sets the discounts, margins and the block switch, and every role that can open the page gets the pricing calculator. Open it at /ui/cost-tracking. In the left nav it is Cost Tracking, inside the Settings menu of the Settings group.
A real-world scenario
A company negotiates a 5 percent discount with one provider and charges each internal team a 10 percent operating fee. The platform admin adds the discount under Provider Discounts and the fee under Fee/Price Margin, and from the next request on every spend log row, budget and invoice reflects both. Before a new team launches a feature, its lead uses the Pricing Calculator to estimate 100,000 requests a month on two candidate models and exports the estimate as a CSV for the budget request.
Add a discount and check it on a response
-
Open Settings, then Cost Tracking, and click the Provider Discounts header to open the section.
-
Click + Add Provider Discount, pick the provider under Provider, enter
5under Discount Percentage and click Add Provider Discount.Expected result: the toast Discount configuration updated successfully, and a row for the provider reading
5.0%. The same setting from a script, as a proxy admin:curl -X PATCH http://localhost:4000/config/cost_discount_config \-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \-d '{"anthropic": 0.05, "openai": 0.01}'Expected result:
{"message": "Cost discount configuration updated successfully", "status": "success", "values": {"anthropic": 0.05, "openai": 0.01}}. -
Send a request to a model of that provider with
curl -iand read the headers.x-spanway-response-costis the final cost,x-spanway-response-cost-originalthe cost before the discount andx-spanway-response-cost-discount-amountthe amount taken off. Paste the first and the last into the Discount Calculator on the Test It tab to see the percentage worked out. -
To estimate a workload, open Pricing Calculator, pick a model under Model, leave Input Tokens at
1000and Output Tokens at500, enter100000under Requests/Month, and read Total Monthly under Cost Estimates. The same estimate from a script:curl -X POST http://localhost:4000/cost/estimate \-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \-d '{"model": "claude-sonnet-5-5", "input_tokens": 1000, "output_tokens": 500, "num_requests_per_month": 100000}'Expected result: the per request cost and the monthly total, with the discounts and margins above already applied.
The nav item is shown to the session roles Admin (proxy admins) and Admin Viewer (proxy admin viewers). Org admins, internal users and internal viewers do not see it. The page has no extra guard of its own. No license feature is needed.
The page header reads Cost Tracking Settings with a Docs menu that links to Custom pricing for models and Spend tracking. The line under it says changes are saved automatically, which is true for every edit below. There is no separate save button.
The content is a stack of collapsible sections. Provider Discounts, Fee/Price Margin and Block Unpriced Models start closed, and Pricing Calculator starts open. Click a section header to open or close it.
Provider Discounts section
Shown only to the session role Admin. A discount lowers the recorded cost of every request to that provider, using final_cost = base_cost × (1 - discount%/100). It helps when you negotiated a lower price with a provider: spend, budgets and reports then match your real bill. With no discount the list price is recorded. A discount applies from the next request, makes budgets last longer, and is written to the audit log. The section has two tabs, Discounts and Test It.
Discounts tab
The + Add Provider Discount button opens the add dialog. Below it is the table of configured discounts, sorted by provider name.
| Column | Meaning |
|---|---|
| Provider | The provider logo and name. |
| Discount Percentage | The discount with one decimal, for example 5.0%, and an edit button. |
| Actions | A remove button. |
Click the edit button to change a discount in place. Type a value from 0 to 100, then press the check button or Enter to save, or the cross button or Escape to cancel. A value outside 0 to 100, or one that is not a number, is dropped without saving or showing a message.
Click the remove button to open the Remove Provider Discount dialog, which asks Are you sure you want to remove the discount for the provider. Remove deletes that provider's discount from the saved configuration and Cancel keeps it. A removed discount can only be restored by adding it again, and requests made in between are priced without it.
A successful change shows Discount configuration updated successfully.
Add Provider Discount dialog
| Field | Type | What it does |
|---|---|---|
| Provider | Searchable select | The provider to discount. Providers that already have a discount are left out of the list. The placeholder is Select provider and an empty search shows No providers found. |
| Discount Percentage | Text | The discount as a percentage, for example 5 for 5%. It must be from 0 to 100. |
Add Provider Discount stays disabled until both fields have a value. A value outside 0 to 100 shows Discount must be between 0% and 100%. The gateway also checks the provider name and rejects anything that is not a supported provider. Closing the dialog clears the form.
Test It tab
This tab explains how discounts show up on a response and lets you check one by hand. It lists the formula, an example (a 5% discount on a $10.00 request costs $9.50) and the valid range of 0% to 100%. It shows a sample curl call and the three response headers to look at, x-spanway-response-cost (final cost after discount), x-spanway-response-cost-original (cost before discount) and x-spanway-response-cost-discount-amount (amount discounted).
The Discount Calculator takes two values copied from those headers.
| Field | What it does |
|---|---|
| Response Cost (x-spanway-response-cost) | The final cost from the response header. |
| Discount Amount (x-spanway-response-cost-discount-amount) | The discount amount from the response header. |
When both are filled with numbers other than zero, Calculated Results shows Original Cost, Final Cost, Discount Amount and Discount Applied as a percentage. This calculator runs in the browser only and saves nothing.
Fee/Price Margin section
Shown only to the session role Admin. A margin adds a fee on top of provider cost, for internal billing or cost recovery. It helps when you charge teams or customers for AI use, because their spend already includes your fee. With no margin only the provider cost is recorded. A margin applies from the next request, makes budgets run out sooner, and is written to the audit log. The + Add Provider Margin button opens the add dialog. Below it is the table of configured margins, with the global margin first and the rest sorted by provider name.
| Column | Meaning |
|---|---|
| Provider | The provider logo and name, or Global (All Providers) for the global margin. |
| Margin | The margin as a percentage, a fixed amount in USD with six decimals, or both joined with +, followed by an edit button. |
| Actions | A remove button. |
Editing a row shows a percentage box and a fixed amount box side by side. Fill either or both and press the check button to save, or the cross button to cancel. The percentage must be from 0 to 1000 and the fixed amount must be 0 or more. A value outside its range is dropped without a message, so if only one of the two is valid, only that one is saved, and if neither is valid nothing changes.
Click the remove button to open the Remove Provider Margin dialog. Remove deletes that margin from the saved configuration and Cancel keeps it. A removed margin can only be restored by adding it again.
A successful change shows Margin configuration updated successfully.
Add Provider Margin dialog
| Field | Type | What it does |
|---|---|---|
| Provider | Searchable select | Global (All Providers) applies the margin to every provider. The other options are the providers that do not have a margin yet. The placeholder is Select provider or 'Global'. |
| Margin Type | Radio | Percentage-based (the default) or Fixed Amount. |
| Margin Percentage | Text | Shown for Percentage-based. For example 10 for a 10% margin. It must be from 0 to 1000. |
| Fixed Margin Amount | Text | Shown for Fixed Amount. A fixed USD fee per request, for example 0.001. It must be 0 or more. |
Add Provider Margin stays disabled until a provider and the value for the chosen type are filled. Picking Global (All Providers) when a global margin already exists shows Margin for Global already exists. Edit it in the table above. Out of range values show Percentage must be between 0% and 1000% or Fixed amount must be non-negative. A new margin uses one type only. To combine a percentage with a fixed amount, add the margin and then edit the row.
Block Unpriced Models section
Shown only to the session role Admin. It holds one switch, Block requests for models without pricing. When it is on, a request whose resolved model has no entry in the cost map is rejected with a 403, so an admin can add pricing before more unpriced spend is logged as $0. It is off by default. The help text under the switch says in plain words what on and off do. On, callers of a new or private model get errors until an admin adds a price, which keeps budgets and chargeback exact. Off, the request goes through, is recorded at $0 and marked unpriced, so budgets do not count it. It points to block_unpriced_models_when_budgeted in spanway_settings, which refuses unpriced models only for requests that have a budget: a key, team, user, customer or organization budget, a per-model key budget or the gateway's global max_budget. Unpriced requests that do go through are counted in spanway_zero_cost_requests_total with the reason model_not_priced. Each change is written to the audit log.
The switch saves as soon as you flip it and shows Requests for models without pricing will now be blocked or Requests for models without pricing are now allowed. It is disabled while the setting loads and while a change is being saved.
Pricing Calculator section
Shown to everyone who can open the page. It estimates cost for the traffic you expect, using the same pricing the gateway applies to real requests, including the discounts and margins above.
A Per Day or Per Month choice at the top sets the period. Per Month is the default. Switching the period clears the request counts entered for the other period.
Each row of the table is one model.
| Column | Type | What it does |
|---|---|---|
| Model | Searchable select | A model group on the proxy. The placeholder is Select a model. A row without a model is not estimated. |
| Input Tokens | Number | Expected input tokens per request. It defaults to 1000. |
| Output Tokens | Number | Expected output tokens per request. It defaults to 500. |
| Requests/Month or Requests/Day | Number | Expected requests in the chosen period. It is empty by default, and the period totals appear only when it is filled. |
| Remove | Button | Removes the row. It is disabled when only one row is left. |
Add Another Model adds a new empty row. The estimate for a row is fetched about half a second after you stop typing.
Cost Estimates
Once a row has a result, Cost Estimates shows the combined totals and a per model table.
| Item | Meaning |
|---|---|
| Total Per Request | The cost of one request to each selected model added together. |
| Total Monthly or Total Daily | The combined cost for the period, from the request counts entered. |
| Margin Fee/Request and Monthly Margin Fee or Daily Margin Fee | Shown only when a margin applies. The margin part of the totals. |
The per model table has the columns Model, Per Request, Margin Fee and Monthly or Daily. A row whose model has no pricing shows a warning that no pricing data was found and that base_model should be set in the config. Click the arrow at the end of a row to show its breakdown, with Total/Request, Input Cost, Output Cost, Margin Fee, the period total for the entered request count, the period input, output and margin costs, and the token pricing per 1M input and output tokens.
The Export menu appears when at least one row has a result.
| Option | What it does |
|---|---|
| Export as PDF | Opens a print view of the estimates in a new window and starts printing. If the browser blocks the popup, an alert asks you to allow popups. |
| Export as CSV | Downloads cost_estimate_multi_model_<date>.csv with the combined totals and one line per model. |
CloudZero Cost Tracking tab
The CloudZero export is set up outside this page, in the CloudZero Cost Tracking tab of the Logging and Alerts page under Settings. It is described here because it exports the same cost data. Only proxy admins can create, edit, delete, dry run or export, and Admin Viewers can see the saved settings.
When nothing is set up the tab shows No CloudZero Integration Found and an Add CloudZero Integration button that opens Create CloudZero Integration.
| Field | Type | What it does |
|---|---|---|
| CloudZero API Key | Password with show and hide button | Required. The message Please enter your CloudZero API key appears when it is empty. |
| Connection ID | Text | Required. The message Please enter your CloudZero connection ID appears when it is empty. |
| Timezone | Text | The timezone for date handling. It defaults to UTC when left empty. |
Create saves the integration and Cancel closes the dialog without saving.
Once set up, the tab shows CloudZero Configuration with a status badge, and the rows API Key (Redacted), Connection ID and Timezone. The API key is only ever shown masked.
| Control | What it does |
|---|---|
| Edit | Opens Edit CloudZero Integration with the same fields. Leave CloudZero API Key empty to keep the saved key. Connection ID is required. Update saves the change. |
| Delete | Opens Delete CloudZero Integration?, which lists the connection ID and timezone and warns that all associated settings are permanently removed. Confirming deletes the integration and cannot be undone. Cost data already sent to CloudZero is not affected. |
| Run Dry Run Simulation | Builds the export for up to 10 records without sending anything, then shows the output under Dry Run Results. |
| Export Data Now | Opens Export Data to CloudZero, which warns that the current accumulated cost data will be pushed to CloudZero. Export sends it and replaces the matching hourly data there. |
Errors
| What you see | Meaning | Fix |
|---|---|---|
| No provider discounts configured or No provider margins configured. | Nothing is set yet. | Click the add button. Loading configuration... shows while the settings load. |
| Failed to fetch discount configuration: | GET /config/cost_discount_config or GET /config/cost_margin_config failed, for example Failed to read cost discount config: <reason> or DB not connected. The page refuses to save until the stored values load, so a save cannot wipe them. | Check DATABASE_URL and the database, then reload the page. |
| The saved discounts did not load, so nothing was changed. Refresh the page and try again. | An edit or remove was tried after a failed load. | Reload the page. |
| Failed to update discount configuration or Failed to update margin configuration, or the gateway's own reason. | The save was rejected. The common reason is Set 'STORE_MODEL_IN_DB='True' in your env to enable this feature. | Set STORE_MODEL_IN_DB=True on the proxy and connect a database. |
Invalid provider(s): ... or Discount for <provider> must be between 0 and 1. | The provider is not one the gateway supports, or the value is out of range. | Pick a provider from the list and a percentage from 0 to 100. |
Margin percentage for <provider> must be between 0 and 10 or Fixed margin amount ... must be non-negative. | A margin is out of range. | Use 0 to 1000 percent, or a fixed amount of 0 or more. |
| An edited value is dropped without a message. | The inline editor received a value outside its range or not a number. | Enter a number inside the range and press the check button. |
| A calculator row shows a warning that no pricing data was found. | The model has no price in the price map or its model_info. | Add custom pricing or set base_model. |
| Select models above to see cost estimates. | No row has a model yet. | Pick a model. Calculating costs... shows while the first estimate loads. |
A row shows its model name and model not found. | The model is not on the gateway. | Pick a model group that exists on the Models + Endpoints page. |
| An add button stays disabled. | A required field is empty. | Fill in the provider and the value. The Block Unpriced Models switch is disabled while it loads or saves, and the remove row button when only one row is left. |
Audit and logs
Every save on this page writes an audit row on Spanway_Config with the object cost_discount_config, cost_margin_config or block_requests_for_models_without_pricing, who saved it, and the values before and after. A first save records an empty object or false as the before value. The gateway logs Updated cost_discount_config: <values>, Updated cost_margin_config: <values> and Updated block_requests_for_models_without_pricing: <value> at INFO for each save, and Error fetching cost discount config: <reason> or Error updating cost discount config: <reason> at ERROR when the database read or write fails. See custom pricing logs for the pricing warnings.
Differences by role and license
| Role | What changes |
|---|---|
| Admin (proxy admin) | Sees every section and can change discounts, margins and the block setting. |
| Admin Viewer | Sees only the pricing calculator, because the discount, margin and block sections are rendered only for the session role Admin. The gateway also rejects every change for a view only admin. |
| Org admin, internal user, internal viewer | The nav item is hidden. If they open the URL directly, only the pricing calculator section is rendered, and the page does not ask the gateway for the admin-only settings, so no error toast appears. |
The page needs no license feature.
Related
- Custom pricing for the discount, margin and block settings behind this page, and for setting your own model prices.
- Cost tracking for how the gateway records spend.
- Cost exports for the CloudZero tab and the other export destinations.
- Spend capture rate for finding traffic with missing prices.
- Logging for the other callbacks.