Implementation:Openai Openai python Response Failed Event
| Knowledge Sources | |
|---|---|
| Domains | API_Types, Responses_API |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Concrete streaming event type emitted when a response fails, provided by the openai-python SDK.
Description
ResponseFailedEvent is a Pydantic model representing a streaming event emitted when a response fails. It contains a response field holding the full Response object (including error information), a sequence_number for event ordering, and a fixed type of "response.failed". This event signals that the model was unable to complete the response and the associated Response object will contain error details. This type is auto-generated from the OpenAI OpenAPI specification by Stainless.
Usage
Import ResponseFailedEvent when handling streaming events from the Responses API and you need to detect and handle response failures.
Code Reference
Source Location
- Repository: openai-python
- File: src/openai/types/responses/response_failed_event.py
Signature
class ResponseFailedEvent(BaseModel):
"""An event that is emitted when a response fails."""
response: Response
sequence_number: int
type: Literal["response.failed"]
Import
from openai.types.responses import ResponseFailedEvent
I/O Contract
Fields
| Name | Type | Required | Description |
|---|---|---|---|
| response | Response |
Yes | The response that failed, containing error details. |
| sequence_number | int |
Yes | The sequence number of this event. |
| type | Literal["response.failed"] |
Yes | The type of the event. Always "response.failed".
|
Usage Examples
from openai.types.responses import ResponseFailedEvent
# Detect failures during streaming
for event in stream:
if isinstance(event, ResponseFailedEvent):
print(f"Response failed: {event.response.id}")
if event.response.error:
print(f"Error code: {event.response.error.code}")
print(f"Error message: {event.response.error.message}")