litellm/tests/unit/completion_extras
tavren27 339280356f
fix(responses): reject background on bridged chat completions unless the provider streams it live (#54357)
* fix(responses): reject background on chat completions bridged to the Responses API

A background run answers with a queued response and no output, so the chat bridge
failed with a 500 after OpenAI had already started a billed run, and retries started
more. The bridge now answers 400 UnsupportedParamsError before any upstream call,
unless drop_params, litellm.drop_params, or additional_drop_params drops it, and it
never sends background upstream.

* fix(responses): keep background on streamed chat completions bridged to the Responses API

OpenAI streams a background run's events and the chat bridge turns them into chunks, so a streamed request with background worked before. The background check now applies only to non-streamed requests, where the run's output never reaches the caller.

* fix(responses): reject background on bridged chat completions unless the provider streams it live

A faked stream (fake_stream, or a model without native streaming) still sends a non-streamed request upstream, so background there starts a run /chat/completions cannot retrieve. Treat it like a non-streamed call: drop under drop_params, answer 400 otherwise.

* fix(responses): keep background on providers that strip it and send background false as set

ChatGPT and Bedrock Runtime drop background before the upstream call, so the
chat bridge now asks each provider's Responses config whether it forwards
background and skips the check when it does not. background: false reaches the
provider unchanged, extra_body stream decides whether the run streams live, and
the 400 names additional_drop_params.

* fix(responses): check background with the dispatch's own Responses config

The guard now asks the same resolver the Responses dispatch uses, so a
deployment that passes /v1/responses through is guarded and an azure_ai
base that does not serve the OpenAI v1 API keeps its chat fallback

* fix(responses): let providers that answer background inline keep it, and read faked streams from the dispatch config

OpenRouter, refuseless, openinfer and zerogpu answer a background: true
Responses call in the same reply, so bridged chat completions there keep
sending it instead of getting a 400. The fake-stream check now resolves the
same Responses config the dispatch uses, so a pass-through deployment on a
model without native streaming is refused when it streams with background.

* refactor(responses): run the background check inside the bridge params helper

* fix(responses): check background on Eden AI only where its upstream starts a run

* fix(responses): refuse background only on servers known to start a run

The check now refuses a bridged chat completion with background only where the
server is known to start a run, which is OpenAI and Azure hosts plus the
providers that were seen to queue one. Any other server gets background as it
did before. When such a server answers with an unfinished run, the call ends
in one 400 after that single run, so the Router does not retry it into more.

drop_params and additional_drop_params drop background on every bridged call
that does not stream live. Streams are judged by the Responses config that
serves the call, also when the call is bridged late for its tools, and the
fake-stream timeout goes back to the behavior on main

* fix(responses): judge background by the server a supplied OpenAI client points at

A caller that passes client=OpenAI(base_url=...) sends the request to that base URL, so the background check now reads it instead of OpenAI's default host

* fix(responses): count Azure cognitiveservices hosts as servers that start background runs

An openai/ or custom_openai/ deployment on a *.cognitiveservices.azure.com Azure OpenAI v1 host started one billed run before the 400, so the check now knows that host too

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-12-01 03:01:25 +00:00
..
litellm_responses_transformation fix(responses): reject background on bridged chat completions unless the provider streams it live (#54357) 2026-12-01 03:01:25 +00:00
__init__.py test: add __init__.py to migrated tests/unit packages 2026-09-20 11:53:49 +00:00
test_litellm_responses_transformation_transformation.py test: migrate wave 1 phase 1 legacy tests to tests/unit 2026-09-20 09:17:57 +00:00
test_responses_bridge_provider_propagation.py fix(responses): honor request cache controls on chat completions bridged to the Responses API (#44676) 2026-10-05 17:52:44 -07:00