The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Add opt out varible for v1/messages to responses
Sameer Kankute99c62ca40ea8
diff --git a/litellm/__init__.py b/litellm/__init__.pyindex 6e42f2c1ea5..50fa0e76755 100644--- a/litellm/__init__.py+++ b/litellm/__init__.py@@ -197,6 +197,9 @@ telemetry = Truemax_tokens: int = DEFAULT_MAX_TOKENS # OpenAI Defaultsdrop_params = bool(os.getenv("LITELLM_DROP_PARAMS", False))modify_params = bool(os.getenv("LITELLM_MODIFY_PARAMS", False))+use_chat_completions_url_for_anthropic_messages: bool = bool(+ os.getenv("LITELLM_USE_CHAT_COMPLETIONS_URL_FOR_ANTHROPIC_MESSAGES", False)+) # When True, routes OpenAI /v1/messages requests to chat/completions instead of the Responses APIretry = True### AUTH ###api_key: Optional[str] = Nonediff --git a/litellm/llms/anthropic/experimental_pass_through/messages/handler.py b/litellm/llms/anthropic/experimental_pass_through/messages/handler.pyindex 6fe0fcd4fdf..5b215c1fe54 100644--- a/litellm/llms/anthropic/experimental_pass_through/messages/handler.py+++ b/litellm/llms/anthropic/experimental_pass_through/messages/handler.py@@ -30,11 +30,17 @@ from .utils import AnthropicMessagesRequestUtils, mock_response# Providers that are routed directly to the OpenAI Responses API instead of# going through chat/completions.-_RESPONSES_API_PROVIDERS = frozenset({"openai", "azure", "azure_text"})+_RESPONSES_API_PROVIDERS = frozenset({"openai"})def _should_route_to_responses_api(custom_llm_provider: Optional[str]) -> bool:- """Return True when the provider should use the Responses API path."""+ """Return True when the provider should use the Responses API path.++ Set ``litellm.use_chat_completions_url_for_anthropic_messages = True`` to+ opt out and route OpenAI/Azure requests through chat/completions instead.+ """+ if litellm.use_chat_completions_url_for_anthropic_messages:+ return Falsereturn custom_llm_provider in _RESPONSES_API_PROVIDERS####### ENVIRONMENT VARIABLES ###################