Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Openai Openai python Image Gen Partial Event

From Leeroopedia
Knowledge Sources
Domains API_Types, Python
Last Updated 2026-02-15 00:00 GMT

Overview

Concrete tool for representing a partial image during image generation streaming provided by the openai-python SDK.

Description

ImageGenPartialImageEvent is a Pydantic BaseModel emitted when a partial image is available during image generation streaming. It carries b64_json base64-encoded partial image data along with generation settings metadata: background (transparent, opaque, or auto), output_format (png, webp, or jpeg), quality (low, medium, high, or auto), and size. The partial_image_index field provides a 0-based index for ordering partial images during streaming. The type field is always "image_generation.partial_image".

Usage

Import ImageGenPartialImageEvent when processing streaming events from the image generation API to render progressive image updates before the final result arrives.

Code Reference

Source Location

Signature

class ImageGenPartialImageEvent(BaseModel):
    b64_json: str
    background: Literal["transparent", "opaque", "auto"]
    created_at: int
    output_format: Literal["png", "webp", "jpeg"]
    partial_image_index: int
    quality: Literal["low", "medium", "high", "auto"]
    size: Literal["1024x1024", "1024x1536", "1536x1024", "auto"]
    type: Literal["image_generation.partial_image"]

Import

from openai.types import ImageGenPartialImageEvent

I/O Contract

Fields

Name Type Required Description
b64_json str Yes Base64-encoded partial image data, suitable for rendering as an image.
background Literal["transparent", "opaque", "auto"] Yes The background setting for the requested image.
created_at int Yes Unix timestamp when the event was created.
output_format Literal["png", "webp", "jpeg"] Yes The output format for the requested image.
partial_image_index int Yes 0-based index for the partial image during streaming.
quality Literal["low", "medium", "high", "auto"] Yes The quality setting for the requested image.
size Literal["1024x1024", "1024x1536", "1536x1024", "auto"] Yes The size of the requested image.
type Literal["image_generation.partial_image"] Yes The event type. Always "image_generation.partial_image".

Usage Examples

from openai.types import ImageGenPartialImageEvent
import base64

# When processing streaming events from image generation
def handle_partial(event):
    if isinstance(event, ImageGenPartialImageEvent):
        print(f"Partial image #{event.partial_image_index}")
        print(f"Format: {event.output_format}, Size: {event.size}")
        # Render partial image for progressive display
        partial_data = base64.b64decode(event.b64_json)
        with open(f"partial_{event.partial_image_index}.png", "wb") as f:
            f.write(partial_data)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment