In this guide, you will learn about building applications involving images with the OpenAI API.
If you know what you want to build, find your use case below to get started. If you’re not sure where to start, continue reading to get an overview.
A tour of image-related use cases
Recent language models can process image inputs and analyze them—a capability known as vision. GPT Image models can use text and image inputs to create new images or edit existing ones.
The OpenAI API offers several endpoints to process images as input or generate them as output, enabling you to build powerful multimodal applications.
Analyze images and use them as input to generate text or audio
To learn more about the input and output modalities supported by our models, refer to our models page.
Generate or edit images
You can generate or edit images using the Image API or the Responses API.
The state-of-the-art image generation model, gpt-image-2, can understand text and images and use broad world knowledge to generate images with strong instruction following and contextual awareness.
Generate images with Responses
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20import OpenAI from "openai";const openai = new OpenAI();const response = await openai.responses.create({ model: "gpt-5.6", input: "Generate an image of gray tabby cat hugging an otter with an orange scarf", tools: [{ type: "image_generation" }],});// Save the image to a fileconst imageData = response.output .filter((output) => output.type === "image_generation_call") .map((output) => output.result);if (imageData.length > 0) { const imageBase64 = imageData[0]; const fs = await import("fs"); fs.writeFileSync("cat_and_otter.png", Buffer.from(imageBase64, "base64"));}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22from openai import OpenAIimport base64client = OpenAI()response = client.responses.create(model="gpt-5.6",input="Generate an image of gray tabby cat hugging an otter with an orange scarf",tools=[{"type": "image_generation"}],)# Save the image to a fileimage_data = [ output.resultfor output in response.outputif output.type =="image_generation_call"]if image_data: image_base64 = image_data[0]withopen("cat_and_otter.png", "wb") as f: f.write(base64.b64decode(image_base64))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43package mainimport ( "context" "encoding/base64" "os" "github.com/openai/openai-go/v3" "github.com/openai/openai-go/v3/responses")func main() { client := openai.NewClient() response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{ Model: "gpt-5.6", Input: responses.ResponseNewParamsInputUnion{ OfString: openai.String("Generate an image of a gray tabby cat hugging an otter with an orange scarf."), }, Tools: []responses.ToolUnionParam{{ OfImageGeneration: &responses.ToolImageGenerationParam{}, }}, }) if err != nil { panic(err) } for _, output := range response.Output { if output.Type != "image_generation_call" { continue } image, err := base64.StdEncoding.DecodeString(output.AsImageGenerationCall().Result) if err != nil { panic(err) } if err := os.WriteFile("cat_and_otter.png", image, 0o600); err != nil { panic(err) } return } panic("response did not include an image generation call")}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21require "base64"require "openai"client = OpenAI::Client.newresponse = client.responses.create( model: "gpt-5.6", input: "Generate an image of a gray tabby cat hugging an otter with an orange scarf.", tools: [{type: :image_generation}])image_call = response.output.find do |item| item.is_a?(OpenAI::Models::Responses::ResponseOutputItem::ImageGenerationCall)endunless image_call.is_a?(OpenAI::Models::Responses::ResponseOutputItem::ImageGenerationCall) raise "No image generation call returned"endFile.binwrite( "cat_and_otter.png", Base64.strict_decode64(image_call.result))
1
2
3
4
5
6
7
8openai responses create \ --model gpt-5.6 \ --raw-output \ --transform 'output.#(type=="image_generation_call").result' <<'YAML' | base64 --decode > cat_and_otter.pngtools: - type: image_generationinput: Generate an image of a gray tabby cat hugging an otter with an orange scarf.YAML
You can learn more about image generation in our Image
generation guide.
Using world knowledge for image generation
GPT Image models can use visual understanding of the world to generate lifelike images including real-life details without a reference.
For example, if you prompt GPT Image to generate an image of a glass cabinet with the most popular semi-precious stones, the model knows enough to select gemstones like amethyst, rose quartz, jade, etc, and depict them in a realistic way.
Analyze images
Vision is the ability for a model to “see” and understand images. If there is text in an image, the model can also understand the text.
It can understand most visual elements, including objects, shapes, colors, and textures, even if there are some limitations.
Giving a model images as input
You can provide images as input to generation requests either by providing a fully qualified URL to an image file, or providing an image as a Base64-encoded data URL.
You can provide multiple images as input in a single request by including multiple images in the content array, but keep in mind that images count as tokens and will be billed accordingly.
You can provide images as input to generation requests in multiple ways:
By providing a fully qualified URL to an image file
By providing an image as a Base64-encoded data URL
By providing a file ID (created with the Files API)
You can provide multiple images as input in a single request by including multiple images in the content array, but keep in mind that images count as tokens and will be billed accordingly.
Up to 512 MB total payload size per request - Up to 1500 individual
image inputs per request
Other requirements
No watermarks or logos - No NSFW content - Clear enough for a human to
understand
Choose an image detail level
The detail parameter tells the model what level of detail to use when processing and understanding the image (low, high, original, or auto). If you skip the parameter, the model will use auto. This behavior is the same in both the Responses API and the Chat Completions API. On gpt-5.5 and GPT-5.6 models, auto and the default omitted behavior are equivalent to original.
Use the following guidance to choose a detail level:
Detail level
Best for
low
Fast, low-cost understanding when fine visual detail is not important. The model receives a low-resolution 512px x 512px version of the image.
high
Standard high-fidelity image understanding when precise original-image coordinates are not required.
original
Large, dense, spatially sensitive, or computer-use images. Available on gpt-5.4 and future models.
auto
Automatic detail selection. On gpt-5.5 and GPT-5.6 models, auto and the omitted/default behavior are equivalent to original.
For high-accuracy tasks that require fine visual detail or precise coordinates in the original image, such as optical character recognition (OCR), small-object detection, bounding boxes, localization, or computer use, set "detail": "original" when supported. The low and high detail levels may resize the image before analysis, which can obscure small details and cause model-generated coordinates to no longer match the original image. On gpt-5.4 and gpt-5.5, original can also resize images that exceed the model’s patch or dimension limits; for coordinate-sensitive tasks, resize those images before sending them and remap returned coordinates to the original image. Use low or high when lower cost or latency is more important than fine-detail recognition or spatial accuracy. See the Computer use guide for more detail.
Different models use different resizing rules before image tokenization:
Model family
Supported detail levels
Patch and resizing behavior
GPT-5.6 family
low, high, original,
auto
low and high can resize images under their
finite limits. original preserves the input dimensions and
does not resize the image to a pixel-dimension or patch-budget limit.
auto and omitted detail use the same sizing
behavior as original. Request payload and other image-input
limits still apply.
gpt-5.5
low, high, original,
auto
high allows up to 2,500 patches or a 2048-pixel maximum
dimension. original allows up to 10,000 patches or a
6000-pixel maximum dimension. If either limit is exceeded, we resize the
image while preserving aspect ratio to fit within the lesser of those two
constraints for the selected detail level. auto and omitted
detail use the same sizing behavior as
original. Full resizing details
below.
gpt-5.4
low, high, original,
auto
high allows up to 2,500 patches or a 2048-pixel maximum
dimension. original allows up to 10,000 patches or a
6000-pixel maximum dimension. If either limit is exceeded, we resize the
image while preserving aspect ratio to fit within the lesser of those two
constraints for the selected detail level. auto and omitted
detail use the same sizing behavior as
high. Full resizing details
below.
gpt-5.4-mini, gpt-5.4-nano,
gpt-5-mini, gpt-5-nano, gpt-5.2,
gpt-5.3-codex, gpt-5-codex-mini,
gpt-5.1-codex-mini, gpt-5.2-codex,
gpt-5.2-chat-latest, o4-mini, and the
gpt-4.1-mini and gpt-4.1-nano 2025-04-14
snapshot variants
low, high, auto
high allows up to 1,536 patches or a 2048-pixel maximum
dimension. If either limit is exceeded, we resize the image while
preserving aspect ratio to fit within the lesser of those two constraints.
Full resizing details below.
GPT-4o, GPT-4.1, GPT-4o-mini,
computer-use-preview, and o-series models except
o4-mini
Image inputs are metered and charged in token units similar to text inputs. How images are converted to text token inputs varies based on the model. You can find a vision pricing calculator in the FAQ section of the pricing page.
Patch-based image tokenization
Some models tokenize images by covering them with 32px x 32px patches. Many model and detail-level combinations define a maximum patch budget. The token cost of an image is determined as follows:
A. Compute how many 32px x 32px patches are needed to cover the original image. A patch may extend beyond the image boundary.
For GPT-5.6 models with detail set to original or auto, the service uses the original patch count without resizing the image to a patch budget or pixel-dimension limit. This means large images can use more input tokens than they did with earlier models. To control token use and latency, resize the image before sending it or select low or high detail.
B. If the original image would exceed the model’s patch budget, scale it down proportionally until it fits within that budget. Then adjust the scale so the final resized image stays within budget after converting to integer pixel dimensions and computing patch coverage.
C. Convert the adjusted scale into integer pixel dimensions, then compute the number of patches needed to cover the resized image. This resized patch count is the image-token count before applying the model multiplier, and it is capped by the model’s patch budget.
Resized patch count before the model multiplier: 1452
Multiply by the model’s token multiplier to get the billed token units.
Tile-based image tokenization
GPT-4o, GPT-4.1, GPT-4o-mini, CUA, and o-series (except o4-mini)
The token cost of an image is determined by two factors: size and detail.
Any image with "detail": "low" costs a set, base number of tokens. This amount varies by model. To calculate the cost of an image with "detail": "high", we do the following:
Scale to fit in a 2048px x 2048px square, maintaining original aspect ratio
Scale so that the image’s shortest side is 768px long
Count the number of 512px squares in the image. Each square costs a set amount of tokens, shown below.
Add the base tokens to the total
Model
Base tokens
Tile tokens
gpt-5, gpt-5-chat-latest
70
140
gpt-4o, gpt-4.1, gpt-4.5
85
170
gpt-4o-mini
2833
5667
o1, o1-pro, o3
75
150
computer-use-preview
65
129
GPT Image 1
For GPT Image 1, we calculate the cost of an image input the same way as described above, except that we scale down the image so that the shortest side is 512px instead of 768px.
The price depends on the dimensions of the image and the input fidelity.
When input fidelity is set to low, the base cost is 65 image tokens, and each tile costs 129 image tokens.
When using high input fidelity, we add a set number of tokens based on the image’s aspect ratio in addition to the image tokens described above.
If your image is square, we add 4160 extra input image tokens.
If it is closer to portrait or landscape, we add 6240 extra tokens.
While models with vision capabilities are powerful and can be used in many situations, it’s important to understand the limitations of these models. Here are some known limitations:
Medical images: The model is not suitable for interpreting specialized medical images like CT scans and shouldn’t be used for medical advice.
Non-English: The model may not perform optimally when handling images with text of non-Latin alphabets, such as Japanese or Korean.
Small text: Enlarge text within the image to improve readability. When available, using "detail": "original" can also help performance.
Rotation: The model may misinterpret rotated or upside-down text and images.
Visual elements: The model may struggle to understand graphs or text where colors or styles—like solid, dashed, or dotted lines—vary.
Spatial reasoning: The model struggles with tasks requiring precise spatial localization, such as identifying chess positions.
Accuracy: The model may generate incorrect descriptions or captions in certain scenarios.
Image shape: The model struggles with panoramic and fisheye images.
Metadata and resizing: The model doesn’t process original file names or metadata. low and high detail, and models with finite image budgets, may resize images before analysis. GPT-5.6 models preserve the input dimensions with original and auto detail.
Counting: The model may give approximate counts for objects in images.
CAPTCHAs: For safety reasons, our system blocks the submission of CAPTCHAs.
We process images at the token level, so each image we process counts towards your tokens per minute (TPM) limit.
For the most precise and up-to-date estimates for image processing, please use our image pricing calculator available here.