# GPT Image 2

> OpenAI's premium image generation family for text-to-image creation and single-image editing with simple prompt-driven controls.

## Overview

- Submit: `https://api.poyo.ai/api/generate/submit`
- Status: `https://api.poyo.ai/api/generate/status/{task_id}`
- Page: https://poyo.ai/models/gpt-image-2
- Model page ID: `gpt-image-2`
- API model IDs: `gpt-image-2`, `gpt-image-2-edit`
- Category: Image
- Auth: `Authorization: Bearer $POYO_API_KEY`
- Create a key at https://poyo.ai/dashboard/api-key

This model uses PoYo's unified async API. POST the JSON body below, then poll status with the returned `task_id` or receive a webhook on `callback_url`. Failed tasks are not charged.

## Pricing

- Low quality - 1K: 2 credits ($0.010) per generation
- Low quality - 2K: 4 credits ($0.020) per generation
- Low quality - 4K: 8 credits ($0.040) per generation
- Medium quality - 1K: 8.48 credits ($0.042) per generation
- Medium quality - 2K: 8.96 credits ($0.045) per generation
- Medium quality - 4K: 16.16 credits ($0.081) per generation
- High quality - 1K: 33.76 credits ($0.169) per generation
- High quality - 2K: 35.52 credits ($0.178) per generation
- High quality - 4K: 64.16 credits ($0.321) per generation

For more details, see https://poyo.ai/models/gpt-image-2.

## API Information

The request envelope is always `{ model, input, callback_url? }`. Input fields below are nested under `input`.

### Request envelope

- `model` (`ModelEnum`, required):
  GPT Image 2 model identifier
  - Options: `"gpt-image-2"`, `"gpt-image-2-edit"`
- `callback_url` (`string`, optional):
  Webhook callback URL for result notifications
  - Examples: "https://your-domain.com/callback"

### Input Schema

Input parameters for generation or editing

The API accepts the following `input` parameters:

- `prompt` (`string`, required):
  Prompt describing the target image or requested edit
  - Length: 0 to 20000 characters
  - Examples: "A beautiful sunset over the ocean"
- `quality` (`QualityEnum`, optional):
  Output image quality. Possible enum values: `low`, `medium`, `high`.
  - Default: `"low"`
  - Options: `"low"`, `"medium"`, `"high"`
  - Examples: "low"
- `image_urls` (`list`, optional):
  Reference image URLs. Required for `gpt-image-2-edit`. Supports multiple input images.
  - Array of string
  - Examples: `["https://example.com/flower.jpg","https://example.com/vase.jpg"]`
- `size` (`string`, optional):
  Output image aspect ratio or custom pixel size. Preset values: `auto`, `1:1`, `2:3`, `3:2`, `4:3`, `3:4`, `4:5`, `5:4`, `16:9`, `9:16`, `21:9`. Custom size uses `WIDTHxHEIGHT` format (e.g., `2304x1536`) and requires `resolution` to be `2K` or `4K`. Images with `auto` or without a `size` parameter will always use 1K resolution.
  - Default: `"auto"`
  - Examples: "1:1"
- `resolution` (`ResolutionEnum`, optional):
  Output image resolution. `1K` (default): standard resolution. `2K`: high resolution. `4K`: ultra-high resolution applies to `16:9`, `9:16`, `21:9`, or custom sizes with a 3840-pixel edge; other 4K selections are downgraded to 2K.
  - Default: `"1K"`
  - Options: `"1K"`, `"2K"`, `"4K"`
  - Examples: "1K"

Required Parameters Example:

```json
{
  "model": "gpt-image-2",
  "input": {
    "prompt": "A premium product photo of a silver espresso machine on a clean white studio background, realistic lighting, high detail",
    "quality": "low",
    "size": "1:1"
  }
}
```

Full Example:

```json
{
  "model": "gpt-image-2",
  "input": {
    "prompt": "A premium product photo of a silver espresso machine on a clean white studio background, realistic lighting, high detail",
    "quality": "low",
    "size": "1:1",
    "image_urls": [
      "https://example.com/flower.jpg",
      "https://example.com/vase.jpg"
    ],
    "resolution": "1K"
  }
}
```

GPT Image 2 Generation (2K):

```json
{
  "model": "gpt-image-2",
  "input": {
    "prompt": "A premium product photo of a silver espresso machine on a clean white studio background, realistic lighting, high detail",
    "quality": "medium",
    "size": "16:9",
    "resolution": "2K"
  }
}
```

GPT Image 2 Generation (4K):

```json
{
  "model": "gpt-image-2",
  "input": {
    "prompt": "A cinematic landscape with dramatic lighting, ultra-high detail",
    "quality": "high",
    "size": "16:9",
    "resolution": "4K"
  }
}
```

### Output Schema

Submit returns a `task_id`. Poll `GET /api/generate/status/{task_id}` until `status` is `finished` or `failed`. Completed media is in `data.files`.

Response fields:

- `code` (`CodeEnum`, required):
  Business status code. `200` means success; any other value means the request failed. Always check this field: some validation errors return HTTP 200 with `code: 400` in the body.
  
  - `200`: Success
  - `400`: Invalid request parameters
  - `401`: Missing or invalid API key
  - `402`: Insufficient credits
  - `403`: Permission denied
  - `404`: Resource not found
  - `408`: Request timeout
  - `429`: Rate limit exceeded
  - `500`: Internal server error
  - `502`: Upstream service error
  - `503`: Service unavailable
  
  See [Error Codes](/api-manual/error-codes) for details.
  - Options: `200`, `400`, `401`, `402`, `403`, `404`, `408`, `429`, `500`, `502`, `503`
  - Examples: `200`
- `data` (`object`, required):

Example Response:

```json
{
  "code": 200,
  "data": {
    "task_id": "task_example",
    "status": "finished",
    "files": [
      {
        "file_url": "https://storage.poyo.ai/gpt-image-2/gpt-image-2-example-1_1.png",
        "file_type": "image"
      }
    ]
  }
}
```

## Usage Examples

### cURL

```bash
curl --request POST \
  --url https://api.poyo.ai/api/generate/submit \
  --header "Authorization: Bearer $POYO_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{"model":"gpt-image-2","input":{"prompt":"A premium product photo of a silver espresso machine on a clean white studio background, realistic lighting, high detail","quality":"low","size":"1:1"}}'
```

### Python

```python
import json
import os
import time
import requests

API = "https://api.poyo.ai"
headers = {
    "Authorization": f"Bearer {os.environ['POYO_API_KEY']}",
    "Content-Type": "application/json",
}
payload = json.loads("{\n  \"model\": \"gpt-image-2\",\n  \"input\": {\n    \"prompt\": \"A premium product photo of a silver espresso machine on a clean white studio background, realistic lighting, high detail\",\n    \"quality\": \"low\",\n    \"size\": \"1:1\"\n  }\n}")

submit = requests.post(f"{API}/api/generate/submit", headers=headers, json=payload)
submit.raise_for_status()
task_id = submit.json()["data"]["task_id"]

while True:
    status = requests.get(f"{API}/api/generate/status/{task_id}", headers=headers)
    status.raise_for_status()
    data = status.json()["data"]
    if data["status"] in ("finished", "failed"):
        print(data)
        break
    time.sleep(2)
```

### JavaScript

```javascript
const headers = {
  Authorization: `Bearer ${process.env.POYO_API_KEY}`,
  "Content-Type": "application/json",
};

const submit = await fetch("https://api.poyo.ai/api/generate/submit", {
  method: "POST",
  headers,
  body: JSON.stringify({
  "model": "gpt-image-2",
  "input": {
    "prompt": "A premium product photo of a silver espresso machine on a clean white studio background, realistic lighting, high detail",
    "quality": "low",
    "size": "1:1"
  }
}),
});

const submitted = await submit.json();
const taskId = submitted.data.task_id;

while (true) {
  const statusResponse = await fetch(`https://api.poyo.ai/api/generate/status/${taskId}`, { headers });
  const status = await statusResponse.json();
  if (["finished", "failed"].includes(status.data.status)) {
    console.log(status.data);
    break;
  }
  await new Promise((resolve) => setTimeout(resolve, 2000));
}
```

## Additional Resources

### Documentation

- [Model Playground](https://poyo.ai/models/gpt-image-2)
- [API Documentation](https://docs.poyo.ai/api-manual/image-series/gpt-image-2)
- [API Documentation (Markdown)](https://docs.poyo.ai/api-manual/image-series/gpt-image-2.md)
- [Task status](https://docs.poyo.ai/api-manual/task-management/query-task-status)
- [Webhooks](https://docs.poyo.ai/api-manual/task-management/webhooks)

### Other agent-readable surfaces

- [Platform overview](https://poyo.ai/llms.txt)
- [Documentation index](https://docs.poyo.ai/llms.txt)
- [Full documentation text](https://docs.poyo.ai/llms-full.txt)
- Any other model: `https://poyo.ai/models/<model-id>/llms.txt`
