# GPT Image 2 API

> GPT Image 2 — fast, high-fidelity AI image generation & editing.

- **Provider**: OpenAI
- **Model id**: `gpt-image-2-text-to-image`
- **Modality**: image
- **Price**: 12.56–24.93 credits

## Overview

GPT Image 2 is called in two steps: create a generation task, then poll the task until the result is ready.

## Authentication

All requests require a Bearer Token in the request header:

```
Authorization: Bearer YOUR_API_KEY
```

## Create Task

`POST https://you.bot/api/v1/generate`

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| modelId | string | Yes | Model id: `gpt-image-2-text-to-image` |
| input | object | Yes | Input parameters object (see below) |
| callbackUrl | string | No | https URL to receive a signed webhook on completion |

### input object parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| prompt | string | Yes | Used to describe the generated images. (default: A vintage brass diving helmet overgrown with coral and tiny anemones, resting on pale sand in slanting shafts of turquoise underwater light.) |
| aspect_ratio | string | No | For 2K and 4K resolution, the following aspect ratios are not supported: 5:4, 4:5, 3:1, 1:3, and 9:21. (options: auto | 1:1 | 3:2 | 2:3 | 4:3 | 3:4 | 16:9 | 9:16 | 2:1 | 1:2 | 3:1 | 1:3 | 21:9 | 9:21 | 5:4 | 4:5) (default: auto) |
| resolution | string | No | Image resolution (options: 1K | 2K | 4K) (default: 1K) |

### Request example

```json
{
  "modelId": "gpt-image-2-text-to-image",
  "input": {
    "prompt": "A photorealistic portrait of a red fox in a snowy forest, soft morning light, shallow depth of field, 85mm.",
    "aspect_ratio": "auto",
    "resolution": "1K"
  }
}
```

### Response example

```json
{
  "taskId": "281e5b0…f39b9",
  "creditsCharged": 24
}
```

## Query Task

`GET https://you.bot/api/v1/task/{taskId}?model=gpt-image-2-text-to-image`

When `state` is `success`, the output is in `resultUrls`: `{ "state": "success", "resultUrls": [ ... ] }`. (Text models return inline in the create response.)

## Error Codes

| Code | Description |
|------|-------------|
| 200 | Request successful |
| 400 | Invalid request parameters |
| 401 | Authentication failed, check API Key |
| 402 | Insufficient account balance |
| 422 | Parameter validation failed |
| 429 | Request rate limit exceeded |
| 500 | Internal server error |
