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 transform_request for OpenAI responses API
Ishaan Jaff0f8de3d0a512
diff --git a/litellm/llms/base_llm/responses/transformation.py b/litellm/llms/base_llm/responses/transformation.pyindex 27b0a439c72..76b0a5b329d 100644--- a/litellm/llms/base_llm/responses/transformation.py+++ b/litellm/llms/base_llm/responses/transformation.py@@ -1,8 +1,13 @@import typesfrom abc import ABC, abstractmethod-from typing import TYPE_CHECKING, Any, Optional--from litellm.types.llms.openai import ResponsesAPIRequestParams+from typing import TYPE_CHECKING, Any, Optional, Union++from litellm.types.llms.openai import (+ ResponseInputParam,+ ResponsesAPIOptionalRequestParams,+ ResponsesAPIRequestParams,+)+from litellm.types.router import GenericLiteLLMParamsfrom litellm.types.utils import ModelInfofrom ..chat.transformation import BaseLLMException@@ -48,7 +53,7 @@ class BaseResponsesAPIConfig(ABC):optional_params: dict,model: str,drop_params: bool,- ) -> ResponsesAPIRequestParams:+ ) -> ResponsesAPIOptionalRequestParams:pass@@ -66,7 +71,6 @@ class BaseResponsesAPIConfig(ABC):self,api_base: Optional[str],model: str,- optional_params: dict,stream: Optional[bool] = None,) -> str:"""@@ -80,15 +84,16 @@ class BaseResponsesAPIConfig(ABC):raise ValueError("api_base is required")return api_base- # @abstractmethod- # def transform_request(- # self,- # model: str,- # optional_params: dict,- # litellm_params: dict,- # headers: dict,- # ) -> dict:- # pass+ @abstractmethod+ def transform_request(+ self,+ model: str,+ input: Union[str, ResponseInputParam],+ response_api_optional_request_params: ResponsesAPIOptionalRequestParams,+ litellm_params: GenericLiteLLMParams,+ headers: dict,+ ) -> ResponsesAPIRequestParams:+ pass# @abstractmethod# def transform_response(diff --git a/litellm/llms/openai/responses/transformation.py b/litellm/llms/openai/responses/transformation.pyindex 7c52679e7f9..d67846e1010 100644--- a/litellm/llms/openai/responses/transformation.py+++ b/litellm/llms/openai/responses/transformation.py@@ -1,9 +1,14 @@-from typing import Optional+from typing import Optional, Unionimport litellmfrom litellm.llms.base_llm.responses.transformation import BaseResponsesAPIConfigfrom litellm.secret_managers.main import get_secret_str-from litellm.types.llms.openai import ResponsesAPIRequestParams+from litellm.types.llms.openai import (+ ResponseInputParam,+ ResponsesAPIOptionalRequestParams,+ ResponsesAPIRequestParams,+)+from litellm.types.router import GenericLiteLLMParamsclass OpenAIResponsesAPIConfig(BaseResponsesAPIConfig):@@ -41,9 +46,9 @@ class OpenAIResponsesAPIConfig(BaseResponsesAPIConfig):optional_params: dict,model: str,drop_params: bool,- ) -> ResponsesAPIRequestParams:+ ) -> ResponsesAPIOptionalRequestParams:- return ResponsesAPIRequestParams(+ return ResponsesAPIOptionalRequestParams(include=optional_params.get("include"),instructions=optional_params.get("instructions"),max_output_tokens=optional_params.get("max_output_tokens"),@@ -66,6 +71,18 @@ class OpenAIResponsesAPIConfig(BaseResponsesAPIConfig):timeout=optional_params.get("timeout"),)+ def transform_request(+ self,+ model: str,+ input: Union[str, ResponseInputParam],+ response_api_optional_request_params: ResponsesAPIOptionalRequestParams,+ litellm_params: GenericLiteLLMParams,+ headers: dict,+ ) -> ResponsesAPIRequestParams:+ return ResponsesAPIRequestParams(+ model=model, input=input, **response_api_optional_request_params+ )+def validate_environment(self,headers: dict,@@ -89,7 +106,6 @@ class OpenAIResponsesAPIConfig(BaseResponsesAPIConfig):self,api_base: Optional[str],model: str,- optional_params: dict,stream: Optional[bool] = None,) -> str:"""diff --git a/litellm/types/llms/openai.py b/litellm/types/llms/openai.pyindex 9b6581773d6..1b521ece9d4 100644--- a/litellm/types/llms/openai.py+++ b/litellm/types/llms/openai.py@@ -695,11 +695,9 @@ OpenAIAudioTranscriptionOptionalParams = Literal[OpenAIImageVariationOptionalParams = Literal["n", "size", "response_format", "user"]-class ResponsesAPIRequestParams(TypedDict, total=False):- """TypedDict for parameters supported by the responses API."""+class ResponsesAPIOptionalRequestParams(TypedDict, total=False):+ """TypedDict for Optional parameters supported by the responses API."""- input: Union[str, ResponseInputParam]- model: strinclude: Optional[List[ResponseIncludable]]instructions: Optional[str]max_output_tokens: Optional[int]@@ -720,3 +718,10 @@ class ResponsesAPIRequestParams(TypedDict, total=False):extra_query: Optional[Dict[str, Any]]extra_body: Optional[Dict[str, Any]]timeout: Optional[Union[float, httpx.Timeout]]+++class ResponsesAPIRequestParams(ResponsesAPIOptionalRequestParams, total=False):+ """TypedDict for request parameters supported by the responses API."""++ input: Union[str, ResponseInputParam]+ model: str