# Images and vision

Learn how to understand or generate images.

## Overview

[Create images](https://platform.openai.com/docs/guides/image-generation)[Process image inputs](#analyze-images)

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**. With `gpt-image-1`, they can both analyze visual inputs and
create images.

The OpenAI API offers several endpoints to process images as input or generate
them as output, enabling you to build powerful multimodal applications.

| API                                                                         | Supported use cases                                                   |
| --------------------------------------------------------------------------- | --------------------------------------------------------------------- |
| [Responses API](https://platform.openai.com/docs/api-reference/responses)   | Analyze images and use them as input and/or generate images as output |
| [Images API](https://platform.openai.com/docs/api-reference/images)         | Generate images as output, optionally using images as input           |
| [Chat Completions API](https://platform.openai.com/docs/api-reference/chat) | 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](https://platform.openai.com/docs/models).

## Generate or edit images

You can generate or edit images using the Image API or the Responses API.

Our latest image generation model, `gpt-image-1`, is a natively multimodal large
language model. It can understand text and images and leverage its broad world
knowledge to generate images with better instruction following and contextual
awareness.

In contrast, we also offer specialized image generation models - DALLÂ·E 2 and
3 - which don't have the same inherent understanding of the world as GPT Image.

```javascript
import OpenAI from "openai";
const openai = new OpenAI();

const response = await openai.responses.create({
  model: "gpt-4.1-mini",
  input:
    "Generate an image of gray tabby cat hugging an otter with an orange scarf",
  tools: [{ type: "image_generation" }],
});

// Save the image to a file
const 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"));
}
```

```python
from openai import OpenAI
import base64

client = OpenAI()

response = client.responses.create(
    model="gpt-4.1-mini",
    input="Generate an image of gray tabby cat hugging an otter with an orange scarf",
    tools=[{"type": "image_generation"}],
)

// Save the image to a file
image_data = [
    output.result
    for output in response.output
    if output.type == "image_generation_call"
]

if image_data:
    image_base64 = image_data[0]
    with open("cat_and_otter.png", "wb") as f:
        f.write(base64.b64decode(image_base64))
```

You can learn more about image generation in our
[Image generation](https://platform.openai.com/docs/guides/image-generation)
guide.

### Using world knowledge for image generation

The difference between DALLÂ·E models and GPT Image is that a natively multimodal
language model can use its 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](https://platform.openai.com/docs/guides/images-vision#limitations).

### Giving a model images as input

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](https://platform.openai.com/docs/api-reference/files))

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](https://platform.openai.com/docs/guides/images-vision#calculating-costs)
and will be billed accordingly.

Passing a URL

```javascript
import OpenAI from "openai";

const openai = new OpenAI();

const response = await openai.responses.create({
  model: "gpt-4.1-mini",
  input: [
    {
      role: "user",
      content: [
        { type: "input_text", text: "what's in this image?" },
        {
          type: "input_image",
          image_url:
            "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg",
        },
      ],
    },
  ],
});

console.log(response.output_text);
```

```python
from openai import OpenAI

client = OpenAI()

response = client.responses.create(
    model="gpt-4.1-mini",
    input=[{
        "role": "user",
        "content": [
            {"type": "input_text", "text": "what's in this image?"},
            {
                "type": "input_image",
                "image_url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg",
            },
        ],
    }],
)

print(response.output_text)
```

```bash
curl https://api.openai.com/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "model": "gpt-4.1-mini",
    "input": [
      {
        "role": "user",
        "content": [
          {"type": "input_text", "text": "what is in this image?"},
          {
            "type": "input_image",
            "image_url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"
          }
        ]
      }
    ]
  }'
```

Passing a Base64 encoded image

```javascript
import fs from "fs";
import OpenAI from "openai";

const openai = new OpenAI();

const imagePath = "path_to_your_image.jpg";
const base64Image = fs.readFileSync(imagePath, "base64");

const response = await openai.responses.create({
  model: "gpt-4.1-mini",
  input: [
    {
      role: "user",
      content: [
        { type: "input_text", text: "what's in this image?" },
        {
          type: "input_image",
          image_url: `data:image/jpeg;base64,${base64Image}`,
        },
      ],
    },
  ],
});

console.log(response.output_text);
```

```python
import base64
from openai import OpenAI

client = OpenAI()