litellm/tests/unit/llms/openai
Nicolas Mota 5d43214faf
fix(decisions): forward OpenAI prompt cache fields (#51457)
* fix(decisions): forward OpenAI prompt cache fields

The Decisions client rebuilt the outbound body without prompt_cache_key,
prompt_cache_options, or a prompt_cache_breakpoint, so an explicit cache
prefix never reached OpenAI.

* fix(decisions): refuse prompt cache fields where the provider cannot take them

Only the OpenAI Decisions API reads prompt_cache_key, prompt_cache_options,
prompt_cache_breakpoint, and developer or system messages. Other providers
now raise UnsupportedParamsError for them, and drop them under drop_params,
instead of receiving or silently losing them. The cache fields are explicit
typed parameters of decisions() and adecisions(), and are rejected next to
the System One state format.

* fix(decisions): ignore prompt cache fields where the provider cannot take them

Refusing prompt_cache_key, prompt_cache_options, and developer or system
messages broke requests that a non-OpenAI deployment used to answer, such
as a fallback from an OpenAI model group. Providers without prompt cache
now drop the cache fields and breakpoints before validation, and receive
developer and system text as part of the input.

* fix(decisions): ignore prompt cache breakpoints where the provider cannot take them

A prompt_cache_breakpoint with any shape, such as {"mode": "explicit", "ttl": "30m"}, no longer
gives a 400 on a provider without prompt cache. The SDK drops the key from caller message parts
before validating the request, and the proxy drops it before routing, so the deployment that is
chosen decides. OpenAI and Azure still refuse a malformed breakpoint before any HTTP call.

* fix(decisions): forward 12h and breakpoint cache ttls and bill 12h writes

OpenAI's Decisions API accepts a 12h ttl in prompt_cache_options and a ttl on
prompt_cache_breakpoint, so both now pass through as strings and OpenAI checks
them. The response keeps usage.input_tokens_details.cache_write_tokens_details,
and 12h writes are priced at the 12h cache-write rate instead of the 30m one.

* fix(decisions): drop malformed prompt cache values under drop_params

A prompt_cache_key or prompt_cache_options of the wrong type, or a
prompt_cache_breakpoint whose mode OpenAI cannot read, now goes away
under drop_params instead of answering 400. A breakpoint with a bad ttl
keeps its mode, the same as the Responses route. Without drop_params
these values still get a 400 naming the field.

* fix(decisions): trim prompt cache values to what OpenAI accepts under drop_params

Without drop_params, a cache key, options, or breakpoint ttl reach OpenAI as
written so OpenAI's own 400 answers a value it rejects. Under drop_params, a
key over 64 characters is dropped, options keep each valid field, and a
breakpoint keeps its mode while losing a ttl OpenAI rejects.

Typed OpenAIDecisionPromptCacheBreakpoint and OpenAIDecisionPromptCacheOptions
models are dumped before the check, so a typed value reaches the wire too.

* fix(decisions): answer a 400 for cache fields on providers without prompt caching

prompt_cache_key and prompt_cache_options now follow the unsupported-param rule on a provider without prompt
caching, so they get a 400 without drop_params and are dropped under it. Options mode passes through to OpenAI
like ttl, and drop_params keeps only an accepted mode.

* fix(decisions): trim breakpoints in typed SDK messages under drop_params

A typed OpenAIDecisionInputMessage tree skipped the drop_params breakpoint trimming, so an unaccepted ttl or key reached OpenAI. The logging test now sets drop_params, since a provider without prompt caching refuses cache fields otherwise.

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-18 03:25:09 +00:00
..
chat fix(openai): download PDF URLs off the event loop and transform async chat messages once (#49176) 2026-11-10 16:37:00 +00:00
completion fix(openai): keep the upstream error body on e.response for OpenAI and Azure errors (#49079) 2026-10-29 23:30:02 -07:00
decisions fix(decisions): forward OpenAI prompt cache fields (#51457) 2026-11-18 03:25:09 +00:00
embeddings
evals fix(llms): join api_base and route with one shared helper (#47535) 2026-10-21 06:59:32 +00:00
image_generation refactor(images): remove dall-e-2 and dall-e-3 code paths (#48703) 2026-10-28 17:48:09 -07:00
image_variations fix(openai): keep the upstream error body on e.response for OpenAI and Azure errors (#49079) 2026-10-29 23:30:02 -07:00
live refactor(router): delete the python router core, the rust core is the only core (#50178) 2026-11-05 10:40:46 -08:00
realtime feat(realtime)!: support latest OpenAI audio models (#35600) 2026-11-03 07:27:52 +00:00
responses fix(anthropic): close strict JSON schemas on the Messages to Responses bridge (#51337) 2026-11-12 06:15:14 +00:00
speech
transcriptions fix(cost)!: bill transcriptions by the seconds the provider reports (#50727) 2026-11-09 13:37:55 -08:00
vector_store_files
vector_stores
videos feat(videos): add first-class OpenRouter video request fields (#50319) 2026-11-06 16:50:48 -08:00
__init__.py
test_cost_calculation.py feat(fal_ai): bill fal video clips by duration and resolution (#51679) 2026-11-13 12:55:55 -08:00
test_data_residency.py feat(openai): bill gov.api.openai.com FedRAMP endpoint with 1.1x uplift (#49951) 2026-11-04 08:57:42 -08:00
test_gpt_reasoning_transformation.py refactor(router): route the router family through RoutingContext and close the outside surface (#49118) 2026-10-30 19:18:54 -07:00
test_is_model_gpt_5_model.py refactor(llms): rename model-version transformation files to family names (#48509) 2026-10-26 18:53:16 -07:00
test_o_series_transformation.py fix(openai): stop stripping cache_control from the caller's own messages and tools (#35602) 2026-10-31 00:29:10 -07:00
test_openai.py fix(exceptions): map upstream 403 to PermissionDeniedError for OpenAI-style providers (#52179) 2026-11-17 03:14:09 +00:00
test_openai_audio_speech.py fix(openai): bill the audio output tokens OpenAI reports for gpt-4o-mini-tts speech (#52317) 2026-11-17 11:35:30 -08:00
test_openai_authentication_error.py
test_openai_common_utils.py fix(logging): warn when drop_params drops a requested reasoning level on the remaining paths (#48933) 2026-10-30 08:48:43 -07:00
test_openai_empty_response.py fix(openai): send chat completions through client.post so the SDK's per-message param transform stops holding the event loop (#46967) 2026-10-16 18:06:01 -07:00
test_openai_file_content_streaming.py
test_openai_image_edit_transformation.py
test_openai_workload_identity.py refactor(router): route the router family through RoutingContext and close the outside surface (#49118) 2026-10-30 19:18:54 -07:00
test_organization_costs.py
test_use_chat_completions_api_no_leak.py fix(openai): send chat completions through client.post so the SDK's per-message param transform stops holding the event loop (#46967) 2026-10-16 18:06:01 -07:00