Repository navigation
feat(pricing)!: a configured price source is tried before LiteLLM's map, and a listed service tier is priced at its own rates - #962
Conversation
…p, and a listed service tier is priced at its own rates `[prices]` names a `PriceSource` (`impl`, `config`, built with `from_config`), and `configured_prices` tries it before the price map the installed LiteLLM bundles, which prices alone without the table, as before. A source that can't be built, or that raises, leaves the map pricing with a warning and never fails a step. Prompt steps, judges and core's own calls all price through `configured_prices`. `ModelPrice.service_tiers` holds a source's rates by service tier, and tokens off the standard tier are charged their tier's rates where it's listed, keeping `standard_service_tier` only where it isn't. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
End to endReal
|
…s, warn once per source - A sum of turns at the standard level and another is charged the standard rates, marked standard_service_tier, rather than every turn at the other tier's rates (Tokens.some_standard). - A step prices all its turns from the prices as they stood when it started (PriceSource.pinned), so a source that refreshes never reprices a turn already recorded. - The config caches the chain of its source and the map, and pinned copies share its warn state, so a source that raises warns once. - An entry whose models were priced from several sources names none in cost_source; each row names its own. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
End to end, review fixesReal
Both costs match a hand calculation from the gateway's token counts at the file's rates. Before this fix, the first row would have charged all four calls at priority rates, with no mark. Pinning has no effect on a source that reads its file once, so the unit test covers it (a source that refreshes between two turns of a step). Every sandbox was removed and the host is stopped. Model spend was about $0.011. |
… couldn't be reached A compose that gets no digest for its base's published image builds the base itself, under another key. One registry timeout during a shard's first chromium compose left the shared env composed that way, so test_a_compose_of_chromium_from_a_release_record's record named locks a later, normal compose didn't match. A lookup that couldn't reach the registry is now tried once more (a missing tag still isn't), and the test names both sides' lock inputs and keys when they differ. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lace for the map fallback - Tokens keeps the agreed service_tier and speed, combined by agreed_service_level as an entry's are, in place of levels and some_standard: a sum of a standard turn and a priority one is mixed (standard rates, marked), and a turn that reported no tier doesn't disagree, so the label and the price can't differ. - Config.get_prices() gives the chain or the map alone; configured_prices() reads it. - RoleUsage.entry() takes its prices, with no empty-table default. - The published-image lookup reads one digest from either try. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
End to end, after the tier refactorThe same runs on
Both costs match a hand calculation from the gateway's token counts at the file's rates. The unit tests cover a priority turn next to a turn that reported no tier, which no agent here produces. Every sandbox was removed and the host is stopped. Model spend was about $0.015. |
… sit beside it [prices] becomes [model_prices] and Config.get_prices() becomes get_model_prices(), leaving room for sandbox prices in a table of their own. No release read [prices], so nothing else changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
End to end, after the table renameThe same runs on
Both costs match a hand calculation from the gateway's counts. Every sandbox was removed and the host is stopped. Model spend was about $0.016. |
…tiers in any case - PriceSource.pinned() is gone: a step is priced at the rates its source lists when the step's last turn is recorded, so a refresh during a step moves that step's earlier turns, never a finished step's. - Core lower-cases a source's service tier names when it looks one up; each tier's rates are complete in themselves. - The docs say what a source matches (the name as called, routing prefix and all) and that its cost_source name carries a version that changes whenever its prices do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
End to end, after the interface changesThe same runs on
Both costs match a hand calculation from the gateway's counts. The source named itself Every sandbox was removed and the host is stopped. Model spend was about $0.015. |
…ce_tiers - ModelPrice.tiers becomes context_tiers (and _tier_rates _context_tier_rates), so the long-context steps and the service tiers can't be mistaken for each other; a service tier's own service_tiers are never read, as its docstring now says. - Config.get_model_prices() and its cache are typed PriceSource. - The price source tests build the stub's config with _stub(fail=...) rather than editing its text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
End to end, after the
|
| Run | Gateway truth | Ledger entry |
|---|---|---|
OpenCode on gpt-5.4-mini, only the first call asks for priority |
3 calls: 1 priority, 2 default |
mixed, $0.0074928 at the standard rates, bound estimated |
OpenCode on gpt-5.4-mini, every call asks for priority |
3 calls, all priority |
priority, $0.0146031 at the Priority tier's rates, bound exact |
OpenCode on gpt-4.1-mini, which only the map lists |
3 calls, default |
litellm@1.106.6, $0.0041372 at the map's rates, bound exact |
| Gemini CLI solver plus a direct judge, the source's file unreadable | 3 calls | Both steps no_price, the run completed, one Price source FilePrices failed warning |
All three costs match a hand calculation from the gateway's counts.
Every sandbox was removed and the host is stopped. Model spend was about $0.019.
…ts for them The map lists priority, flex, balanced and ultrafast rates for hundreds of models (input_cost_per_token_priority and the like), which the loader skipped, so a priority call priced from the map took the standard rates. PriceTable now reads them into ModelPrice.service_tiers as LiteLLM bills them: a rate a tier's keys don't give is the standard one, past a long-context tier too; writes kept a while are charged the standard rates; the fast speed is charged priority's. One call at each tier is priced as LiteLLM's own cost_per_token prices it, under and past the long-context tier, for GPT and Gemini models of the installed map. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
End to end, LiteLLM's map pricing service tiersReal
Before this change, the first run would have been charged the standard rates, about half, and marked. The file-source runs on the same commit came out as before: mixed $0.00718005 All costs match a hand calculation from the gateway's counts. Every sandbox was removed and the host is stopped. Model spend was about $0.025. |
…route PriceTable.lookup tried the name as called and without its first segment, so vertex_ai/global/gemini-3.1-pro-preview (and the same route behind a proxy's openai/ prefix) found nothing, though the map lists vertex_ai/gemini-3.1-pro-preview and gemini-3.1-pro-preview, and every such call went unpriced. It now tries each of the name's segments with its last, in order, and then its last alone, so the route's provider prices it where the map lists one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
End to end, a model called by a provider and region routeThe Gemini runs that came out
Before, these three entries were Every sandbox was removed and the host is stopped. Model spend was about $0.08. |
Every cost is priced from the price map one LiteLLM release bundles. That leaves two gaps:
This adds a seam for a price source that a deployment configures, tried before the map. The map stays the in-tree default and the fallback, so a bare install prices exactly as before.
Change
[model_prices](named for model usage, so sandbox prices can take a table of their own later) names aPriceSource(impl = "module:Class",[model_prices.config]), built withfrom_config(**config)as[runner]is. It's a plain config table with no environment variable.config showreports it, owned byconfig.runtime.PriceSource.listed(model), the one method a source implements, gives a model'sModelPriceand the source's own name forcost_source(Listed), or None for a model it doesn't list. It gets the name as called, routing prefix and all, and matches it to its own ids. The name carries a version that changes whenever its prices do.PriceTable, LiteLLM's map, is aPriceSource, so every caller that passes a table works unchanged.PriceChaintries sources in order.configured_prices()gives the configured source chained beforelitellm_prices(), or the map alone without the table. The config builds and caches it once (Config.get_model_prices()).StepUsage, which also prices judges' calls, andmodel_call.completeboth read it. An embedder that prices usage should too.price: an endpoint's bill, then the configured source, then the map, then an agent's own figure, then unpriced. The agent's figure stays inreported_cost_usd.PriceTable.lookuptries the name as called, then without its first segment, then each of its segments with its last, in order, then its last alone. Sovertex_ai/global/gemini-3.1-pro-preview, and the same route behind a proxy'sopenai/prefix, findvertex_ai/gemini-3.1-pro-preview. Before, they found nothing, and every such call went unpriced.cost_sourceon its entry. Each model row names its own.ModelPrice.service_tiersholds a source's rates by tier, keyed by the names providers give it in any case (one tier may be listed under several, as a tier name and a speed). Each tier's rates are complete in themselves; nothing is taken from the standard ones.standard_service_tier, as before.Tokenskeeps the agreedservice_tierandspeed, combined byagreed_service_levelas the entry's label is: a standard turn plus a priority turn ismixed(standard rates, marked), and a turn that reported no tier doesn't disagree.input_cost_per_token_priority,_flex,_balanced,_ultrafast), andPriceTablenow reads them as LiteLLM bills them: a rate a tier's keys don't give is the standard one, past a long-context tier too; writes kept a while are charged the standard rates; thefastspeed is charged priority's. So OpenAI and Gemini priority and flex calls priced from the map are exact with no source configured.cost_per_token(service_tier=...)for every tiered model of the installed map, under and past the long-context tier: 625 match. The exceptions are LiteLLM's, not the map's: its Fireworks and Bedrock Kimi cost paths ignore the tier (they charge the standard rate while the map lists a priority one, which we charge), and it can't route thegemini-*-latestaliases.!:ModelPrice.tiers(long-context rates) is nowModelPrice.context_tiers, so it can't be mistaken forservice_tiers. The plugin-API check counts it becauseModelPricejoins the plugin surface here. The hub buildsModelPricepositionally and never reads.tiers, so nothing outside agent-env changes.PriceSourcejoinsBASES.Listed,ModelPrice,ContextTier,PriceTable,configured_pricesandlitellm_pricesjoinUSED.[model_prices].Flaky test fix folded in
test_a_compose_of_chromium_from_a_release_record_pulls_its_image_and_the_browser_boots_from_itfailed once on this PR (slow shard 7), withKeyError: 'published'.ReadTimeout, 10 s).published_digestgave None, so that compose built the base itself, under another key and other lock inputs, and left the shared chromium env composed that way. The test's release record came from that compose, and its fresh compose, which reached GHCR, didn't match it._registry_digesttries a lookup that couldn't reach the registry once more. A missing tag (NoSuchImageError) is still asked once.KeyError.tst/unit/env/published_images_test.py::test_a_lookup_that_cant_reach_the_registry_is_tried_once_more, which fails without the retry.Not in this PR
A concrete source lives with the deployment that configures it.
Testing
tst/unit/config/test_price_sources.py, with a stub source intst/util/price_sources.py:cost_sourcenames it. A model the source lacks falls to the map, then to the agent's figure, then to unpriced.tst/unit/config/test_model_call.py:completeprices a model the map lacks from the configured source.tst/unit/config/test_model_pricing.py:mixed, or two names for different tiers keep the standard rates and the mark.cost_per_tokensays, under and past the long-context tier.mixed, charged standard rates and marked. An unreported turn plus a priority turn, or two priority turns, get priority rates. Two spellings of standard stay standard.tst/unit/task_step/usage_models_test.py: an entry whose models were priced from two sources names neither, and each row names its own.tst/unit/config/test_model_pricing.py: a routed name finds its provider's entry before the bare one (region route, behind a proxy route, first prefix, last segment), and the installed map pricesvertex_ai/global/gemini-3.1-pro-preview.tst/unit/config/test_describe.py: the full-surface config reports[model_prices].litellm_priceswhereStepUsageread it now patchconfigured_prices.computer_execsystem-command tests that fail locally fail the same way onmainon macOS (BSDbase64flags).ruffis clean, andcheck_plugin_api.pyreports no break.For the docs site
cost_sourcenames the one that priced each cost.standard_service_tier.🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge; no blocking issue remains from this review.Summary
Adds configurable model prices before LiteLLM’s bundled map, supports listed service-tier rates, and expands lookup for routed model names.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Usage and model name] --> B{Endpoint reported a bill?} B -->|Yes| C[Keep endpoint bill] B -->|No| D{Configured source lists model?} D -->|Yes| E[Use listed rates] D -->|No or lookup fails| F{LiteLLM map lists model?} F -->|Yes| E F -->|No| G{Agent reported a cost?} G -->|Yes| H[Keep agent figure] G -->|No| I[Record as unpriced]Reviews (14) · Last reviewed commit: "feat(pricing): the map finds a model cal..." · Reviewed by Greptile