# Image generation

Learn how to generate or edit images.

## Overview

The OpenAI API lets you generate and edit images from text prompts, using the
GPT Image or DALLÂ·E models. You can access image generation capabilities through
two APIs:

### Image API

The [Image API](https://platform.openai.com/docs/api-reference/images) provides
three endpoints, each with distinct capabilities:

- **Generations**:
  [Generate images](https://platform.openai.com/docs/guides/image-generation#generate-images)
  from scratch based on a text prompt
- **Edits**:
  [Modify existing images](https://platform.openai.com/docs/guides/image-generation#edit-images)
  using a new prompt, either partially or entirely
- **Variations**:
  [Generate variations](https://platform.openai.com/docs/guides/image-generation#image-variations)
  of an existing image (available with DALLÂ·E 2 only)

This API supports `gpt-image-1` as well as `dall-e-2` and `dall-e-3`.

### Responses API

The
[Responses API](https://platform.openai.com/docs/api-reference/responses/create#responses-create-tools)
allows you to generate images as part of conversations or multi-step flows. It
supports image generation as a
[built-in tool](https://platform.openai.com/docs/guides/tools?api-mode=responses),
and accepts image inputs and outputs within context.

Compared to the Image API, it adds:

- **Multi-turn editing**: Iteratively make high fidelity edits to images with
  prompting
- **Flexible inputs**: Accept image
  [File](https://platform.openai.com/docs/api-reference/files) IDs as input
  images, not just bytes

The image generation tool in responses only supports `gpt-image-1`. For a list
of mainline models that support calling this tool, refer to the
[supported models](https://platform.openai.com/docs/guides/image-generation#supported-models)
below.

### Choosing the right API

- If you only need to generate or edit a single image from one prompt, the Image
  API is your best choice.
- If you want to build conversational, editable image experiences with GPT
  Image, go with the Responses API.

Both APIs let you
[customize output](https://platform.openai.com/docs/guides/image-generation#customize-image-output)
â adjust quality, size, format, compression, and enable transparent backgrounds.

### Model comparison

Our latest and most advanced model for image generation is `gpt-image-1`, a
natively multimodal language model.

We recommend this model for its high-quality image generation and ability to use
world knowledge in image creation. However, you can also use specialized image
generation modelsâDALLÂ·E 2 and DALLÂ·E 3âwith the Image API.

| Model     | Endpoints                                                         | Use case                                                                               |
| --------- | ----------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
| DALLÂ·E 2  | Image API: Generations, Edits, Variations                         | Lower cost, concurrent requests, inpainting (image editing with a mask)                |
| DALLÂ·E 3  | Image API: Generations only                                       | Higher image quality than DALLÂ·E 2, support for larger resolutions                     |
| GPT Image | Image API: Generations, Edits â Responses API support coming soon | Superior instruction following, text rendering, detailed editing, real-world knowledge |

This guide focuses on GPT Image, but you can also switch to the docs for
[DALLÂ·E 2](https://platform.openai.com/docs/guides/image-generation?image-generation-model=dall-e-2)
and
[DALLÂ·E 3](https://platform.openai.com/docs/guides/image-generation?image-generation-model=dall-e-3).

To ensure this model is used responsibly, you may need to complete the API
Organization Verification from your developer console before using
`gpt-image-1`.

![a vet with a baby otter](https://cdn.openai.com/API/docs/images/otter.png)

## Generate Images

You can use the
[image generation endpoint](https://platform.openai.com/docs/api-reference/images/create)
to create images based on text prompts, or the
[image generation tool](https://platform.openai.com/docs/guides/tools?api-mode=responses)
in the Responses API to generate images as part of a conversation.

To learn more about customizing the output (size, quality, format,
transparency), refer to the
[customize image output](https://platform.openai.com/docs/guides/image-generation#customize-image-output)
section below.

You can set the `n` parameter to generate multiple images at once in a single
request (by default, the API returns a single image).

Responses API

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

const response = await openai.responses.create({
  model: "gpt-5",
  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("otter.png", Buffer.from(imageBase64, "base64"));
}
```

```python
from openai import OpenAI
import base64

client = OpenAI()

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