gpt-image-2
For the complete model list and pricing, see the Models page.
Core Capabilities
- Text-to-image: Generate illustrations, posters, concept images, or visual drafts from natural language prompts.
- Image editing: Modify an existing image based on text instructions, such as replacing the background, adjusting the style, or generating a new visual version.
- Multiple image candidates: Generate multiple candidate images in one request for later selection and iteration.
- Visual concept exploration: Quickly try different styles, compositions, color palettes, or scenes around the same theme.
Use Cases
- Marketing asset generation: Generate candidate images for landing pages, social media, ads, or content operations.
- Product visual exploration: Quickly create product concept images with different styles, compositions, colors, or scenes.
- Creative iteration: Generate multiple candidates around the same theme, then manually select and refine them.
- Dataset creation: Generate synthetic images for demos, testing, or assisted annotation workflows.
Key Parameters
Image generation requests usually include the following information:prompt: Describes the subject, scene, style, composition, colors, and constraints for the image. A more specific prompt helps the model understand the subject, scene, style, and constraints.image: The reference image used for image editing. This is required when usingclient.images.edit().size: Controls image size. The basic example uses1024x1024; landscape images can use1792x1024. Image width and height must be divisible by 16. Use the model details and actual API responses as the source of truth for supported size ranges.n: Controls the number of images generated in one request.n=1andn=2can be used for basic generation. Generating multiple images usually increases cost and processing time.quality: Controls image quality. Current supported values arelow,medium,high, andauto.
Billing
The response returnsusage, which can be used to inspect token usage for the request. Image generation usage fields differ from text generation and may include:
input_tokensinput_tokens_details.text_tokensinput_tokens_details.image_tokensoutput_tokenstotal_tokens
Usage Recommendations
- Describe the subject and purpose clearly: Explain what should be generated and whether the image is for a poster, product image, illustration, avatar, or concept design.
- Add key visual details: Describe the scene, composition, colors, materials, lighting, and style. Avoid contradictory requirements.
- Iterate in a small scope first: Generate a small number of images to validate the prompt and style, then adjust size, count, quality, or reference image.
- Save prompts and parameters: Record the model, prompt, size, quality, and other parameters for reproduction, comparison, and troubleshooting.
- Review before publishing: Before production use, check image quality, copyright risk, brand consistency, and content safety.
Limitations
- Supported models, input formats, image sizes, generation count, response format, image storage method, and billing may vary by image generation model.
- Image generation is stochastic. The same prompt may not generate the exact same image every time.
- Images containing text, fine details, hands, logos, tables, or precise spatial relationships may require manual review and further editing.
- Higher resolution, more generated images, reference image editing, or higher quality modes usually increase processing time and cost.
- Do not include sensitive personal information, copyrighted content you do not have the right to use, or content that violates platform policies in prompts or reference images.
Examples
The examples read the API Key from an environment variable so the key is not written into code.Generate an Image
The following example uses the OpenAI Python SDK to callgpt-image-2, generate one image, and save the returned Base64 image as a local PNG file.
For gpt-image-2, image results are in the response data array. Each image item includes a b64_json field, which can be decoded and saved as an image file.
The current
gpt-image-2 response returns Base64 image data. Do not rely on the url field to retrieve the image; even if the response structure includes url, it may be empty.Edit an Image
gpt-image-2 supports passing a reference image through client.images.edit() and generating an edited image based on the prompt.

