> ## Documentation Index
> Fetch the complete documentation index at: https://docs.snapgen.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Image API protocol

> Common request and response rules for image models.

SnapGen exposes an OpenAI-compatible image generations endpoint. Select the exact model page under **Image Series** for its price and output rules.

<ParamField body="model" type="string" required>
  An image model ID returned by [`GET /v1/models`](/api-reference/list-models).
</ParamField>

<ParamField body="prompt" type="string" required>
  A clear description of the image to generate.
</ParamField>

<ParamField body="size" type="string">
  Use `1024x1024`, `1536x1024`, or `1024x1536` for an explicit square,
  landscape, or portrait frame. Omit it for automatic framing.
</ParamField>

<ParamField body="n" type="integer" default="1">
  Request one image. The current SnapGen image routes do not support batch
  generation.
</ParamField>

## Generate an image

```bash theme={null}
curl https://api.snapgen.org/v1/images/generations \
  -H "Authorization: Bearer $SNAPGEN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "A precise indigo product icon on a white background",
    "size": "1024x1024",
    "n": 1
  }'
```

Image generation is synchronous and can take 20 to 60 seconds. Set a client timeout of at least 120 seconds.

## Decode the response

The response contains base64 image bytes at `data[0].b64_json`.

```bash theme={null}
curl https://api.snapgen.org/v1/images/generations \
  -H "Authorization: Bearer $SNAPGEN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-image-2","prompt":"An indigo paper lantern"}' \
  | jq -r '.data[0].b64_json' \
  | base64 --decode > image.png
```

On macOS, replace `base64 --decode` with `base64 -D`.

```json theme={null}
{
  "created": 1784045139,
  "data": [{"b64_json": "iVBORw0KGgoAAAANSUhEUg..."}]
}
```

<Note>
  `gpt-image-2` costs $0.01 per successful generation and `gpt-image-2-all`
      costs $0.02. See the individual model page before estimating cost.
</Note>
