Repository navigation
fix(batches)!: backport P0 batch-cost, pricing and translation fixes to stable/1.103.x for v1.103.7 - #47732
Conversation
Backport of #45108 to stable/1.103.x. Cherry-picked from 5cd1126 (main). Prerequisite for #45151: adds the claude-haiku-5-5 entries that fix corrects. Cost-map conflicts resolved by appending the new entries; schema test lives under tests/test_litellm on this line. The cost-map schema and its schema test also allow cache_creation_input_token_cost_batches, cache_read_input_token_cost_batches and supports_anthropic_compaction, which these entries carry and main already allows.
… capability flags (#45151) Backport of #45151 to stable/1.103.x. Cherry-picked from 46d440a (main). Adapted to the line: the model-catalog Rust crate is not on this line so its two files are dropped; tests live under tests/test_litellm; conflicts resolved by keeping the line's fields plus the over-100k fields this PR adds. Prerequisite from #39861 ported minimally: the standard above-threshold loop skips *_batches keys, so a non-batch request over 100k is not billed at the batch tier. The batch long-context tier tests are dropped since this line's batch cost path has no long-context tiers, and the runtime profile test calls the line's private _is_adaptive_thinking_model.
…equest carries safeguards (#43955) Backport of #43955 to stable/1.103.x. Cherry-picked from eb5295b (main). Adapted to the line: the transformation lives under anthropic/experimental_pass_through, the integration tests live under tests/integration/providers, and the CLI-beta wire assertion change is dropped since that test is not on the line. The github_copilot safeguards test uses the line's authenticator mock, since per-user Copilot sessions are not on this line.
Backport of #43738 to stable/1.103.x. Cherry-picked from a3552c4 (main). Prerequisite for #43935: adds the gpt-6.1-sol entry that fix corrects. Cost-map conflict resolved by appending the new entry. The cost-map schema and its schema test also allow the *_above_272k_tokens_batches keys this row carries, which main already allows.
Backport of #43935 to stable/1.103.x. Cherry-picked from d7620c7 (main). Ported from the stable/1.104.x adaptation (54f9259): the bridge check lives in litellm/main.py and the effort helpers keep the line's private names. Cost-map edits replay only this PR's reasoning-effort flags (gpt-6-astra and gpt-5.3-codex rows), plus supports_none_reasoning_effort=false on the azure gpt-6.1-sol rows from #46377, which the fix's tests key on. Tests built on gpt-6-sol rows (#42515), the Foundry tools-to-Responses bridge, or a full azure/eu/gpt-6-astra row are dropped since none of those are on this line.
…lures (#47184) Backport of #47184 to stable/1.103.x. Cherry-picked from 3fb95c8 (main). Ported from the stable/1.104.x hand-port (f7b0b09) onto this line's poller, which keeps LiteLLM_ManagedObjectTable and direct prisma table access. Brings the managed-files postgres_storable_json sanitizer from #45703 that this fix needs. Test files keep the line's content plus this PR's own cases.
…47190) Backport of #47190 to stable/1.103.x. Cherry-picked from 0ede0e1 (main). Ported from the stable/1.104.x hand-port (3b7b5ab319). Carries the small typed table helpers that port relies on (_ManagedObjectRow protocol and the _managed_object_table/_user_table/_token_table/_team_table accessors, from the stable/1.104.x base). The poll-starvation integration test is dropped since its base and harness (#42622, integration/_support/prisma_clients) are not on this line. The 404-recovery unit test resets the litellm callback lists so a callback left by an earlier test cannot shadow it.
Backport of #47625 to stable/1.103.x. Cherry-picked from 6564a49 (main). Adapted to the line: the batch accounting retry (track_batch_accounting in proxy_track_cost_callback and its use in check_batch_cost) is ported, while this PR's router-budget charge-once changes in router_utils/batch_utils, budget_limiter and model_max_budget_limiter are left out, since they refactor charge-once code from main (8a33b37, 9acf09f) that is not on this line. The write-started mark keys on a budget reservation only, as the search free tier is not on this line. Tests use the line's _ProxyDBLogger, and the router-budget and search-allowance assertions are dropped.
Prerequisite for the #47419 backport to stable/1.103.x, taken from the stable/1.104.x hand-port 49cacdb4b2. Minimal port of helpers from #41523/#43890/#46647 needed by #47419; behavior changes of those PRs not included. Registrations are tracked in a _runtime_registered_fields side table and cost-map entries stay plain dicts.
…47419) Backport of #47419 to stable/1.103.x. Cherry-picked from 3124797 (main), via the stable/1.104.x port c88cf13cd3. Adapted to the line: the cost-calc threshold changes are applied to this line's loop without the 1.104 base's batch-tier helpers; ModelNotMappedError from #42497 is hand-ported (exception class plus the get_model_info raise and re-raise) so registration lookups can tell an unmapped model from a transient failure; tests whose catalog rows (gpt-6-sol, gpt-6-luna from #42515) are not on this line are retargeted to amazon.nova-micro-v1:0 and gpt-5.6-sol profiles; the test conftest also snapshots _runtime_registered_fields. Billing checked unchanged on this line for a cross-provider alias (keeps cache prices) and for unpriced openai/ft: and bedrock/ap-northeast-1 deployments.
…nce backport Prerequisite for the #47625 backport to stable/1.103.x. Ports only the BATCH_RETRIEVE_CALL_TYPES / is_batch_retrieve_call_type helper from main 9acf09f, which #47625's charge-once helpers call. The rest of that commit (keeping batch retrieves out of router tpm/rpm counters) is not taken: its test passes on this line's tip, since batch retrieves are not stamped with a model group here.
Backport of #38172 to stable/1.103.x, from main 8327cd6 via the stable/1.104.x port 844e02f602. Prerequisite for #47625: RouterBudgetLimiting reads the provider from the logging payload, so the batch poller's aretrieve_batch events reach router budgets at all. Test file placed at tests/test_litellm/router_strategy/ on this line.
Backport of the router charge-once part of #47625 to stable/1.103.x, from main 6564a49 via the stable/1.104.x port 91cb4a55b5. The batch accounting retry already landed in the earlier #47625 commit; this adds the charge-once helpers moved into router_utils.batch_utils and RouterBudgetLimiting's per-batch marker using the line's duration_in_seconds window. The shared-worker test waits for this line's background Redis push before reading spend.
Both model_prices_and_context_window.json and litellm/model_prices_and_context_window_backup.json are byte-identical to main at 6083cf9.
Adds search_free_requests, token_count_model (with litellm_provider enum bedrock/bedrock_mantle), token_count_framing and token_count_tokenizer to ci_cd/generate_model_prices_schema.py using main's definitions, and regenerates model_prices_and_context_window.schema.json. Schema keys are CI-only; the line already fetches main's map at runtime.
Test-only. Takes main's version of test_shipped_tool_search_rule_fills_mapped_claude_entries_without_flag, test_cache_control_injection_tool_config_honors_ttl_for_regional_model_lacking_own_pricing and test_get_model_info_gemini; retargets three tests whose rows main changed or removed (gemini-2.0-flash-001 -> gemini-2.5-flash, gpt-5.1-codex-max -> gpt-5.2 for xhigh, gpt-5.1-chat-latest -> gpt-5.1); registers this line's unsupported providers in PROVIDER_LABELS_WITHOUT_A_MODEL_SET; adds extraction mode, main's enum lists and every key main's map uses to test_utils' inline schema, plus main's seedance cost exceptions.
Matches main's resolved aiohttp and its claude-agent-sdk pin (==0.2.165, dev group). Lock moved only those two packages.
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
@litereview code-review |
|
@greptileai review |
|
The failing tests are the same 4 failures and 2 errors, all in
The line tip Cause: these Rust-extension tests expect native sync |
PR overviewAll previously flagged issues have been addressed. No open security concerns remain on this pull request. Security reviewNo open security issues remain on this pull request. Fixed/addressed: 1 · PR risk: 0/10 |
|
|
@litereview code-review |
|
@veria-ai Same code is on main (transformation.py:2984, caching_handler.py:1075), so this needs a fix on main first, then carry it to every backport line |
|
bugbot run |
|
@greptileai review |
|
This PR is too large for Bugbot to review. It changes 74,946 lines and 4,067,017 characters. Split the change into smaller pull requests to get a review. |
…translation_cost_stable_1_103_x # Conflicts: # litellm/model_prices_and_context_window_backup.json # litellm/proxy/hooks/proxy_track_cost_callback.py # litellm/responses/litellm_completion_transformation/streaming_iterator.py # model_prices_and_context_window.json # tests/test_litellm/proxy/hooks/test_proxy_track_cost_callback.py # tests/test_litellm/test_utils.py # uv.lock
|
|
TLDR
Opened under the author's account (Devin was asked to open it; the author's GitHub link was active), so this PR needs a reviewer's approval.
Problem this solves:
How it solves it:
Intentional product change: Azure gpt-6-astra now rejects
reasoning_effort: none, gpt-5.3-codex rejectsminimal, and custom- or zero-priced deployments bill catalog priority/flex rates onservice_tierrequests, all as main does.User Flow
Before: on 1.103.4 several requests fail outright or are billed wrong
"safeguards": [...]to an Anthropic model returns 400 "safeguards: Extra inputs are not permitted""reasoning_effort": "none"returns 400 from OpenAIAfter: the same requests succeed and are billed at the right rates
dangerous-tool-use-2026-09-03betaLinear ticket
p0-regression: LIT-9498
Resolves LIT-9498 (#47155, #47184), LIT-9499 (#47190), LIT-9950 (#47625), LIT-9898 (#47419), LIT-9133 (#44460), LIT-9394 (#45659), LIT-9393 (#45686), LIT-8284 (#43955), LIT-9082 (#43935), LIT-9660 (#47182)
Picks
Each pick fixes a bug present on 1.103: at least one of its own added tests fails on the line tip
dce7feb75cand passes here.incompleteand echo request params#/$defsrefs in json_schemapostgres_storable_jsonfrom fix(responses): bill a background response once, on the first read or poll that sees it finished #45703)model_map_informationreports the entry billing usedModelNotMappedErrorfrom fix(spend): return 400 from /spend/calculate for a model with no pricing row #42497Dropped:
Dependencies and cost map
model_prices_and_context_window.jsonand the backup are byte-identical to main at6083cf97769aeedb2719c5b5c901ded3106cc79eScreenshots / Proof of Fix
Live replay against real OpenAI and Anthropic, one proxy per tree, same config (
/tmp/p0_live/config.yaml:claude-sonnet= anthropic/claude-sonnet-4-6,claude-haiku-5-5,gpt-6.1-sol,drop_params: true).Before (dce7feb)
Safeguards beta (#43955)
POST /v1/messages {"model":"claude-sonnet","max_tokens":16,"safeguards":[{"type":"dangerous_tool_use"}],...}AnthropicException - safeguards: Extra inputs are not permittedgpt-6.1-sol reasoning effort none (#43935)
POST /v1/chat/completions {"model":"gpt-6.1-sol","reasoning_effort":"none",...}OpenAIException - Unsupported value: 'reasoning_effort' does not support 'none' with this modelclaude-haiku-5-5 cost (#45151)
POST /v1/chat/completions {"model":"claude-haiku-5-5",...}x-litellm-response-costheader absent (model not priced)Truncated Responses (#44460)
POST /v1/responses {"model":"claude-sonnet","input":"Count from 1 to 200...","max_output_tokens":16}status: incomplete,incomplete_details.reason: max_output_tokens,max_output_tokens: null(request param not echoed)After (d898de4)
Safeguards beta (#43955)
msg_...with text contentgpt-6.1-sol reasoning effort none (#43935)
"content": "Hi!"claude-haiku-5-5 cost (#45151)
x-litellm-response-cost: 8.2e-06Truncated Responses (#44460)
status: incomplete,incomplete_details.reason: max_output_tokens,max_output_tokens: 16Everything else
ModelNotMappedErrorhand-port escapes no existing handler. On the cost-calculator, converse and utils test files, head and the line tip fail the same 9 tests, so none is new on head. A first pass reported 9 head-only failures, but rerunning the same files on both trees showed identical failure setsType
🐛 Bug Fix
Caveats (if any)
Severe
service_tierrequests on custom- or zero-priced deployments now bill catalog tier rates (from fix(router): bill service tiers at catalog rates for custom-priced deployments #43890, matches main)reasoning_effort: none; gpt-5.3-codex rejectsminimal(fix(openai): drop unsupported reasoning effort for gpt-6.1-sol #43935, matches main)High
With the bundled map (
LITELLM_LOCAL_MODEL_COST_MAP=True), 477openrouter/*rows are gone, as on main (refactor(cost-map): remove openrouter rows, part 1 of 5 #45665)openrouter/openai/gpt-4ocost: 0.0035 on 1.103.4,ModelNotMappedErrorhere and on mainWithout Redis, fix(batches): retry confirmed pre-accounting failures #47625's per-batch markers can evict router budget counters (same bug on main)
Medium
With shared exact caching, a Responses cache hit can return another caller's echoed
metadata(from fix(responses): report truncated bridged output as incomplete and echo request params #44460, flagged by Veria)transformation.py:2984,caching_handler.py:1075), so the fix belongs on main firstBundled-map changes from the mirror: 11 github_copilot rows removed, azure/gpt-4o-mini family repriced, 19 azure region codex/pro rows move from
chattoresponsesmode7 providers in main's map are not on this line, so the provider-registration test exempts them (they cannot be routed here)
Provider budgets now count embeddings and other API surfaces (fix(router): count provider budget spend on every API surface #38172)
Azure EU gpt-6-astra price corrected to match the other gpt-6-astra rows (cost map mirror)
register_modelcustom rates now also apply to region-prefixed Bedrock profiles (fix(bedrock): resolve profile pricing before applying custom rates #47419)Cross-region profile ARNs still bill the base row; needs fix(bedrock): bill the regional row for inference-profile ARNs that embed a cross-region prefix #46128, not on this line
Test infra: the line's conftest now also restores the new pricing-registration table between tests, and batch tests reset callback lists
Low
router.completionnot counted toward provider budgets; Router with a provider budget built outside an event loop raises