Implementation:Openai Openai python Image Generate Params
| Knowledge Sources | |
|---|---|
| Domains | Computer_Vision, Image_Generation |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Concrete TypedDict parameter types for configuring image generation and editing requests provided by the OpenAI Python SDK.
Description
ImageGenerateParams and ImageEditParams are TypedDicts defining all valid parameters for image generation and editing API calls. They specify the prompt, model, size, quality, format, and advanced options like streaming partial images and transparent backgrounds.
Usage
Parameters are typically passed directly to images.generate() or images.edit() as keyword arguments. The TypedDicts provide type checking and IDE support.
Code Reference
Source Location
- Repository: openai-python
- File: src/openai/types/image_generate_params.py
- Lines: L1-145
- File: src/openai/types/image_edit_params.py
- Lines: L1-143
Signature
class ImageGenerateParams(TypedDict, total=False):
prompt: Required[str]
model: Union[str, ImageModel, None]
n: Optional[int]
quality: Literal["standard", "hd", "low", "medium", "high", "auto"]
response_format: Optional[Literal["url", "b64_json"]]
size: Optional[Literal["auto", "1024x1024", "1536x1024", "1024x1536", "256x256", "512x512", "1792x1024", "1024x1792"]]
style: Optional[Literal["vivid", "natural"]]
user: str
background: Optional[Literal["transparent", "opaque", "auto"]]
output_format: Optional[Literal["png", "jpeg", "webp"]]
output_compression: Optional[int]
partial_images: Optional[int]
moderation: Optional[Literal["low", "auto"]]
class ImageEditParams(TypedDict, total=False):
image: Required[Union[FileTypes, List[FileTypes]]]
prompt: Required[str]
mask: FileTypes
model: Union[str, ImageModel, None]
n: Optional[int]
quality: Optional[Literal["standard", "low", "medium", "high", "auto"]]
size: Optional[Literal["auto", "1024x1024", "1536x1024", "1024x1536", "256x256", "512x512"]]
background: Optional[Literal["transparent", "opaque", "auto"]]
input_fidelity: Optional[Literal["high", "low"]]
Import
from openai.types import ImageGenerateParams, ImageEditParams
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| prompt | str | Yes | Image description |
| model | str | No | dall-e-2, dall-e-3, or gpt-image-1 |
| size | str | No | Image dimensions |
| quality | str | No | Quality level |
| response_format | str | No | url or b64_json |
| output_format | str | No | png, jpeg, webp |
| background | str | No | transparent, opaque, auto |
| partial_images | int | No | Number of streaming partial previews |
Outputs
| Name | Type | Description |
|---|---|---|
| params | TypedDict | Configuration dict passed to generate/edit |
Usage Examples
Generation Parameters
from openai import OpenAI
client = OpenAI()
response = client.images.generate(
prompt="A sunset over mountains",
model="gpt-image-1",
size="1024x1024",
quality="high",
output_format="png",
background="opaque",
)
Edit Parameters
response = client.images.edit(
image=open("photo.png", "rb"),
prompt="Add a rainbow in the sky",
model="gpt-image-1",
size="1024x1024",
quality="high",
)