Implementation:Openai Openai python Unwrap Webhook Event
| Knowledge Sources | |
|---|---|
| Domains | API_Types, Python |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Concrete type alias for representing a discriminated union of all webhook event types provided by the openai-python SDK.
Description
UnwrapWebhookEvent is a TypeAlias that defines a discriminated union of all supported webhook event types. It uses Annotated with PropertyInfo(discriminator="type") to enable automatic dispatching based on the "type" field in the incoming webhook payload. The union includes BatchCancelledWebhookEvent, BatchCompletedWebhookEvent, BatchExpiredWebhookEvent, BatchFailedWebhookEvent, EvalRunCanceledWebhookEvent, EvalRunFailedWebhookEvent, EvalRunSucceededWebhookEvent, FineTuningJobCancelledWebhookEvent, FineTuningJobFailedWebhookEvent, FineTuningJobSucceededWebhookEvent, RealtimeCallIncomingWebhookEvent, ResponseCancelledWebhookEvent, ResponseCompletedWebhookEvent, ResponseFailedWebhookEvent, and ResponseIncompleteWebhookEvent.
Usage
Import this type alias when you need to handle any webhook event generically. The discriminated union allows Pydantic to automatically select the correct model based on the value of the "type" field in the incoming JSON payload.
Code Reference
Source Location
- Repository: openai-python
- File: src/openai/types/webhooks/unwrap_webhook_event.py
Signature
UnwrapWebhookEvent: TypeAlias = Annotated[
Union[
BatchCancelledWebhookEvent,
BatchCompletedWebhookEvent,
BatchExpiredWebhookEvent,
BatchFailedWebhookEvent,
EvalRunCanceledWebhookEvent,
EvalRunFailedWebhookEvent,
EvalRunSucceededWebhookEvent,
FineTuningJobCancelledWebhookEvent,
FineTuningJobFailedWebhookEvent,
FineTuningJobSucceededWebhookEvent,
RealtimeCallIncomingWebhookEvent,
ResponseCancelledWebhookEvent,
ResponseCompletedWebhookEvent,
ResponseFailedWebhookEvent,
ResponseIncompleteWebhookEvent,
],
PropertyInfo(discriminator="type"),
]
Import
from openai.types.webhooks import UnwrapWebhookEvent
I/O Contract
Union Members
| Type Discriminator | Model Class | Description |
|---|---|---|
| "batch.cancelled" | BatchCancelledWebhookEvent | Batch job was cancelled. |
| "batch.completed" | BatchCompletedWebhookEvent | Batch job completed successfully. |
| "batch.expired" | BatchExpiredWebhookEvent | Batch job expired. |
| "batch.failed" | BatchFailedWebhookEvent | Batch job failed. |
| "eval.run.canceled" | EvalRunCanceledWebhookEvent | Eval run was canceled. |
| "eval.run.failed" | EvalRunFailedWebhookEvent | Eval run failed. |
| "eval.run.succeeded" | EvalRunSucceededWebhookEvent | Eval run succeeded. |
| "fine_tuning.job.cancelled" | FineTuningJobCancelledWebhookEvent | Fine-tuning job was cancelled. |
| "fine_tuning.job.failed" | FineTuningJobFailedWebhookEvent | Fine-tuning job failed. |
| "fine_tuning.job.succeeded" | FineTuningJobSucceededWebhookEvent | Fine-tuning job succeeded. |
| "realtime.call.incoming" | RealtimeCallIncomingWebhookEvent | Incoming SIP call received. |
| "response.cancelled" | ResponseCancelledWebhookEvent | Background response was cancelled. |
| "response.completed" | ResponseCompletedWebhookEvent | Background response completed. |
| "response.failed" | ResponseFailedWebhookEvent | Background response failed. |
| "response.incomplete" | ResponseIncompleteWebhookEvent | Background response was interrupted. |
Usage Examples
from openai.types.webhooks import UnwrapWebhookEvent
from openai.types.webhooks import (
ResponseCompletedWebhookEvent,
EvalRunSucceededWebhookEvent,
)
# The client.webhooks.unwrap() method returns UnwrapWebhookEvent
event: UnwrapWebhookEvent = client.webhooks.unwrap(payload, headers, secret)
# Use isinstance checks to handle specific event types
if isinstance(event, ResponseCompletedWebhookEvent):
print(f"Response {event.data.id} completed")
elif isinstance(event, EvalRunSucceededWebhookEvent):
print(f"Eval run {event.data.id} succeeded")