Implementation:Openai Openai python Response Image Gen Call Partial
| Knowledge Sources | |
|---|---|
| Domains | API_Types, Responses_API |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Concrete streaming event type for delivering partial image data during image generation provided by the openai-python SDK.
Description
ResponseImageGenCallPartialImageEvent is a Pydantic model emitted when a partial image is available during image generation streaming. It carries the item_id identifying the image generation item, the output_index locating it in the response output array, partial_image_b64 containing the base64-encoded partial image data suitable for rendering, partial_image_index as a 0-based index for the partial image chunk, and a sequence_number for event ordering. The type field is always "response.image_generation_call.partial_image".
Usage
Import this type when building streaming event handlers that render progressive image previews as partial image data arrives from the server.
Code Reference
Source Location
- Repository: openai-python
- File: src/openai/types/responses/response_image_gen_call_partial_image_event.py
Signature
class ResponseImageGenCallPartialImageEvent(BaseModel):
"""Emitted when a partial image is available during image generation streaming."""
item_id: str
output_index: int
partial_image_b64: str
partial_image_index: int
sequence_number: int
type: Literal["response.image_generation_call.partial_image"]
Import
from openai.types.responses import ResponseImageGenCallPartialImageEvent
I/O Contract
Fields
| Name | Type | Required | Description |
|---|---|---|---|
| item_id | str | Yes | The unique identifier of the image generation item being processed. |
| output_index | int | Yes | The index of the output item in the response's output array. |
| partial_image_b64 | str | Yes | Base64-encoded partial image data, suitable for rendering as an image. |
| partial_image_index | int | Yes | 0-based index for the partial image (backend is 1-based, but this is 0-based for the user). |
| sequence_number | int | Yes | The sequence number of the image generation item being processed. |
| type | Literal["response.image_generation_call.partial_image"] | Yes | The type of the event. Always response.image_generation_call.partial_image.
|
Usage Examples
import base64
import openai
client = openai.OpenAI()
stream = client.responses.create(
model="gpt-4o",
input="Generate an image of a sunset over mountains.",
stream=True,
)
for event in stream:
if event.type == "response.image_generation_call.partial_image":
# Decode and display partial image preview
partial_bytes = base64.b64decode(event.partial_image_b64)
print(f"Received partial image chunk {event.partial_image_index} "
f"({len(partial_bytes)} bytes)")