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 native Responses API support for litellm_proxy provider (#15347)
Copilot422631409678
diff --git a/litellm/__init__.py b/litellm/__init__.pyindex 60cf327c26f..e461c88efd6 100644--- a/litellm/__init__.py+++ b/litellm/__init__.py@@ -1190,6 +1190,9 @@ from .llms.azure.responses.transformation import AzureOpenAIResponsesAPIConfigfrom .llms.azure.responses.o_series_transformation import (AzureOpenAIOSeriesResponsesAPIConfig,)+from .llms.litellm_proxy.responses.transformation import (+ LiteLLMProxyResponsesAPIConfig,+)from .llms.openai.chat.o_series_transformation import (OpenAIOSeriesConfig as OpenAIO1Config, # maintain backwards compatibilityOpenAIOSeriesConfig,diff --git a/litellm/llms/litellm_proxy/responses/transformation.py b/litellm/llms/litellm_proxy/responses/transformation.pynew file mode 100644index 00000000000..0b81d8be7d8--- /dev/null+++ b/litellm/llms/litellm_proxy/responses/transformation.py@@ -0,0 +1,48 @@+"""+Responses API transformation for LiteLLM Proxy provider.++LiteLLM Proxy supports the OpenAI Responses API natively when the underlying model supports it.+This config enables pass-through behavior to the proxy's /v1/responses endpoint.+"""++from typing import Optional++from litellm.llms.openai.responses.transformation import OpenAIResponsesAPIConfig+from litellm.secret_managers.main import get_secret_str+from litellm.types.utils import LlmProviders+++class LiteLLMProxyResponsesAPIConfig(OpenAIResponsesAPIConfig):+ """+ Configuration for LiteLLM Proxy Responses API support.++ Extends OpenAI's config since the proxy follows OpenAI's API spec,+ but uses LITELLM_PROXY_API_BASE for the base URL.+ """++ @property+ def custom_llm_provider(self) -> LlmProviders:+ return LlmProviders.LITELLM_PROXY++ def get_complete_url(+ self,+ api_base: Optional[str],+ litellm_params: dict,+ ) -> str:+ """+ Get the endpoint for LiteLLM Proxy responses API.++ Uses LITELLM_PROXY_API_BASE environment variable if api_base is not provided.+ """+ api_base = api_base or get_secret_str("LITELLM_PROXY_API_BASE")++ if api_base is None:+ raise ValueError(+ "api_base not set for LiteLLM Proxy responses API. "+ "Set via api_base parameter or LITELLM_PROXY_API_BASE environment variable"+ )++ # Remove trailing slashes+ api_base = api_base.rstrip("/")++ return f"{api_base}/responses"diff --git a/litellm/utils.py b/litellm/utils.pyindex 47250615ef6..5861d703a34 100644--- a/litellm/utils.py+++ b/litellm/utils.py@@ -7305,6 +7305,8 @@ class ProviderConfigManager:return litellm.AzureOpenAIOSeriesResponsesAPIConfig()else:return litellm.AzureOpenAIResponsesAPIConfig()+ elif litellm.LlmProviders.LITELLM_PROXY == provider:+ return litellm.LiteLLMProxyResponsesAPIConfig()return None@staticmethoddiff --git a/tests/local_testing/test_config.py b/tests/local_testing/test_config.pyindex a0a31c2e78c..5d8fae282ce 100644--- a/tests/local_testing/test_config.py+++ b/tests/local_testing/test_config.py@@ -401,3 +401,24 @@ def test_provider_config_manager_bedrock_converse_like():# model="gpt-3.5-turbo", provider=LlmProviders(provider)# )# _check_provider_config(config, provider)+++def test_litellm_proxy_responses_api_config():+ """Test that litellm_proxy provider returns correct Responses API config"""+ from litellm.llms.litellm_proxy.responses.transformation import (+ LiteLLMProxyResponsesAPIConfig,+ )++ config = ProviderConfigManager.get_provider_responses_api_config(+ model="litellm_proxy/gpt-4",+ provider=LlmProviders.LITELLM_PROXY,+ )+ print(f"config: {config}")+ assert config is not None, "Config should not be None for litellm_proxy provider"+ assert isinstance(+ config, LiteLLMProxyResponsesAPIConfig+ ), f"Expected LiteLLMProxyResponsesAPIConfig, got {type(config)}"+ assert (+ config.custom_llm_provider == LlmProviders.LITELLM_PROXY+ ), "custom_llm_provider should be LITELLM_PROXY"+diff --git a/tests/test_litellm_proxy_responses_config.py b/tests/test_litellm_proxy_responses_config.pynew file mode 100644index 00000000000..6242a9dbf3b--- /dev/null+++ b/tests/test_litellm_proxy_responses_config.py@@ -0,0 +1,84 @@+"""+Unit test for LiteLLM Proxy Responses API configuration.+"""++import pytest++from litellm.types.utils import LlmProviders+from litellm.utils import ProviderConfigManager+++def test_litellm_proxy_responses_api_config():+ """Test that litellm_proxy provider returns correct Responses API config"""+ from litellm.llms.litellm_proxy.responses.transformation import (+ LiteLLMProxyResponsesAPIConfig,+ )++ config = ProviderConfigManager.get_provider_responses_api_config(+ model="litellm_proxy/gpt-4",+ provider=LlmProviders.LITELLM_PROXY,+ )+ print(f"config: {config}")+ assert config is not None, "Config should not be None for litellm_proxy provider"+ assert isinstance(+ config, LiteLLMProxyResponsesAPIConfig+ ), f"Expected LiteLLMProxyResponsesAPIConfig, got {type(config)}"+ assert (+ config.custom_llm_provider == LlmProviders.LITELLM_PROXY+ ), "custom_llm_provider should be LITELLM_PROXY"+++def test_litellm_proxy_responses_api_config_get_complete_url():+ """Test that get_complete_url works correctly"""+ import os+ from litellm.llms.litellm_proxy.responses.transformation import (+ LiteLLMProxyResponsesAPIConfig,+ )++ config = LiteLLMProxyResponsesAPIConfig()++ # Test with explicit api_base+ url = config.get_complete_url(+ api_base="https://my-proxy.example.com",+ litellm_params={},+ )+ assert url == "https://my-proxy.example.com/responses"++ # Test with trailing slash+ url = config.get_complete_url(+ api_base="https://my-proxy.example.com/",+ litellm_params={},+ )+ assert url == "https://my-proxy.example.com/responses"++ # Test that it raises error when api_base is None and env var is not set+ if "LITELLM_PROXY_API_BASE" in os.environ:+ del os.environ["LITELLM_PROXY_API_BASE"]++ with pytest.raises(ValueError, match="api_base not set"):+ config.get_complete_url(api_base=None, litellm_params={})+++def test_litellm_proxy_responses_api_config_inherits_from_openai():+ """Test that LiteLLMProxyResponsesAPIConfig extends OpenAI config properly"""+ from litellm.llms.litellm_proxy.responses.transformation import (+ LiteLLMProxyResponsesAPIConfig,+ )+ from litellm.llms.openai.responses.transformation import (+ OpenAIResponsesAPIConfig,+ )++ config = LiteLLMProxyResponsesAPIConfig()++ # Should inherit from OpenAI config+ assert isinstance(config, OpenAIResponsesAPIConfig)++ # Should have the correct provider set+ assert config.custom_llm_provider == LlmProviders.LITELLM_PROXY+++if __name__ == "__main__":+ test_litellm_proxy_responses_api_config()+ test_litellm_proxy_responses_api_config_get_complete_url()+ test_litellm_proxy_responses_api_config_inherits_from_openai()+ print("All tests passed!")