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

# Image generation

> Generate images from text prompts via `POST /v1/images/generations`.

Image generation is synchronous and OpenAI-shaped: send a prompt, get back base64-encoded PNGs in the response body. Find image-capable models with `supports` containing `image_generation` — see [model discovery](/inference-api/guides/model-discovery#image-generation).

The example below uses `FLUX.1-schnell`.

## Example

<CodeGroup>
  ```bash cURL theme={null}
  curl https://tokens.flex.ai/v1/images/generations \
    -H "Authorization: Bearer $FLEXAI_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "FLUX.1-schnell",
      "prompt": "a watercolor of a fox in a snowdrift",
      "size": "1024x1024"
    }' \
    | jq -r '.data[0].b64_json' | base64 -d > out.png
  ```

  ```python Python theme={null}
  import base64, os
  from openai import OpenAI

  client = OpenAI(base_url="https://tokens.flex.ai/v1", api_key=os.environ["FLEXAI_API_KEY"])

  resp = client.images.generate(
      model="FLUX.1-schnell",
      prompt="a watercolor of a fox in a snowdrift",
      size="1024x1024",
  )
  with open("out.png", "wb") as f:
      f.write(base64.b64decode(resp.data[0].b64_json))
  ```

  ```typescript TypeScript theme={null}
  import fs from "node:fs";
  import OpenAI from "openai";

  const client = new OpenAI({
    baseURL: "https://tokens.flex.ai/v1",
    apiKey: process.env.FLEXAI_API_KEY,
  });

  const resp = await client.images.generate({
    model: "FLUX.1-schnell",
    prompt: "a watercolor of a fox in a snowdrift",
    size: "1024x1024",
  });
  fs.writeFileSync("out.png", Buffer.from(resp.data[0].b64_json!, "base64"));
  ```
</CodeGroup>

## Request fields

| Field             | Required | Notes                                                                                                                                                  |
| ----------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `model`           | Yes      | Must have `image_generation` in `supports`.                                                                                                            |
| `prompt`          | Yes      | —                                                                                                                                                      |
| `n`               | No       | Must be `1` (the default). Multiple images per request are not currently supported.                                                                    |
| `size`            | No       | One of `512x512`, `768x768`, `1024x1024`, `1024x1792`, `1792x1024`. Default `1024x1024`.                                                               |
| `response_format` | No       | **`b64_json` only.** OpenAI's `url` format is not supported — the field is accepted for SDK compatibility but anything other than `b64_json` is a 400. |

## Response

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

Decode `b64_json` with your language's base64 helper and write the bytes as a `.png`.

## Billing

Image models bill per output image, not per token — see the `pricing[]` rows on the model entry in `GET /api/models`, or the [billing reference](/inference-api/reference/billing).
