From f6287c88b537cb59774b49376bc1b707ba3c8d61 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Thu, 29 Oct 2026 05:00:49 -0700 Subject: [PATCH] fix(passthrough): forward the client's OpenAI-Beta only on agents, vaults, and ChatKit paths --- .../llm_passthrough_endpoints.py | 22 +++++++---------- .../test_llm_pass_through_endpoints.py | 24 +++++++++++++++++++ 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py b/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py index b315d7231c9..f96fab75bd1 100644 --- a/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py +++ b/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py @@ -3532,6 +3532,7 @@ async def deepgram_listen_websocket_route( _OPENAI_BETA_HEADER: Final = "openai-beta" +_CLIENT_OPENAI_BETA_RESOURCES: Final = frozenset({"agents", "vaults", "chatkit"}) class BaseOpenAIPassThroughHandler: @@ -3594,21 +3595,16 @@ class BaseOpenAIPassThroughHandler: _base_openai_pass_through_handler = base_openai_pass_through_handler - @staticmethod - def _openai_beta_route_default(endpoint: str, request: Request) -> str | None: - if is_openai_agents_api_path(endpoint): - return "agents=v1" - if openai_api_resource(endpoint) == "chatkit" or not RouteChecks.is_assistants_api_request(request): - return None - return "assistants=v2" - @staticmethod def _openai_beta(endpoint: str, request: Request, custom_llm_provider: litellm.LlmProviders) -> str | None: - if custom_llm_provider != litellm.LlmProviders.OPENAI: - return "assistants=v2" if RouteChecks.is_assistants_api_request(request) else None - return request.headers.get(_OPENAI_BETA_HEADER) or BaseOpenAIPassThroughHandler._openai_beta_route_default( - endpoint, request - ) + if ( + custom_llm_provider == litellm.LlmProviders.OPENAI + and openai_api_resource(endpoint) in _CLIENT_OPENAI_BETA_RESOURCES + ): + return request.headers.get(_OPENAI_BETA_HEADER) or ( + "agents=v1" if is_openai_agents_api_path(endpoint) else None + ) + return "assistants=v2" if RouteChecks.is_assistants_api_request(request) else None @staticmethod def _append_openai_beta_header( diff --git a/tests/unit/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py b/tests/unit/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py index 5c55b75842f..33ddd98610b 100644 --- a/tests/unit/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py +++ b/tests/unit/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py @@ -4069,6 +4069,30 @@ def test_openai_passthrough_forwards_verbatim_to_openai( pytest.param("POST", "/openai/v1", "/assistants", {}, ["assistants=v2"], id="assistants_default"), pytest.param("POST", "/openai/v1", "/threads/thread_123/messages", {}, ["assistants=v2"], id="threads_default"), pytest.param("POST", "/openai/v1", "/chat/completions", {}, [], id="no_beta"), + pytest.param( + "POST", + "/openai_passthrough/v1", + "/responses", + {"OpenAI-Beta": "12345"}, + [], + id="client_beta_dropped_off_beta_paths", + ), + pytest.param( + "POST", + "/openai/v1", + "/chat/completions", + {"OpenAI-Beta": "assistants=v2"}, + [], + id="client_beta_dropped_on_chat_completions", + ), + pytest.param( + "POST", + "/openai/v1", + "/threads/thread_123/messages", + {"OpenAI-Beta": "assistants=v1"}, + ["assistants=v2"], + id="assistants_client_beta_replaced", + ), ], ) def test_openai_passthrough_sends_the_openai_beta_header_upstream(