/v1/images/generations and /v1/images/edits endpoints for gpt-image-2. Use the native Gemini generateContent endpoint for Gemini image models.
Supported image models
See the Model Directory for the complete model list and current pricing.
Use gpt-image-2
Use the OpenAI SDK
Generate an image with curl
data[0].b64_json; gpt-image-2 does not provide a hosted image URL. See the Images API reference for all fields.
Edit an image with curl
Use/v1/images/edits to upload an input image together with editing instructions. This endpoint uses multipart/form-data; image is required and mask is optional.
image supports PNG, JPEG, and WebP. Omit mask to edit the whole image based on the prompt. When a mask is provided, its transparent areas identify the regions to redraw. The edited image is returned in data[0].b64_json. See the edit API reference for all fields.
Use Gemini image models
Gemini image models use the following endpoint. Replace{model} with a model ID:
"IMAGE" in generationConfig.responseModalities. Generated images are returned in candidates[].content.parts[].inlineData.
Use curl
Use Python and save the image
Install an HTTP client:Use Node.js and save the image
Gemini request fields
array
required
Conversation content. For text-to-image generation, put the image description in
parts[].text.array
required
Response modalities. Use
["TEXT", "IMAGE"] for text and images, or ["IMAGE"] to request images only.string
required
The model ID appears in the URL path, not in the request body. For example,
gemini-3-pro-image.Gemini response format
inlineData.data contains the base64-encoded image. A response can contain text and multiple image parts. Iterate through parts instead of assuming that the image is always the first item.Troubleshooting
The API returns get_channel_failed
Make sure the endpoint matches the model:- Use
/v1/images/generationsto generate withgpt-image-2. - Use
/v1/images/editsto edit withgpt-image-2. - Use
/v1beta/models/{model}:generateContentfor Gemini image models.
The Gemini response does not contain an image
Make suregenerationConfig.responseModalities contains "IMAGE". Also check the response for an error or safety block.
Write effective prompts
- Specify the style: photorealistic, oil painting, watercolor, 3D render
- Include lighting details: golden hour, studio lighting, dramatic shadows
- Specify the composition: close-up, wide angle, bird’s-eye view, portrait orientation
- Add quality modifiers: highly detailed, 4K, professional photography