# GPT Image 2 API Documentation

Generate images with GPT Image 2. Submit a request, save the task ID, then query for the finished image.

## Overview

Model ID: gpt-image-2. Text to Image · Image to Image. Check the current price and availability before your first request.

`POST /v1/tasks` — Create a task

`GET /v1/tasks/{id}` — Get the result

- [Model pricing & playground](https://gikyapi.com/models/gpt-image-2/)

## Authentication

Use Authorization: Bearer YOUR_API_KEY. For task creation, also send Content-Type: application/json and a unique Idempotency-Key. The example below includes all three headers.

## Request examples

Choose an operation and language. Replace YOUR_API_KEY and use a unique Idempotency-Key for each new generation; preserve it when retrying the same request.

### Text to Image

```json
{
  "model": "gpt-image-2",
  "operation": "text-to-image",
  "input": {
    "prompt": "A blue ceramic cup on a white table, soft morning light",
    "quality": "high",
    "resolution": "4K"
  }
}
```

### Image to Image

```json
{
  "model": "gpt-image-2",
  "operation": "image-to-image",
  "input": {
    "prompt": "A blue ceramic cup on a white table, soft morning light",
    "quality": "high",
    "image_urls": [
      "https://example.com/reference.png"
    ],
    "resolution": "4K"
  }
}
```

## Request parameters

The request body contains model, operation and input. Model-specific fields belong inside input; their accepted values are listed below.

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| model | string | Yes | gpt-image-2 |
| operation | string | Yes | text-to-image / image-to-image |
| input | object | Yes | Parameters for your selected operation. |
| callback | object | No | Use an endpoint_id saved in your account’s Webhooks settings. Omit this field when polling. |

## Text to Image input

Fields inside input. Optional fields may be omitted; send only the fields listed here.

| Parameter | Type | Required | Description / accepted values |
| --- | --- | --- | --- |
| prompt | string | Yes | Describe the scene, style or edit you want to make. Maximum 20000 characters. |
| quality | string | Yes | quality. Accepted: low, medium, high. |
| resolution | string | Yes | Output resolution. Choose a resolution listed in the model pricing. Accepted: 1K, 2K, 4K. |
| aspect_ratio | string | No | Aspect ratio of the generated output. Accepted: 1:1, 1:2, 2:1, 1:3, 3:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 9:21, 21:9. |
| output_format | string | No | File format of the generated image. Accepted: png, jpeg, webp. |

## Image to Image input

Fields inside input. Optional fields may be omitted; send only the fields listed here.

| Parameter | Type | Required | Description / accepted values |
| --- | --- | --- | --- |
| prompt | string | Yes | Describe the scene, style or edit you want to make. Maximum 20000 characters. |
| quality | string | Yes | quality. Accepted: low, medium, high. |
| image_urls | array | Yes | Public HTTPS URLs of reference images. Each URL must be accessible without signing in. Maximum 16 items. |
| resolution | string | Yes | Output resolution. Choose a resolution listed in the model pricing. Accepted: 1K, 2K, 4K. |
| aspect_ratio | string | No | Aspect ratio of the generated output. Accepted: 1:1, 1:2, 2:1, 1:3, 3:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 9:21, 21:9. |
| output_format | string | No | File format of the generated image. Accepted: png, jpeg, webp. |

## Create response

HTTP 202 means the task was accepted. Save id and use it to query the result. The response below is illustrative; generation has not finished at this stage.

```
{
  "id": "00000000-0000-4000-8000-000000000001",
  "status": "queued",
  "outputs": [],
  "error_code": null,
  "created_at": "2026-11-02T00:00:00Z",
  "updated_at": "2026-11-02T00:00:00Z"
}
```

## Query the result

Replace TASK_ID with the returned id. Use the same API key and poll every five seconds or more. When status is succeeded, read the file URLs from outputs.

`GET /v1/tasks/{id}` — Retrieve a task

```
curl --fail-with-body 'https://gikyapi.com/v1/tasks/TASK_ID' -H 'Authorization: Bearer YOUR_API_KEY'
```

## Response parameters

Creation and status queries return the same task structure.

| Field | Type | Description |
| --- | --- | --- |
| id | string | Task ID used in subsequent status queries. |
| status | string | queued / submitting / running / succeeded / failed / needs_review |
| outputs | string[] | Generated file URLs when the task succeeds. Save files to your own storage. |
| error_code | string | null | Failure code when available; null if there is no error. |
| created_at | string | Time the task was created. |
| updated_at | string | Time of the last task update. |

```
{
  "id": "00000000-0000-4000-8000-000000000001",
  "status": "succeeded",
  "outputs": [
    "https://example.com/result.png"
  ],
  "error_code": null,
  "created_at": "2026-11-02T00:00:00Z",
  "updated_at": "2026-11-02T00:00:00Z"
}
```

## Webhooks (optional)

Add an endpoint in Dashboard → Webhooks and save the signing secret on your server. Include its ID in the task request. You can also poll task status without configuring a callback.

| Parameter | Type | Required with callback | Description |
| --- | --- | --- | --- |
| callback.endpoint_id | string | Yes | ID of a callback endpoint owned by your account. |

```
{
  "callback": {
    "endpoint_id": "YOUR_ENDPOINT_ID"
  }
}
```

- [Configure callback endpoints](https://gikyapi.com/dashboard/webhooks/)
- [Signature verification & delivery retries](https://gikyapi.com/docs/webhooks/)

## Webhook parameters

Completion events use task.succeeded or task.failed. Verify the signature before processing and deduplicate by event id. A missing callback does not mean the task failed; query its status.

| Field | Type | Description |
| --- | --- | --- |
| id | string | Unique event ID; use it to deduplicate deliveries. |
| type | string | task.succeeded or task.failed |
| task_id | string | The generation task ID. |
| status | string | Task status at the time of the event. |
| outputs | string[] | Generated file URLs for a successful task. |

## Errors & retries

If a submission times out, retry with the same Idempotency-Key and identical body. If you already have a task ID, query that task instead of creating another one.

| Status | What to do |
| --- | --- |
| 400 | Check required fields, accepted values and the priced configuration. |
| 401 | Check your API key, expiry and restrictions. |
| 409 | Check the error code: refresh changed configurations or resolve a reused request key. |
| 429 | Wait at least 60 seconds before retrying. |
| failed | Read error_code and check the consumption record. |
| needs_review | Keep the task ID and stop automatic resubmission. |

- [All error codes](https://gikyapi.com/docs/errors/)
- [Billing & refunds](https://gikyapi.com/docs/billing/)
