mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-16 09:22:22 +00:00
fix(passthrough): forward the client's OpenAI-Beta only on agents, vaults, and ChatKit paths
This commit is contained in:
parent
560d514843
commit
f6287c88b5
2 changed files with 33 additions and 13 deletions
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue