Implementation:Openai Openai python Realtime Error Event
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Error_Handling, Realtime_Communication |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Concrete typed error event model for handling Realtime API errors delivered as WebSocket events provided by the OpenAI Python SDK.
Description
The RealtimeErrorEvent Pydantic model represents error events received in the Realtime API event stream. It contains an error object with type, code, message, and param fields. Applications detect errors by matching event.type == "error" in the event loop.
Usage
Pattern-match on event.type == "error" within the async event loop. Access event.error.message for the human-readable error description.
Code Reference
Source Location
- Repository: openai-python
- File: src/openai/types/realtime/realtime_error_event.py
Signature
class ErrorEvent(BaseModel):
type: Literal["error"]
event_id: str
error: Error
class Error(BaseModel):
type: str
code: Optional[str] = None
message: str
param: Optional[str] = None
Import
from openai.types.realtime import ErrorEvent
# Detected via: event.type == "error"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| event | RealtimeServerEvent | Yes | Server event from WebSocket stream |
Outputs
| Name | Type | Description |
|---|---|---|
| error.type | str | Error type identifier |
| error.code | str or None | Error code |
| error.message | str | Human-readable error description |
| error.param | str or None | Parameter that caused the error |
Usage Examples
Error Detection in Event Loop
async for event in connection:
if event.type == "error":
print(f"Error [{event.error.code}]: {event.error.message}")
if event.error.param:
print(f" Parameter: {event.error.param}")
break
elif event.type == "response.text.delta":
print(event.delta, end="")
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment