Skip to main content
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. The example below uses FLUX.1-schnell.

Example

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
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))
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"));

Request fields

FieldRequiredNotes
modelYesMust have image_generation in supports.
promptYes
nNoMust be 1 (the default). Multiple images per request are not currently supported.
sizeNoOne of 512x512, 768x768, 1024x1024, 1024x1792, 1792x1024. Default 1024x1024.
response_formatNob64_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

{
  "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.