# OpenAI

import { Steps } from '@astrojs/starlight/components'

Invoke supports OpenAI's image generation models — the GPT Image family and DALL·E 3 — through the OpenAI API.

:::note[DALL·E 2 removed]
DALL·E 2 was deprecated by OpenAI and is scheduled for shutdown on 2026-05-12. It is no longer offered as a starter model in Invoke.
:::

## Getting an API Key

<Steps>
1. Open the [OpenAI API Platform](https://platform.openai.com/api-keys) and sign in.
2. Create a new secret API key.
3. Make sure your account has billing set up — image endpoints are paid per request.
</Steps>

## Configuration

Add your key to `api_keys.yaml` in your Invoke root directory:

```yaml
external_openai_api_key: "sk-..."

# Optional — use this to point at a compatible proxy or Azure OpenAI deployment
external_openai_base_url: "https://api.openai.com"
```

Restart Invoke for the change to take effect.

## Available Models

| Model | Modes | Aspect Ratios | Batch | Notes |
| --- | --- | --- | --- | --- |
| **GPT Image 1.5** | txt2img, img2img | 1:1, 3:2, 2:3 | up to 10 | Fastest and cheapest GPT Image model. |
| **GPT Image 1** | txt2img, img2img | 1:1, 3:2, 2:3 | up to 10 | Highest quality of the GPT Image family. |
| **GPT Image 1 Mini** | txt2img, img2img | 1:1, 3:2, 2:3 | up to 10 | ~80% cheaper than GPT Image 1. |
| **DALL·E 3** | txt2img only | 1:1, 7:4, 4:7 | 1 | No reference-image / edit support. |

Inpainting (mask-based editing) is not currently supported for any OpenAI model in Invoke. img2img on the GPT Image family routes through the `/v1/images/edits` endpoint without a mask.

## Provider-Specific Options

Selecting a GPT Image model adds a **Provider options** section to the Generate panel:

- **Quality** — `low`, `medium`, `high`, or `auto`. Higher quality costs more and takes longer.
- **Background** — `auto`, `transparent`, or `opaque`. Use `transparent` for PNG output with an alpha channel.
- **Input fidelity** — `low` or `high`, offered only for models that take image inputs (img2img or reference images). Leave it on the provider default to let OpenAI choose.

DALL·E 2 and DALL·E 3 do not expose these options.

These are recorded in the image metadata, so **Recall All** and **Remix** restore them when the image's model is selected.

The **Size** section lists the provider's fixed sizes per aspect ratio (**Provider size**). Any other size is mapped to the closest one the provider accepts.

## Canvas

GPT Image models that advertise `img2img` can generate from the Canvas: an empty bounding box runs text-to-image, and a filled one sends the composited bounding box as the init image. Invoke asks for the provider size whose aspect ratio is closest to the bounding box's, such as 1536×1024 for a 640×512 box. A text-to-image result is scaled to cover the bounding box and cropped to it from the center, so it is never stretched; when the shapes differ, a strip at two opposite edges is cut off. For image-to-image, the init image is resized to the provider size and the result is resized back to the exact bounding box. The render size, denoising strength, control layers and regional guidance do not apply and are not offered. Inpainting and outpainting are not available for OpenAI models.

DALL·E 3 generates only from text: on the Canvas, hide raster layers or move their content out of the bounding box to generate with it.

## How Requests Are Routed

- Pure text-to-image requests hit `/v1/images/generations`.
- Any request with an init image or reference images is sent to `/v1/images/edits` instead. This is done transparently — you don't need to pick an endpoint.

## Tips

<Steps>
1. Batching on GPT Image tops out at 10 per request. Larger batches are split into multiple API calls.
2. Costs can climb quickly with high-quality GPT Image generations. Start with GPT Image 1 Mini when iterating on prompts.
3. Rate limits from OpenAI surface as failed invocations — retry after a short wait.
</Steps>