mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
[Bug Fix]: ErrorEvent ValidationError when OpenAI Responses API returns nested error structure (#15804)
* add ErrorEventError nested field * test_openai_responses_api_token_limit_error * test_openai_responses_api_token_limit_error
This commit is contained in:
parent
2ab2d15efc
commit
d91efa7a7b
2 changed files with 36 additions and 3 deletions
|
|
@ -1408,13 +1408,20 @@ class ImageGenerationPartialImageEvent(BaseLiteLLMOpenAIResponseObject):
|
|||
b64_json: str
|
||||
|
||||
|
||||
class ErrorEvent(BaseLiteLLMOpenAIResponseObject):
|
||||
type: Literal[ResponsesAPIStreamEvents.ERROR]
|
||||
code: Optional[str]
|
||||
class ErrorEventError(BaseLiteLLMOpenAIResponseObject):
|
||||
"""Nested error object within ErrorEvent"""
|
||||
type: str # e.g., 'invalid_request_error'
|
||||
code: str # e.g., 'context_length_exceeded'
|
||||
message: str
|
||||
param: Optional[str]
|
||||
|
||||
|
||||
class ErrorEvent(BaseLiteLLMOpenAIResponseObject):
|
||||
type: Literal[ResponsesAPIStreamEvents.ERROR]
|
||||
sequence_number: int
|
||||
error: ErrorEventError
|
||||
|
||||
|
||||
class GenericEvent(BaseLiteLLMOpenAIResponseObject):
|
||||
type: str
|
||||
|
||||
|
|
|
|||
|
|
@ -1508,3 +1508,29 @@ async def test_basic_openai_responses_with_websearch(stream):
|
|||
print("chunk=", json.dumps(chunk, indent=4, default=str))
|
||||
else:
|
||||
print("response=", json.dumps(response, indent=4, default=str))
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_openai_responses_api_token_limit_error():
|
||||
"""
|
||||
Relevant issue: https://github.com/BerriAI/litellm/issues/15785
|
||||
|
||||
|
||||
When this fails you'll see:
|
||||
"pydantic_core._pydantic_core.ValidationError: 3 validation errors for ErrorEvent"
|
||||
in the console.
|
||||
"""
|
||||
litellm._turn_on_debug()
|
||||
|
||||
# Generate text with >400k tokens to trigger token limit error
|
||||
oversized_text = "This is a test sentence. " * 50000 # ~400k tokens
|
||||
|
||||
# This will raise ValidationError instead of showing the real error
|
||||
response = await litellm.aresponses(
|
||||
model="gpt-5-mini",
|
||||
input=oversized_text,
|
||||
stream=True
|
||||
)
|
||||
|
||||
async for event in response:
|
||||
print(event) # Never reaches here - ValidationError is raised
|
||||
Loading…
Add table
Reference in a new issue