Custom pricing
The gateway prices requests with the price map bundled with each release. Custom pricing replaces those prices for one deployment, which you need for negotiated discounts, self-hosted models, fine-tuned models, models that are not in the price map yet, and pass-through routes. Custom prices flow into spend logs, budgets, reports, exports and invoices exactly like bundled prices, so a self-hosted model shows up in the same monthly report as a hosted one.
A real-world scenario
A platform team hosts an open-weights model on its own GPUs and puts it behind the gateway as internal-llama. The spend report shows every call to it at 0 dollars, so teams treat it as free and nobody can compare it with the hosted models. The team works out that the GPUs cost about 0.10 dollars per million input tokens and 0.20 per million output tokens, adds those prices to the deployment, and from the next request on the model is priced like every other one, shows up in budgets, and the spend report finally reflects what it costs to run.
Give a deployment a price
-
Work out the price per token. A price of 2.50 dollars per million tokens is
0.0000025per token. -
Add the prices to the deployment. In the config file put them in
model_info(orspanway_params) and reload the gateway:model_list:- model_name: internal-llamaspanway_params:model: hosted_vllm/meta-llama/Llama-4-Scoutapi_base: http://vllm.internal:8000/v1model_info:input_cost_per_token: 0.0000001output_cost_per_token: 0.0000002In the Admin UI open Models + Endpoints, click Add Model, open the advanced settings, turn on Custom Pricing, pick Pricing Model (per token or per second) and fill in Input Cost (per 1M tokens) and Output Cost (per 1M tokens), so
0.10and0.20for this example. For a model that already exists, open it on Models + Endpoints, click Edit Model and fill in Input Cost (per 1M tokens) and Output Cost (per 1M tokens), which also take dollars per million tokens. You can still set the per-token keys in the Model Info JSON instead. When models are stored in the database, every instance picks up the change without a restart. -
Check that the price is used:
curl -X POST http://localhost:4000/spend/calculate \-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \-d '{"model": "internal-llama", "messages": [{"role": "user", "content": "Where is my order?"}]}'Expected result:
{"cost": 0.0000012}for a prompt of about twelve tokens. The route reads prices frommodel_infoandspanway_params, follows a model group or alias to its deployment and usesbase_modelwhen it is set. A model with no price answers400withThis model isn't mapped yet., see the errors below. The next real request to the model carries the same price in itsx-spanway-response-costheader and its spend log row.
Pricing units
| Key | Unit |
|---|---|
input_cost_per_token, output_cost_per_token | Per token. |
cache_read_input_token_cost, cache_creation_input_token_cost | Per cached input token read or written. |
output_cost_per_reasoning_token | Per reasoning token. |
input_cost_per_second, output_cost_per_second | Per second, for audio and video models. |
output_cost_per_image | Per generated image. |
input_cost_per_query | Per search query. |
cost_per_request | Flat price per call, for custom pass-through endpoints. |
input_cost_per_character, output_cost_per_character | Per character, for speech and other models a provider bills by text length. |
cost_per_second | Per second of the whole call, for models billed by running time. |
input_cost_per_pixel, output_cost_per_pixel | Per image pixel read or written. |
input_cost_per_token_flex, _priority, _balanced, _ultrafast, and the cache_read_input_token_cost_flex style variants | The rate used when the request asks for that service_tier. A tier without its own rate uses the standard one. |
tiered_pricing | A list of tiers, each with a range of input tokens and its own rates. See below. |
off_peak_pricing | Cheaper rates for hours of the day. See below. |
Prices that depend on the request size
Some providers charge a different rate for every token of a large request. tiered_pricing lists the tiers by input tokens, and the gateway picks one tier from the request's input tokens and bills every token of the request at that tier's rates. A tier matches when the input tokens are above the start of its range and at or below its end, and a request above the last range uses the last tier.
model_info:
tiered_pricing:
- range: [0, 32000]
input_cost_per_token: 0.0000004
output_cost_per_token: 0.0000012
- range: [32000, 128000]
input_cost_per_token: 0.0000012
output_cost_per_token: 0.0000036
A request with 50,000 input tokens is recorded at the second tier's rates for all its tokens, and the spend log row shows that cost.
Cheaper prices at night
off_peak_pricing replaces the rates while one of its windows is open. hours_utc holds windows in UTC such as "16:30-00:30" that apply every day, and windows holds entries with their own hours_utc and weekdays (with weekday_timezone to read the weekday in a local zone). A window may cross midnight, its start counts and its end does not. Any rate the block leaves out keeps its normal value.
model_info:
input_cost_per_token: 0.0000006
output_cost_per_token: 0.0000024
off_peak_pricing:
hours_utc: ["16:30-00:30"]
input_cost_per_token: 0.0000003
output_cost_per_token: 0.0000012
A request at 18:00 UTC is recorded at the off-peak rates, one at 09:00 UTC at the normal rates.
If a deployment runs a model that is in the price map under another name, point base_model at it instead of copying prices. This is the usual fix for Azure deployments, see cost tracking.
model_info:
base_model: anthropic/claude-sonnet-5-5
Discounts and margins
To apply a discount to every model of a provider rather than setting each price, use cost_discount_config in spanway_settings, keyed by provider, with a fraction such as 0.05 for 5 percent off. A margin, for internal billing or cost recovery, is added the same way with cost_margin_config, as a fraction (0.1 adds 10 percent), a fixed amount per request ({"fixed_amount": 0.001}) or both, and the key global applies to every provider.
-
In the Admin UI open Settings, then Cost Tracking. Open Provider Discounts, click + Add Provider Discount, pick the provider, enter
5for 5 percent and click Add Provider Discount. Margins work the same way under Fee/Price Margin. Changes save at once and need a database withSTORE_MODEL_IN_DB=True. -
Or set them with the API, 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}}. The object you send replaces the stored one, so send every provider you want to keep. Each save writes an audit row with the values before and after. -
Check a response. The headers
x-spanway-response-cost-original,x-spanway-response-cost-discount-amountandx-spanway-response-cost-margin-amountshow howx-spanway-response-costwas adjusted, and the Test It tab of the Provider Discounts section works the numbers out for you from those headers.
Models without a price
A request for a model that has no price row, either in the price map or in the deployment's model_info, is recorded as unpriced rather than as free. The spend log row keeps a cost of 0 so totals still add up, its metadata carries zero_cost_diagnostic with the reason model_not_priced, the gateway logs a warning that names the model, and the Prometheus counter spanway_zero_cost_requests_total{reason="model_not_priced"} goes up, so you can alert on it.
To refuse these requests instead, turn on Block requests for models without pricing under Block Unpriced Models on the Cost Tracking page, or set one of these in spanway_settings:
spanway_settings:
block_unpriced_models_when_budgeted: true
block_unpriced_models_when_budgeted refuses only when the request has a budget, which means the key, team, user, customer or organization has a max_budget, the key has a per-model budget, or the gateway has a global max_budget. block_requests_for_models_without_pricing refuses for every caller. Both are off by default. A refused request gets a 403 with the error type model_cost_map_missing that names the model. Add prices with model_info as shown above, or pin a newer price map, to allow it again.
| Setting | Default | On | Off |
|---|---|---|---|
block_requests_for_models_without_pricing | false | Every request for an unpriced model is refused with a 403, so no spend goes unrecorded. Callers of a new or private model see errors until an admin adds its price. | The request goes through and is recorded at 0 dollars and marked unpriced, so budgets do not count it. |
block_unpriced_models_when_budgeted | false | Only requests that have a budget are refused, so budgets stay exact while unbudgeted traffic keeps working. | Same as above. |
Updating and verifying the price map
The gateway loads the price map at start. To pick up new prices without a restart, reload it now or on a schedule. Every reload, schedule change and cancel writes an audit row on Spanway_Config, so you can see who changed the prices a request is billed at and when. In the Admin UI open Models + Endpoints, then the Price Data Reload tab, which reloads now, sets the schedule and shows the Pricing Data Source card.
| Method | Path | Summary |
|---|---|---|
| POST | /reload/model_cost_map | Reload the price map now |
| POST | /schedule/model_cost_map_reload | Reload the price map on a schedule |
| DELETE | /schedule/model_cost_map_reload | Stop the scheduled price map reload |
| GET | /schedule/model_cost_map_reload/status | Show the price map reload schedule |
| GET | /model/cost_map/source | Show where the price map came from |
curl -X POST http://localhost:4000/reload/model_cost_map -H "Authorization: Bearer $SPANWAY_MASTER_KEY"
curl -X POST "http://localhost:4000/schedule/model_cost_map_reload?hours=24" -H "Authorization: Bearer $SPANWAY_MASTER_KEY"
Expected result: {"message": "Price data reloaded successfully! 2841 models updated.", "status": "success", ...} and {"message": "Model cost map reload scheduled for every 24 hours", "status": "success", "interval_hours": 24, ...}. When the fetch fails the call answers 502 and the current prices stay in use.
| Environment variable | Default | What it does |
|---|---|---|
SPANWAY_MODEL_COST_MAP_URL | the public price map | Where the gateway fetches the price map from, an https:// or file:// URL. |
SPANWAY_MODEL_COST_MAP_SHA256 | unset | The SHA-256 the fetched file must have. On: a file with any other digest is rejected and the bundled copy is kept, which stops a changed file from changing your prices. Off: any well-formed file is used. |
SPANWAY_LOCAL_MODEL_COST_MAP | False | True uses only the copy bundled with the build and never fetches, which suits air-gapped gateways. |
For the full bundled map, GET /public/spanway_model_cost_map returns the prices the gateway is using right now, and SPANWAY_LOCAL_MODEL_COST_MAP=True pins it to the copy bundled with the build. When the gateway fetches the price map from SPANWAY_MODEL_COST_MAP_URL (an https:// or file:// URL), set SPANWAY_MODEL_COST_MAP_SHA256 to the hex SHA-256 of the file you expect. A fetched map whose digest differs is rejected and the gateway keeps the copy bundled with the build, the same fallback it uses when the fetch fails or the map fails the size checks.
export SPANWAY_MODEL_COST_MAP_URL=https://prices.internal.example/model_prices_and_context_window.json
export SPANWAY_MODEL_COST_MAP_SHA256=$(shasum -a 256 model_prices_and_context_window.json | cut -d " " -f 1)
Errors
| What you see | Meaning | Fix |
|---|---|---|
400 This model isn't mapped yet. model=<model>, custom_llm_provider=<provider>. Add it here - ... from POST /spend/calculate (error type invalid_request_error). | The model has no price in the price map or on its deployment. | Add input_cost_per_token and output_cost_per_token to model_info, or set base_model. |
Spend log rows at 0 with zero_cost_diagnostic reason model_not_priced. | Requests reached a model with no price. | The same fix. |
403 model_cost_map_missing, Model '<model>' has no pricing in the cost map, so spanway cannot price the request. ... on a request. | One of the block switches is on and the model is unpriced. | Add a price, or turn the switch off. See the error reference. |
400 Invalid provider(s): ... or Discount for <provider> must be between 0 and 1 (0% to 100%) from PATCH /config/cost_discount_config. | A provider name is not one the gateway supports, or a value is outside 0 to 1. | Use the provider names shown in the Admin UI picker and fractions such as 0.05. |
400 Discount for <provider> must be a number. | A discount value is not a number. | Send numbers such as 0.05. |
400 Margin percentage for <provider> must be between 0 and 10 (0% to 1000%), Margin percentage for <provider> must be a number, Fixed margin amount for <provider> must be a number or Fixed margin amount for <provider> must be non-negative. | A margin value is out of range or not a number. | Percentages are fractions up to 10 (1000 percent), fixed amounts are dollars per request, 0 or more. |
400 Margin config for <provider> cannot be empty. Must include 'percentage' and/or 'fixed_amount', or Margin for <provider> must be a number (percentage) or dict with 'percentage' and/or 'fixed_amount'. | A margin object is empty or has the wrong shape. | Send a number, or an object with percentage, fixed_amount or both. |
500 Set `'STORE_MODEL_IN_DB='True'` in your env to enable this feature. | Discounts, margins and the block switch are saved to the database config, which is off. | Set STORE_MODEL_IN_DB=True and connect a database. |
500 Failed to read cost discount config: <reason> or Failed to read cost margin config: <reason>. | The stored values could not be read. The Admin UI then keeps the add buttons off so nothing overwrites them. | Check the database connection and reload the page. |
500 Failed to update cost discount config: <reason>, Failed to update cost margin config: <reason> or Failed to update setting: <reason>. | Saving the config to the database failed. | Check the database connection and retry. |
403 Access denied. Admin role required. Current role: <role> from a price map route. | Only proxy admins may reload or schedule the price map, and admin viewers may read its status and source. | Use a proxy admin key. |
502 Failed to reload model cost map: <reason>. Current pricing data was kept. | The price map could not be fetched or failed its checks. | Check SPANWAY_MODEL_COST_MAP_URL and the digest, then retry. |
500 Internal Server Error (model cost map unavailable) from GET /public/spanway_model_cost_map. | The gateway could not read its price map. Anyone may call this route, so the answer never carries the cause. | Read the Model cost map could not be read log line and check the bundled or fetched map. |
400 Hours must be greater than 0. | POST /schedule/model_cost_map_reload got 0 or a negative number. | Send a whole number of hours, 1 or more. |
| A fetched price map is rejected in the gateway log. | Its SHA-256 did not match SPANWAY_MODEL_COST_MAP_SHA256, or it failed the size checks. | Update the digest after a deliberate change, otherwise treat the mismatch as tampering. |
Logs
| Level | Message | Meaning | Action |
|---|---|---|---|
| WARNING | Billable request has no price and is logged as unpriced (model_group=<group> model=<model> ...): model '<model>' has no price ... Counted in spanway_zero_cost_requests_total{reason="model_not_priced"} | A request reached a model with no price. Its spend log row is recorded at 0 and budgets do not count it. | Add a price, or turn on a block switch. |
| WARNING | register_model: model=<model> has custom pricing but not in built-in cost map ...; cache_creation_input_token_cost and cache_read_input_token_cost will default to 0 for this model | The deployment has its own prices but no cache prices, so cached tokens are free in spend. | Add cache_read_input_token_cost and cache_creation_input_token_cost to model_info when the provider bills them. |
| INFO | Updated cost_discount_config: <values>, Updated cost_margin_config: <values> or Updated block_requests_for_models_without_pricing: <value> | An admin saved a discount, margin or block switch. | Normal. |
| INFO | Model cost map reloaded successfully in current pod. Models count: <n> | A manual reload took effect on this instance. | Normal. |
| INFO | Model cost map reload scheduled for every <n> hours or Model cost map reload schedule cancelled | The reload schedule changed. | Normal. |
| ERROR | Failed to reload model cost map: <reason> | A reload failed and the old prices stay in use. | Check the URL and digest. |
| ERROR | Model cost map could not be read: <error type> | GET /public/spanway_model_cost_map answered 500. | Check the price map file or SPANWAY_MODEL_COST_MAP_URL, then restart. |
Run the gateway with --detailed_debug to see how each request was priced.
Related
- Cost tracking for how a price becomes a spend log row.
- Cost Tracking page for every control of the discounts, margins, block switch and pricing calculator.
- Models and endpoints for adding and editing deployments in the Admin UI.
- Spend capture rate for finding unpriced traffic against the provider bill.
- Pass-through endpoints for
cost_per_requeston custom routes.