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
test_basic_openai_responses_api
Ishaan Jaffd6351c34330d
diff --git a/litellm/responses/main.py b/litellm/responses/main.pyindex ed5faa54d05..25e47dc5d9b 100644--- a/litellm/responses/main.py+++ b/litellm/responses/main.py@@ -6,6 +6,7 @@ from typing import Any, Dict, Iterable, List, Literal, Optional, Union, get_typeimport httpximport litellm+from litellm.constants import request_timeoutfrom litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObjfrom litellm.llms.base_llm.responses.transformation import BaseResponsesAPIConfigfrom litellm.llms.custom_httpx.llm_http_handler import BaseLLMHTTPHandler@@ -208,7 +209,7 @@ def responses(logging_obj=litellm_logging_obj,extra_headers=extra_headers,extra_body=extra_body,- timeout=timeout,+ timeout=timeout or request_timeout,_is_async=_is_async,client=kwargs.get("client"),)diff --git a/tests/llm_responses_api_testing/test_openai_responses_api.py b/tests/llm_responses_api_testing/test_openai_responses_api.pyindex 15192c1b552..777a70dcafd 100644--- a/tests/llm_responses_api_testing/test_openai_responses_api.py+++ b/tests/llm_responses_api_testing/test_openai_responses_api.py@@ -9,7 +9,78 @@ import litellmfrom litellm.integrations.custom_logger import CustomLoggerimport jsonfrom litellm.types.utils import StandardLoggingPayload-from litellm.types.llms.openai import ResponseCompletedEvent, ResponsesAPIResponse+from litellm.types.llms.openai import (+ ResponseCompletedEvent,+ ResponsesAPIResponse,+ ResponseTextConfig,+)+++def validate_responses_api_response(response):+ """+ Validate that a response from litellm.responses() or litellm.aresponses()+ conforms to the expected ResponsesAPIResponse structure.++ Args:+ response: The response object to validate++ Raises:+ AssertionError: If the response doesn't match the expected structure+ """+ # Validate response structure+ print("response=", json.dumps(response, indent=4, default=str))+ assert isinstance(+ response, ResponsesAPIResponse+ ), "Response should be an instance of ResponsesAPIResponse"++ # Required fields+ assert "id" in response and isinstance(+ response["id"], str+ ), "Response should have a string 'id' field"+ assert "created_at" in response and isinstance(+ response["created_at"], (int, float)+ ), "Response should have a numeric 'created_at' field"+ assert "output" in response and isinstance(+ response["output"], list+ ), "Response should have a list 'output' field"+ assert "parallel_tool_calls" in response and isinstance(+ response["parallel_tool_calls"], bool+ ), "Response should have a boolean 'parallel_tool_calls' field"++ # Optional fields with their expected types+ optional_fields = {+ "error": (dict, type(None)), # error can be dict or None+ "incomplete_details": (dict, type(None)),+ "instructions": (str, type(None)),+ "metadata": dict,+ "model": str,+ "object": str,+ "temperature": (int, float),+ "tool_choice": (dict, str),+ "tools": list,+ "top_p": (int, float),+ "max_output_tokens": (int, type(None)),+ "previous_response_id": (str, type(None)),+ "reasoning": dict,+ "status": str,+ "text": ResponseTextConfig,+ "truncation": str,+ # "usage": dict,+ "user": (str, type(None)),+ }++ for field, expected_type in optional_fields.items():+ if field in response:+ assert isinstance(+ response[field], expected_type+ ), f"Field '{field}' should be of type {expected_type}, but got {type(response[field])}"++ # Check if output has at least one item+ assert (+ len(response["output"]) > 0+ ), "Response 'output' field should have at least one item"++ return True # Return True if validation passes@pytest.mark.parametrize("sync_mode", [True, False])@@ -24,6 +95,9 @@ async def test_basic_openai_responses_api(sync_mode):print("litellm response=", json.dumps(response, indent=4, default=str))+ # Use the helper function to validate the response+ validate_responses_api_response(response)+@pytest.mark.parametrize("sync_mode", [True])@pytest.mark.asyncio