Overview
Concrete tool for representing an image edit completion streaming event provided by the openai-python SDK.
Description
ImageEditCompletedEvent is a Pydantic BaseModel emitted when image editing has completed and the final image is available. It contains the b64_json base64-encoded final image data, along with metadata about the edit settings: background (transparent, opaque, or auto), output_format (png, webp, or jpeg), quality (low, medium, high, or auto), and size. The type field is always "image_edit.completed". A usage field provides token consumption details via nested Usage and UsageInputTokensDetails models.
Usage
Import ImageEditCompletedEvent when processing streaming events from the image edit API to detect when the final edited image is ready.
Code Reference
Source Location
Signature
class UsageInputTokensDetails(BaseModel):
image_tokens: int
text_tokens: int
class Usage(BaseModel):
input_tokens: int
input_tokens_details: UsageInputTokensDetails
output_tokens: int
total_tokens: int
class ImageEditCompletedEvent(BaseModel):
b64_json: str
background: Literal["transparent", "opaque", "auto"]
created_at: int
output_format: Literal["png", "webp", "jpeg"]
quality: Literal["low", "medium", "high", "auto"]
size: Literal["1024x1024", "1024x1536", "1536x1024", "auto"]
type: Literal["image_edit.completed"]
usage: Usage
Import
from openai.types import ImageEditCompletedEvent
I/O Contract
Fields (ImageEditCompletedEvent)
| Name |
Type |
Required |
Description
|
| b64_json |
str |
Yes |
Base64-encoded final edited image data, suitable for rendering as an image.
|
| background |
Literal["transparent", "opaque", "auto"] |
Yes |
The background setting for the edited image.
|
| created_at |
int |
Yes |
Unix timestamp when the event was created.
|
| output_format |
Literal["png", "webp", "jpeg"] |
Yes |
The output format for the edited image.
|
| quality |
Literal["low", "medium", "high", "auto"] |
Yes |
The quality setting for the edited image.
|
| size |
Literal["1024x1024", "1024x1536", "1536x1024", "auto"] |
Yes |
The size of the edited image.
|
| type |
Literal["image_edit.completed"] |
Yes |
The event type. Always "image_edit.completed".
|
| usage |
Usage |
Yes |
Token usage information for the image generation.
|
Fields (Usage)
| Name |
Type |
Required |
Description
|
| input_tokens |
int |
Yes |
Number of tokens (images and text) in the input prompt.
|
| input_tokens_details |
UsageInputTokensDetails |
Yes |
Detailed breakdown of input tokens.
|
| output_tokens |
int |
Yes |
Number of image tokens in the output image.
|
| total_tokens |
int |
Yes |
Total number of tokens used for the image generation.
|
Fields (UsageInputTokensDetails)
| Name |
Type |
Required |
Description
|
| image_tokens |
int |
Yes |
Number of image tokens in the input prompt.
|
| text_tokens |
int |
Yes |
Number of text tokens in the input prompt.
|
Usage Examples
from openai.types import ImageEditCompletedEvent
import base64
# When processing streaming events from image edit
def handle_event(event):
if isinstance(event, ImageEditCompletedEvent):
# Decode the final image
image_data = base64.b64decode(event.b64_json)
print(f"Image size: {event.size}")
print(f"Quality: {event.quality}")
print(f"Tokens used: {event.usage.total_tokens}")
with open("edited.png", "wb") as f:
f.write(image_data)
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.