litellm/tests/unit
Mateo Wang deba473821
fix(cost): bill batch prompts above 272K at OpenAI's long-context batch tier (#39861)
* fix(cost): bill batch prompts above 272K at OpenAI's long-context batch tier

* fix(cost): mirror batch long-context keys on custom pricing params

Register the two *_above_272k_tokens_batches keys on CustomPricingLiteLLMParams so a per-deployment override stays out of the shared backend key, add them to the inline model-info schema and alias-count tests, and build LiteLLM_Params and GenericLiteLLMParams through model_validate at the two dict-splat call sites so basedpyright's reportArgumentType budget ratchets down instead of blocking the new fields.

* fix(cost): add the gpt-5.5-pro batch long-context tier and ignore malformed batch tier keys

* fix(cost): bill cached batch tokens at OpenAI's cached batch rate

Adds cache_read_input_token_cost_batches and
cache_read_input_token_cost_above_272k_tokens_batches for the tiered
OpenAI entries at half the standard cached rate, bills cached batch
tokens at that rate per output line, and parses string-valued batch
rates in deployment-level model_info.

* fix(cost): bill batch cache writes at the batch cache-write rate and carry published batch rates for one-sided deployments

OpenAI's Batch table prices cache writes for gpt-6-astra, gpt-5.6, gpt-5.6-sol, gpt-5.6-terra and gpt-5.6-luna at half the standard cache-write rate, so the cost map gains cache_creation_input_token_cost_batches and its above_272k tier for those entries and batch cost pulls written tokens out of the input bucket at that rate; models without the key keep billing writes at the batch input rate.

A deployment declaring only one side of its batch pricing now carries every published batch rate of the other side (tier, cached, cache write), its own keys win, and a lone tier, cached or cache-write batch key counts as declared pricing instead of being ignored.

* fix(cost): select the batch long-context tier from any batch tier key

A deployment that declares its own flat standard input rate keeps every
published batch rate of the output direction, including the 272K output
tier, but the tier was only ever selected when an input tier key was also
present. Detect the crossed tier from any of the four batch tier keys so
the carried output, cache-read, and cache-write tiers bill at their tier
rate above 272K tokens.

* chore(proxy): keep the OpenAPI snapshot as CI generates it

* fix(cost): pick each batch price component's tier from its own keys

The batch rate picker crossed one threshold for every component, so a
deployment declaring only an output tier also moved its input, cached, and
cache-write rates to that cutoff. Each component now crosses its own
*_above_<N>k_tokens_batches keys and falls back to its flat key.

The JSON schema is regenerated with the generator as it is on main:
cost-map-guard renders the PR's cost map with the base branch's generator,
so the descriptions for the new batch cache keys move to a follow-up.

* chore(proxy): restore the lazy OpenAPI snapshot to what CI's Python 3.12 generates

The merge commit carried a snapshot regenerated on a Python 3.14 venv, which dedents
docstrings at compile time, so one description line differed from the file CI regenerates
on 3.12 and the schema.d.ts sync check went red. The snapshot is byte-identical to main again
2026-09-22 10:22:41 -07:00
..
a2a_protocol test(a2a): sort imports in merged bedrock agentcore test 2026-09-21 16:10:40 +00:00
anthropic_interface test: add __init__.py to migrated tests/unit packages 2026-09-20 11:53:49 +00:00
batches fix(cost): bill batch prompts above 272K at OpenAI's long-context batch tier (#39861) 2026-09-22 10:22:41 -07:00
chat_completions feat(rust-bridge): add cache and secret migration foundations (#42328) 2026-09-22 03:41:04 +00:00
completion_extras test: add sync and async custom_llm_provider bridge propagation tests 2026-09-20 13:46:52 +00:00
compression test: add __init__.py to migrated tests/unit packages 2026-09-20 11:53:49 +00:00
endpoints test: add __init__.py to migrated tests/unit packages 2026-09-20 11:53:49 +00:00
enterprise test(unit): make bedrock collector and secret scan timing tests deterministic (#42405) 2026-09-22 09:30:28 -07:00
integrations chore: merge main into litellm_migrate_tests_p1 2026-09-20 12:54:53 +00:00
litellm_core_utils fix(cost): honor per-second custom pricing on chat completions for every provider (#42403) 2026-09-21 22:15:35 -07:00
llms test(unit): make bedrock collector and secret scan timing tests deterministic (#42405) 2026-09-22 09:30:28 -07:00
messages feat(rust-bridge): add cache and secret migration foundations (#42328) 2026-09-22 03:41:04 +00:00
models feat(auth): breached password detection, self-service change-password and forced password reset 2026-09-21 18:48:35 +00:00
ocr feat(rust-bridge): add cache and secret migration foundations (#42328) 2026-09-22 03:41:04 +00:00
passthrough test: migrate phase 15 legacy tests to tests/unit 2026-09-20 11:55:43 +00:00
rag test: add __init__.py to intermediate tests/unit packages 2026-09-20 12:55:27 +00:00
realtime_api test: add __init__.py to new tests/unit packages 2026-09-20 12:36:13 +00:00
repositories test: add __init__.py to new tests/unit packages 2026-09-20 12:36:13 +00:00
router_strategy fix(auto-router): skip JEV for encrypted delegated tasks 2026-09-21 18:29:21 +00:00
router_utils Merge pull request #42080 from BerriAI/litellm_prompt_caching_affinity_lookback 2026-09-21 12:44:34 -07:00
rust_bridge Merge remote-tracking branch 'origin/main' into litellm_migrate_tests_p15 2026-09-20 13:44:24 +00:00
sandbox test: add __init__.py to every tests/unit directory phase 16 touches 2026-09-20 11:52:38 +00:00
skills test: add __init__.py to every tests/unit directory phase 16 touches 2026-09-20 11:52:38 +00:00
test_router test: add __init__.py to every tests/unit directory phase 16 touches 2026-09-20 11:52:38 +00:00
types test: add __init__.py to every tests/unit directory phase 16 touches 2026-09-20 11:52:38 +00:00
videos test: migrate phase 16 legacy tests to tests/unit 2026-09-20 10:59:02 +00:00
__init__.py test(unit): add package markers to migrated unit test directories 2026-09-20 11:53:14 +00:00
AGENTS.md docs(tests): define the tier contract for unit, integration and e2e 2026-09-20 06:24:06 +00:00
conftest.py test: use main's local_model_cost_map fixture in tests/unit/conftest.py 2026-09-20 13:44:30 +00:00
test_package_layout.py test(unit): make every tests/unit directory a package so pytest collection is unique 2026-09-20 11:50:59 +00:00
test_socket_policy.py test(unit): block external sockets at import time and add a socket policy regression test 2026-09-20 08:07:50 +00:00