Developer Docs › Image generation

Image generation

Call GPT Image, Gemini (Nano Banana) and other image models with the OpenAI Images format, at 1K / 2K / 4K.

Endpoint

POST https://api.onefast.ai/v1/images/generations   # text-to-image
POST https://api.onefast.ai/v1/images/edits         # image-to-image / inpainting (multipart)
Authorization: Bearer sk-xxx

All image models are called with the OpenAI Images format, and images are returned as Base64 (b64_json).

Text-to-image

cURL

curl https://api.onefast.ai/v1/images/generations \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2.5",
    "prompt": "A cute corgi astronaut, studio lighting",
    "size": "1024x1024",
    "n": 1
  }' | python3 -c "import sys,json,base64; open('out.png','wb').write(base64.b64decode(json.load(sys.stdin)['data'][0]['b64_json']))"

Python

import base64
from openai import OpenAI

client = OpenAI(api_key="sk-xxx", base_url="https://api.onefast.ai/v1")
result = client.images.generate(
    model="gpt-image-2.5",
    prompt="A cute corgi astronaut, studio lighting",
    size="1024x1024",
)
with open("out.png", "wb") as f:
    f.write(base64.b64decode(result.data[0].b64_json))

Node.js

import fs from "node:fs";
import OpenAI from "openai";

const client = new OpenAI({ apiKey: "sk-xxx", baseURL: "https://api.onefast.ai/v1" });
const result = await client.images.generate({
  model: "gpt-image-2.5",
  prompt: "A cute corgi astronaut, studio lighting",
  size: "1024x1024",
});
fs.writeFileSync("out.png", Buffer.from(result.data[0].b64_json, "base64"));

Image generation usually takes 20–60 seconds. Set your HTTP client timeout to 300 seconds or more.

Common parameters

Parameter Description
model Required. Image model; see the model catalog (filter by "Image")
prompt Required. Description of the image
size Size as WIDTHxHEIGHT (lowercase x), e.g. 1024x1024, 1536x1024
n Number of images, default 1
quality Quality. GPT Image: low / medium / high / auto; for Gemini see below
background GPT Image supports transparent (transparent background, with PNG)
output_format GPT Image supports png / jpeg / webp

Gemini images (Nano Banana) and 4K

Gemini (Nano Banana) image models such as gemini-3.1-flash-image, gemini-3-pro-image-preview and gemini-nano-banana-2.1 use the same endpoint. The gateway decides the resolution tier and aspect ratio as follows:

Resolution (1K / 2K / 4K) — quality takes precedence; otherwise the longest side of size decides:

You send Tier
"quality": "4k" / "ultra", or longest side of size ≥ 3000 4K
"quality": "2k" / "hd", or longest side of size ≥ 1600 2K
"quality": "1k", or anything else 1K

Aspect ratio — taken from the width-to-height ratio of size and snapped to the nearest standard ratio (1:1, 16:9, 9:16, 4:3, 3:4, 3:2, 2:3, 21:9).

cURL

curl https://api.onefast.ai/v1/images/generations \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-3.1-flash-image",
    "prompt": "A watercolor lighthouse at dawn",
    "size": "3840x2160"
  }'

The example above produces a 16:9 4K image. Exact pixel dimensions are determined by the model (for example, 2K at 16:9 is about 2752×1536). The output may be PNG or JPEG — check the file header.

Image-to-image / editing

Upload the source image (multipart form) and describe the change in prompt:

cURL

curl https://api.onefast.ai/v1/images/edits \
  -H "Authorization: Bearer $API_KEY" \
  -F model="gpt-image-2.5" \
  -F image="@input.png" \
  -F prompt="Add a red scarf to the dog"

Python

result = client.images.edit(
    model="gpt-image-2.5",
    image=open("input.png", "rb"),
    prompt="Add a red scarf to the dog",
)

Gemini image models accept several reference images in one request (up to 14, field name image[]) and do not support mask.

Response and token usage

A successful response returns the images in data. GPT Image and Gemini image models also return token usage in usage:

{
  "created": 1793777279,
  "data": [{ "b64_json": "iVBORw0KGgo..." }],
  "usage": {
    "total_tokens": 1419,
    "input_tokens": 7,
    "output_tokens": 1412,
    "input_tokens_details": { "text_tokens": 7, "image_tokens": 0 },
    "output_tokens_details": { "text_tokens": 292, "image_tokens": 1120 }
  }
}
  • For Gemini image models, usage covers the whole request, including every image when n is greater than 1. output_tokens includes thinking tokens; these, along with any output the model does not break down by type, are counted in text_tokens.
  • input_tokens_details and output_tokens_details appear only when the model reports a breakdown. usage is omitted when no token usage is reported.
  • For Gemini image models in groups that charge per token, the charge is based on the full input_tokens and output_tokens; input_tokens_details and output_tokens_details are only a breakdown.
  • In groups that charge per image, usage is for reference only and does not affect the charge.

Billing

  • Some groups charge per image (regardless of size), others per token (output image tokens at the output price). The listed price for that group in the model catalog applies.
  • Failed requests are not billed.