Cost Optimization page
The Cost Optimization page tracks the mechanisms that save money on model calls, which are prompt compression, prompt caching and auto-routers, and holds the settings for the first two. Auto-routers themselves are created under Models + Endpoints, on the Auto-Routers tab. Open the page at /ui/cost-optimization. In the left nav it is Cost Optimization in the OBSERVABILITY group, with a docs link to the cost optimization guide.
The nav item is shown to the session roles Admin, Admin Viewer, Internal User and Internal Viewer. Org admins (session role Org Admin) do not see the nav item. When the admin has set enabled_ui_pages_internal_users, non-admin roles see the item only if cost-optimization is listed. The page has no guard of its own and needs no license feature. Proxy admins and admin viewers get four tabs. Everyone else gets only the Overall tab, which covers only their own spend.
The header reads Cost Optimization. Under it a notice says This is an experimental dashboard, with a link to share feedback. All tabs share one date range. It starts at the last 30 days and includes the current UTC day.
| Tab | Who sees it |
|---|---|
| Overall | Everyone (selected by default) |
| Prompt Compression | Proxy admins and admin viewers |
| Prompt Caching | Proxy admins and admin viewers |
| Auto-Router | Proxy admins and admin viewers |
What this page is for
Three gateway features save money on model calls, prompt compression, prompt caching and auto routers. This page adds up what each one saved, in dollars and over time, so a platform lead can answer "was it worth it" with numbers, and it holds the settings for compression and caching and the shadow evals that prove an auto router before a team moves to it.
A real-world scenario
A platform lead is asked whether the auto router rolled out last quarter paid off. She opens the page, sets the range to the quarter, and reads on the Auto-Router tab that smart moved 48 million tokens for 212 dollars where the premium model alone would have cost 824. On the Prompt Caching tab the Cache leakage by virtual key card shows one key sending large uncached prompts, which becomes next month's saving.
Step by step
- Open
/ui/cost-optimizationas a proxy admin. On Overall, set the date range and read Total recorded savings and its three parts. - Pick Auto-Router, then Usage. Choose a router in the dropdown and read Total estimated savings, Routing by tier and the Router usage and savings table.
- Pick Prompt Caching. Turn on Automatic Anthropic prompt caching and pick a Cache lifetime (TTL). Set the date range, switch the table to Spanway injected and click a request id to open it on the Logs page.
- Pick Auto-Router, then Shadow Evals. Fill in Start a shadow eval with a team, a router, Traffic sampled 10, Duration 7 days and Spend budget 25, and click Start shadow eval.
The data behind the tabs over the API:
curl "http://localhost:4000/auto_router/benchmarks?start_date=2026-10-22&end_date=2026-11-21" -H "Authorization: Bearer $SPANWAY_MASTER_KEY"
curl "http://localhost:4000/cost_optimization/prompt_caching/requests?start_date=2026-11-01T00:00:00Z&end_date=2026-11-21T00:00:00Z&filter=injected&page_size=50" -H "Authorization: Bearer $SPANWAY_MASTER_KEY"
curl -X POST http://localhost:4000/auto_router/shadow_eval/start \
-H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json" \
-d '{"team_ids": ["team-platform"], "router_names": ["smart"], "direction": "forward", "shadow_percentage": 10, "judge_model": "claude-sonnet-5-5", "duration_days": 7, "max_budget": 25}'
Expected result
The benchmarks call answers with totals and one entry per configured router under groups, each with spend, saved_spend, baseline_spend, saved_pct, tier_turns and a cache block, which the Usage sub tab renders. The prompt caching call answers with a page of requests, each with cache_read_tokens, cache_creation_tokens, spend and net_savings. The shadow eval start answers 201 with the job, and the eval card appears with the status running and refreshes every 15 seconds.
Overall tab
The date range picker sits at the top right, next to a note that spend is bucketed by UTC day. It has the same presets and Apply rule as the date picker on the Usage page.
| Tile | Meaning |
|---|---|
| Total recorded savings | The sum of the three tiles beside it. Auto-router requests without a savings estimate are left out. Its caching term is the share Spanway injected. |
| Compression savings | Tokens removed before the call by the Headroom guardrail and the built-in compression pass, priced at the model's input rate. The hint gives the number of tokens compressed. |
| Prompt caching savings | The headline is the caching saving Spanway earned by inserting cache breakpoints itself. Total beside it also counts requests that brought their own cache_control and providers that cache on their own. Either figure can be negative when traffic writes more cache than it reads. |
| Auto-router savings | The sum of recorded per request savings estimates against each router's highest tier, net of classifier cost. Requests without an estimate add nothing. |
Each tile has an info tooltip with the same explanation.
| Panel | What it shows |
|---|---|
| Savings | Savings over time for Compression, Prompt caching and Auto-router. Cumulative (default) shows a running total that starts at $0 on the first day. Per day shows each day's savings as bars that are not stacked, because a driver can be negative on a day. The subtitle names the range in UTC. |
| Savings by driver | A donut of the drivers that saved money in the range, with the total in the middle. Drivers with zero or negative savings are left out of the donut. |
| Spend by tool | Proxy admins and admin viewers only. Spend on requests that invoked each tool, MCP and client side, for the top 8 tools. Declaring a tool without invoking it does not count. A request that invoked several tools counts its full spend toward each, so the totals overlap. Total by tool is a bar per tool and Daily spend by tool stacks them per day. It shows Loading... and then No tool usage in this range. when there is nothing. |
Prompt Compression tab
The Headroom prompt compression card explains that Headroom is a native guardrail that compresses prompts before they reach the model, that the savings show on the Overall tab, and links to the Headroom setup docs. The tab itself shows no savings numbers. Below that it lists the compression guardrails already configured, each with its name, API base and a badge.
| Badge | Meaning |
|---|---|
| Always on | The guardrail runs on every request (default_on is true). |
| Opt-in | The guardrail runs only when it is turned on for a key, team or request. |
With none configured it says No prompt compression guardrails configured yet. Add one below to start saving on input tokens.
The Add Headroom compression guardrail form creates a new pre-call guardrail of type headroom.
| Field | Type | What it does |
|---|---|---|
| Name | Text, placeholder headroom-compression | The guardrail name. Required (Name is required). |
| Headroom API base | Text, placeholder https://your-headroom-endpoint | The base URL of your Headroom compression service. Spanway calls its /v1/compress endpoint. Required (API base is required). |
| Apply to all requests | Switch, on by default | On compresses every request on the gateway, so savings start at once. Off creates the guardrail as opt-in, so it runs only for keys, teams or requests that name it. |
| Refuse requests when Headroom is down | Switch, off by default | Off sends requests to the model uncompressed while Headroom is unreachable or broken, so traffic keeps flowing and only the savings stop (unreachable_fallback: fail_open). On refuses those requests with a 502 until Headroom recovers (fail_closed). Turn it on only when an uncompressed prompt would break a context or cost limit. |
| Add guardrail | Button | Creates the guardrail. A toast says Compression guardrail created, the form clears and the list reloads. On failure a toast says Failed to create compression guardrail. The button is disabled while saving. |
A notice under the form says that applying compression to all requests is available to everyone, and that turning it on per key or team is a Spanway Enterprise feature, with a link to get a trial key.
Prompt Caching tab
Prompt Caching settings
The Prompt Caching card holds three gateway settings. Each change saves right away. There is no save button.
| Control | Type | What it does |
|---|---|---|
| Automatic Anthropic prompt caching | Switch, off by default (enable_anthropic_prompt_caching) | Lets Claude reuse the start of a long prompt instead of paying full price for it on every turn, which cuts input cost on chats and agents that resend the same instructions. On, the gateway marks the system prompt and the latest turn as cacheable for Claude on Anthropic, Bedrock, Vertex AI and Azure AI. Off, prompts go out as the client wrote them. Callers that share the same provider credentials share the cache. |
| Cache lifetime (TTL) | Dropdown (anthropic_prompt_caching_ttl) | Shown when the gateway offers the setting. Disabled while automatic caching is off. 5m (default) clears the setting so the provider default of 5 minutes applies, which suits chats with quick replies. 1h keeps the cache through long pauses in an agent session, and each cache write then costs twice as much. |
| System messages first for OpenAI | Switch, off by default (openai_system_messages_first) | Helps OpenAI's automatic prompt cache match more often. On, system and developer messages move to the front of each OpenAI and Azure OpenAI chat request, keeping their order. Off, messages keep the order the client sent. Test agents that place instructions on purpose before turning it on. |
A proxy admin should change these. When the gateway refuses a change, the switch or dropdown goes back to its saved value and a toast shows the error. The settings reference lists the same keys with their environment variables.
The card does not appear until the settings have loaded. If they fail to load, a toast says Failed to load prompt caching settings. The same controls are on the Router Settings page.
Prompt caching requests
A date range picker labelled Date range for requests and cache leakage sets the range for this table and the leakage card. The table Prompt caching requests has three filter tabs, All caching, Spanway injected and Cache hits.
| Column | Meaning |
|---|---|
| Request | The request id. Click it to open that request on the Logs page. |
| Model | The model of the request. |
| Spanway injection | Recorded when Spanway inserted the cache breakpoint, Not recorded otherwise. |
| Cache reads and Cache writes | Tokens read from and written to the cache. |
| Actual cost | What the request cost. |
| Net savings | What caching saved on this request, or Unavailable when it cannot be computed. |
Rows per page offers 10 (default), 25, 50 and 100. The page buttons move one page back or forward and the label shows the current page. Without a date range it says Select a date range to view requests. With no matches it says No matching prompt caching requests in this range. On failure it says Could not load prompt caching requests.
Cache leakage
The card is titled Cache leakage by virtual key or Cache leakage by model, switched with the By virtual key (default) and By model tabs. It lists keys or models that send a lot of uncached input with a low cache hit rate, which likely means they are missing prompt caching.
| Column | Meaning |
|---|---|
| Key or Model | The key alias or model, with a sub label where one exists. |
| Uncached input tokens | Input tokens in the range that were neither read from nor written to the cache. |
| Cache hit rate | The share of input tokens served from the cache. |
| Potential savings | About what this input would save with caching, priced at what your cached traffic already nets per cached token after write premiums. A dash means caching is not saving anything overall in the range. |
Click a column header to sort. The first click uses the natural order (most uncached tokens, lowest hit rate, highest savings) and the next click flips it. The default sort is Potential savings, highest first. The card shows Loading..., Could not load key usage for this range. or a message that there is no key or model usage in the range.
Auto-Router tab
The tab has two sub tabs, Usage (default) and Shadow Evals.
Usage
The Auto-router usage header shows the range in UTC, a date range picker and a router dropdown. The dropdown starts at All auto-routers and lists every router that had traffic in the range.
| Part | What it shows |
|---|---|
| Total estimated savings | The saved amount, or Unavailable, with a badge of the percent cheaper or dearer than the baseline. When not every request could be compared it says how many were, and that adaptive and quality routers are excluded. When per router records differ from recorded savings it says the baseline comparison is unavailable. |
| Spend rows | Actual auto-router spend (with a tooltip), split into LLM spend and Classification cost (with a rate per 1,000 turns), then Estimated baseline spend. A row reads Unavailable when the data is missing, and a note explains when some usage predates classification cost tracking. |
| Routing by tier | Turns per tier over the range, with the total number of turns. |
| Session metrics | Avg turns per session (with the session count), Avg session length and Avg tokens per session. Sessions that overlap the range count in full. |
| Router usage and savings | A table with Auto-router, Tokens through router, Cost via router, Cost per 1M tokens, Saved vs. premium model and % saved. The empty state is No auto-routers in this range. |
| Auto-router prompt caching | The Cache hit rate of auto-routed turns, an Expired-miss share with a tooltip (turns that missed the cache because a return to an earlier tier came after its TTL lapsed), a Share of turns bar and a table with Bucket, Turns and Hit rate. The buckets are Same model (the turn used the same tier as the turn before), First visit (a tier not used yet in the session) and Return to tier (a tier used earlier). Turns that arrived out of order across pods are counted in a note and not bucketed. |
The tab shows Loading auto-router usage... while loading. A 403 from the gateway shows Auto-router usage is visible to proxy admin roles only, and any other failure shows Auto-router usage is unavailable right now.
Shadow Evals
A shadow eval blind judges the auto-router on the real traffic of keys, teams or users. Teams and users cover JWT authenticated traffic. It runs either before a switch, against the models the targets use today, or after a switch, against a fixed baseline.
The section lists running evals first. When none is running it shows the most recent finished one. Each eval card shows a status badge (running, completed or stopped), a headline of what it compares and on what share of traffic, and a line with turns judged, turns errored, eval spend against its budget and when it ends. Stop ends a running eval at once. It reads Stopping... while the request is out. There is no confirmation. A red line shows the last failure when some turns errored.
| Result part | What it shows |
|---|---|
| Target table | Shown when the eval covers more than one target, with Target, Status, Budget used, Router wins and the other side's wins. |
| Headline | The share of judged responses where the router matched or beat your current model (adoption check) or the baseline (regression check), and a cost comparison. |
| Verdict bar | Router won, Tie and Current model won or Baseline won, as shares. |
| Slice tables | By Router (when there are several), by Compared against or Router pick, and by Prompt difficulty. Columns are Judged turns, Router wins, the other side's wins, Ties, Judge confidence, Router cost and the other side's cost. |
Before results exist the card says it is collecting verdicts, that no verdicts were recorded, or that results could not be loaded. Previous evaluations lists the other finished evals. Click it to show or hide the list, and click an eval to load its results.
The Start a shadow eval form is hidden for view only roles. Its description changes with the direction.
| Field | Type | What it does |
|---|---|---|
| Direction | Dropdown | Adoption check: key's traffic vs the router (default) sends a sampled slice of the targets' traffic through the router as well. Regression check: router's picks vs a baseline sends a slice of traffic the router already serves to a fixed baseline model as well. The extra answers are never served to users. |
| Keys to shadow | Key search, placeholder Search keys by alias | Keys whose traffic is sampled. |
| Teams to shadow | Team search, placeholder Search teams by alias | Teams whose traffic is sampled. |
| Users to shadow | User search, placeholder Search users by email | Users whose traffic is sampled. At least one key, team or user is required. |
| Only on models | Multi select, placeholder Every model the targets use | Adoption check only. Narrows every target to requests for these models. At most 100. |
| Auto-routers | Multi select, placeholder Select up to 4 auto-routers | At least one is required and at most 4. A regression check takes exactly one router. With several routers in an adoption check, every router sees the same sampled requests. |
| Traffic sampled | Number, default 10 | Percent of traffic sampled, from 0.1 to 100. |
| Duration | Dropdown | 1 day, 3 days, 7 days (default), 14 days or 30 days. |
| Spend budget | Number in dollars, default 10 | The most the shadow and judge calls may spend, per target, from 0.01 to 10000. |
| Baseline model | Model search | Regression check only, and required there. |
| Judge model | Model search | Required. Recommended judge models carry a Recommended label. |
| Start shadow eval | Button | Starts the eval. It reads Starting... while the request is out. It stays disabled until every required field is valid. |
Judge calls bill to the identity of the sampled traffic. Each target gets its own spend budget. Errors from starting or stopping an eval show in a toast. Running evals refresh every 15 seconds. If the gateway refuses the eval list with a 403, the whole section is hidden.
Empty, error and disabled states
| State | What you see | What to do |
|---|---|---|
| Spend data fails to load | A red banner says fetching spend data failed, so the savings may be empty rather than final. | Reload the page. |
| No savings in the range | Tiles read $0 and the donut is empty. | Widen the range, or turn on compression, caching or an auto-router. |
| Compression guardrails fail to load | A toast says Failed to load compression guardrails. | Reload the tab. |
| Auto-router data refused | Auto-router usage is visible to proxy admin roles only. | Use a proxy admin or admin viewer account. |
| Shadow evals fail to load | Existing evaluations could not be loaded. Refresh the page to retry. | Refresh the page. |
| Disabled controls | Cache lifetime (TTL) is disabled while automatic Anthropic caching is off. Add guardrail and Start shadow eval are disabled while saving or while the form is invalid. | Turn caching on, or fix the form. |
Errors
| What you see | Why | Fix |
|---|---|---|
| Auto-router usage is visible to proxy admin roles only | The benchmarks route answered 403. | Use a proxy admin or admin viewer account. |
| Auto-router usage is unavailable right now | The benchmarks call failed, usually because the database is unavailable. | Check the gateway log and the database connection. |
| Existing evaluations could not be loaded. Refresh the page to retry. | The shadow eval list call failed. | Refresh the page. |
| A toast after Start shadow eval naming a router | A router is not a configured auto router, or a target already has a running job in that direction. | Fix the router name, or stop the running job first. |
| Could not load prompt caching requests | The requests call failed or the date range is invalid. | Pick a range with the start before the end and reload. |
| Failed to create compression guardrail | The guardrail write was refused, for example a duplicate name. | Change the Name and try again. |
| Unavailable in the savings rows | The traffic predates savings tracking, or the router is adaptive or quality and has no baseline. | Nothing to fix. Newer complexity router traffic fills the rows in. |
Logs
The page writes no log lines of its own. The gateway lines behind it, such as a shadow eval that could not prepare its counters or a Headroom outage, are in the log reference and on the Headroom page.
Differences by role and license
| Role | What changes |
|---|---|
| Admin (proxy admin) | All four tabs, deployment wide numbers, Spend by tool, and every write action. |
| Admin Viewer | The same tabs and numbers, because Admin Viewers get the deployment wide cost view. The shadow eval form and the Stop button are hidden. The compression form, the caching switches and the TTL dropdown are still shown, but the gateway rejects these changes for a view only admin, so they end in an error toast and the control goes back to its saved value. The gateway also lets only a proxy admin start or stop a shadow eval. |
| Internal User and Internal Viewer | Only the Overall tab, covering only their own spend, without Spend by tool. |
| Org admin | The nav item is hidden. At the URL they get the Overall tab for their own spend only. |
enabled_ui_pages_internal_users | When set, non-admin roles see the nav item only if cost-optimization is listed. |
The page needs no license feature. The note on the compression form says that per key or per team compression needs Spanway Enterprise.
Related
Cost optimization explains the savings baseline, shadow evals and the caching requests table. Headroom covers the compression service. Auto routing covers auto-routers. Caching covers prompt and response caching. The Usage page, the Logs page and the Router Settings page are the related screens.