Image generation
Generate images with a dedicated endpoint or inline in chat
Gateway generates images two ways, depending on the model:
- Dedicated image models (e.g.
openai/gpt-image-2,xai/grok-imagine-image) usePOST /v1/images/generations. - Hybrid chat+image models (Google’s Nano Banana family:
google/gemini-2.5-flash-image,google/gemini-3.1-flash-image,google/gemini-3-pro-image) generate images inline in a normal/v1/responsesconversation.
Model availability and pricing come from GET /v1/models: image-capable models list image in their output modalities.
Dedicated endpoint
The image arrives as base64 in the JSON response (data[0].b64_json), not
raw bytes. Some vendors also support response_format: "url"; xAI models
always return base64 through Gateway.
Inline images in chat (hybrid models)
Hybrid models generate images as content blocks in a chat response. Pass
modalities: ["text", "image"] and use the typed input form:
Image blocks appear alongside text blocks in output[].content[] with base64
data.
Pricing
Image models bill one of two ways. The pricing block on GET /v1/models
tells you which:
- Per token (
unit: per_token): image output is metered in image-output tokens (reported asusage.image_output_tokens), so cost scales with resolution automatically - Per image (
unit: per_image): a flat rate per generated image, with optional resolution tiers underoutput_per_image_by_resolution