Skip to main content

Image Generation

Drop-in OpenAI compatible

Generate images through OpenAI's native /v1/images/generations API — swap your base URL and the OpenAI SDK's images.generate() just works.

The gateway mimics OpenAI's Images API exactly: the request body is forwarded as-is and the response relayed verbatim, so no client changes are needed beyond pointing at llm.bankr.bot. Today this is served by gpt-image-2.

Generating an image

POST /v1/images/generations

Authentication is the same as every other gateway endpoint — a Bankr API key (bk_...) via X-API-Key or Authorization: Bearer. Generate keys at bankr.bot/api-keys.

curl -X POST https://llm.bankr.bot/v1/images/generations \
-H "Content-Type: application/json" \
-H "X-API-Key: bk_YOUR_API_KEY" \
-d '{
"model": "gpt-image-2",
"prompt": "a friendly pixel-art robot mascot holding a coin",
"size": "1024x1024",
"n": 1
}'

Using the OpenAI SDK, only the base URL and key change:

from openai import OpenAI
import base64

client = OpenAI(base_url="https://llm.bankr.bot/v1", api_key="bk_YOUR_API_KEY")

result = client.images.generate(
model="gpt-image-2",
prompt="a friendly pixel-art robot mascot holding a coin",
size="1024x1024",
)

with open("robot.png", "wb") as f:
f.write(base64.b64decode(result.data[0].b64_json))
import OpenAI from "openai";
import { writeFileSync } from "node:fs";

const client = new OpenAI({
baseURL: "https://llm.bankr.bot/v1",
apiKey: "bk_YOUR_API_KEY",
});

const result = await client.images.generate({
model: "gpt-image-2",
prompt: "a friendly pixel-art robot mascot holding a coin",
size: "1024x1024",
});

writeFileSync("robot.png", Buffer.from(result.data[0].b64_json, "base64"));

Response

The response is relayed verbatim from the provider — the same shape as OpenAI's Images API. Images are returned as base64 in b64_json, and a usage object reports the tokens billed.

{
"created": 1783526478,
"data": [{ "b64_json": "iVBORw0KGgoAAAANSU..." }],
"usage": {
"input_tokens": 19,
"output_tokens": 1756,
"output_tokens_details": { "image_tokens": 1756, "text_tokens": 0 },
"total_tokens": 1775
}
}

Parameters

The body is forwarded to the provider, so any parameter its Images API accepts works. The most common:

ParameterDescription
modelRequired. gpt-image-2.
promptRequired. The text description of the image.
sizee.g. 1024x1024.
nNumber of images, 1–4 (capped by the gateway to bound per-request cost).

Streaming is not supported — omit stream (or set it to false). Unknown parameters are rejected by the provider, so stick to the documented image-generation fields.

Supported models

Image generation runs on models that produce image output. The source of truth is the /v1/models endpoint: an image model reports "output_modalities": ["image"] and its image rate under pricing.image_output. Check the flag rather than hard-coding — coverage expands as more image models come online.

bankr llm models    # or GET /v1/models

Error responses

StatusCodeMeaning
400stream_not_supportedstream was set — image generation does not support streaming.
400invalid_valuen is outside 1–4.
400unsupported_modelThe model does not generate images (chat-only model).
{
"error": {
"message": "Streaming is not supported for image generation",
"type": "invalid_request_error",
"code": "stream_not_supported"
}
}

Pricing

Image generation bills per output token, at the model's image-output rate, from your LLM credit balance.

Rategpt-image-2
Text input$5 / 1M tokens
Image output$30 / 1M tokens

A single 1024x1024 image is roughly 1,700 output tokens ≈ $0.05. The exact count is returned in the response usage object and recorded on your usage dashboard, broken out as image-output tokens separate from text. See credit management to top up.

Coding tools

Chat-based coding agents (Claude Code, Codex, Cursor, OpenCode) consume the chat-completions API, and image-only models are excluded from their model lists — so they don't generate images through the gateway.

OpenClaw is the exception: it has a built-in image_generate tool that routes to any OpenAI-compatible images endpoint. Point its OpenAI provider at the gateway and an OpenClaw agent generates with gpt-image-2 through Bankr — see OpenClaw → Image generation.

Otherwise, use the SDK or HTTP examples above.

Next steps