Generate an image
- Python
- Node.js
- Go
Getting the image bytes
Where the image data lands depends on the model andresponse_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:
- Python
- Go
url is a remote http(s) link (fetch it yourself).
Edit an image
images.edit() calls POST /v1/images/edits with a JSON body. Pass the source image (and
an optional mask or reference_images) as a data:image/...;base64, URL or a bare base64
string; remote http(s) URLs are rejected with 422. The response has the same
shape as a generation. See Image Generation: Edit an image
for the operations each provider supports.
- Python
- Node.js
- Go
images.stream() (Images.Stream in Go) sends stream: true and
yields image chunks. See Image Generation: Streaming.
Response fields
openai/gpt-image-1 is the recommended image generation model. Additional image generation models may be available depending on your account.