Skip to main content

Generate an image

Getting the image bytes

Where the image data lands depends on the model and response_format. With the default (or response_format="url"), some models — including openai/gpt-image-1 — return the image inline as a data: URI in url rather than in b64_json. Pass response_format="b64_json" to always get base64 in b64_json, or use the helper below to get raw bytes regardless of shape:
Both raise/return an error if url is a remote http(s) link (fetch it yourself).

Response fields

openai/gpt-image-1 is the recommended image generation model. Additional image generation models may be available depending on your account.