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

# Image generation

> Generate images with openai/gpt-image-2 through the OpenAI-compatible images endpoint, billed per token from the same prepaid credit balance.

Use `openai/gpt-image-2` to generate images from a text prompt.
`POST /v1/images/generations` accepts OpenAI's Images API shape and returns
base64-encoded image bytes — the model never returns URLs.

## Generate an image

```bash theme={null}
curl https://api.impossibl.com/v1/images/generations \
  -H "Authorization: Bearer imp-rt-..." \
  -H 'content-type: application/json' \
  -d '{
    "model": "openai/gpt-image-2",
    "prompt": "A watercolor lighthouse at dawn",
    "size": "1024x1024"
  }'
```

```json Response (abridged) theme={null}
{
  "created": 1785300000,
  "data": [{ "b64_json": "iVBORw0KGgo..." }],
  "usage": {
    "total_tokens": 214,
    "input_tokens": 18,
    "output_tokens": 196,
    "input_tokens_details": { "text_tokens": 18, "image_tokens": 0 }
  }
}
```

Decode `data[0].b64_json` to get the image file. A `revised_prompt` field
accompanies an image when the provider rewrote your prompt before generating.

## Options

| Field                | Values                                                            |
| -------------------- | ----------------------------------------------------------------- |
| `n`                  | number of images to generate, default 1                           |
| `size`               | `"{width}x{height}"` (e.g. `1024x1024`, `1536x1024`) or `"auto"`  |
| `quality`            | `auto`, `low`, `medium`, `high`, `standard`, `hd`                 |
| `background`         | `auto`, `transparent`, `opaque`                                   |
| `output_format`      | `png`, `jpeg`, `webp`                                             |
| `output_compression` | `0`–`100` (JPEG/WebP only)                                        |
| `user`               | stable per-user id forwarded to the provider for abuse monitoring |

## Billing

Image output is billed **per token** like any other model — text input tokens
plus image output tokens, at the rates in [Models & pricing](/docs/models)
($5.00 / $30.00 per 1M for `openai/gpt-image-2`). The cost is settled when
generation finishes and appears in `GET /v1/usage` and the
[request log](/docs/request-logs).

Two guardrails to know:

* Model and endpoint must match: sending an image model to a text endpoint
  (`/v1/chat/completions`, etc.) fails with `400 invalid_request_error`, as
  does sending a text model to the images endpoint.
* Image generation always draws on the prepaid balance — there is no
  [BYOK](/docs/byok) path for it yet, so an empty balance returns `402` even with a
  provider credential configured.
