Image Generation

Generate and edit images from text prompts across all supported image models.

POST/v1/images/generations

Generate images from text prompts across all supported image models: GPT Image, Nano Banana, FLUX.2, Seedream, and more. The same endpoint also handles image editing when you pass reference images (aliased as POST /v1/images/edits).

Image families

FamilyModel IDsPricing knob
GPT Imagegpt-image-1-mini, gpt-image-1, gpt-image-1.5, gpt-image-2quality: low, medium or high. Omitted, the request bills at the dearest level the model has, so high
GPT Image (five levels)gpt-image-2.5-sunburst, gpt-image-2.6-sunburst, gpt-image-2.6-flarequality: low, medium, high, xhigh or max. Omitted, the request is priced at the dearest level, max; on the two 2.6 models that is the amount held, and the charge follows the output tokens (see below)
Nano Banananano-banana-flash-lite, nano-banana, nano-banana-2, nano-banana-proresolution: 0.5K, 1K, 2K or 4K (availability per model); nano-banana-pro adds 2.415 credits per reference image
FLUX.2flux-2-pro, flux-2-flexFlat rate per image; aspect_ratio and resolution pass through
FLUX 3flux-3-imageresolution: 1K, 1.5K, 2K or 4K, from 106 to 1,333 credits. Omitted, 1K
Grok Imaginegrok-imagine-image-2quality (low or medium) and resolution (1K or 2K): 88, 132 or 176 credits. Omitted, medium and 2K (176 credits)
Qwen Imageqwen-image-3, qwen-image-3-proFlat rate per image on qwen-image-3; qwen-image-3-pro priced by resolution (1K or 2K). Each reference image adds 6.585 credits
Seedreamseedream-4.5, seedream-5-lite, seedream-5-pro, seedream-5-5, seedream-5-flashFlat rate per image, except seedream-5-pro (priced by resolution: 1K or 2K); seedream-5-5 adds 18 credits per reference image; aspect_ratio and resolution pass through

Each model's page shows its current credit price per image, and X-Credits-Used on the response tells you what a call actually cost. A non-square size (e.g. 1536x1024) is billed at 1.5× the square price on gpt-image-1-mini and gpt-image-1.5 only. No other image model adds this surcharge: their price is flat or follows the quality or the resolution, and on the GPT Image 2.x models the size itself can set the price (see below). Passing aspect_ratio rather than size carries no surcharge.

Custom sizes on GPT Image 2, 2.5 and 2.6

On gpt-image-2, gpt-image-2.5-sunburst, gpt-image-2.6-sunburst and gpt-image-2.6-flare, size also takes any WIDTHxHEIGHT that follows OpenAI's rule: both sides multiples of 16, no side over 3,840 pixels, the long side at most 3 times the short side, and between 655,360 and 8,294,400 pixels in all. For example 2048x1152, 2048x2048 or 3840x2160. Any other size returns 400 invalid_parameter naming size, before anything is charged.

On gpt-image-2.5-sunburst, auto, 1024x1024, 1024x1536 and 1536x1024 keep the per-quality price shown on the model page. On gpt-image-2, the three standard sizes keep that price, and auto (or no size) is billed on its output tokens. On gpt-image-2.6-sunburst and gpt-image-2.6-flare, every size is billed on its output tokens, the three standard sizes and auto included: in 1024x1024, 56.4 credits at low and 97.629 at medium. With auto or no size on gpt-image-2, gpt-image-2.6-sunburst and gpt-image-2.6-flare, OpenAI picks the size: the credits held are those of 2048x2048, and the charge is what OpenAI reports, never more than the hold. If the image comes from a route that reports no output tokens, the charge is that of 1312x1199, the size OpenAI drew for auto on GPT Image 2.6 when we measured it. A custom size is billed on the image OpenAI actually produces: the credits held before the call follow OpenAI's published token count for that size and quality, and the charge is what OpenAI reports, never more than the hold. A higher quality costs more at the same size, but more pixels do not always cost more: on GPT Image 2.6 Sunburst, 3840x2160 holds fewer credits than 2048x2048 at the same quality. The playground shows the credits held for each size it offers. A custom size has no fallback: if the call fails, the request fails and the credits held are returned. OpenAI calls sizes larger than 2560x1440 (3,686,400 pixels) experimental on GPT Image 2.5 Sunburst.

Common request body

The fields below are shared by every image model. Model-specific options (size, aspect_ratio, resolution, quality, output_format, negative_prompt, seed, background, etc.) depend on the family. Open the model on Models and switch to the API tab for the full parameter reference.

ParameterTypeRequiredDescription
modelstringYesAny image model ID: e.g. nano-banana-pro, gpt-image-1, flux-2-pro, seedream-4.5.
promptstringYesText description of the image to generate.
nintegerNoNumber of images. Default: 1. Each model has a limit: up to 10 for GPT Image, 6 for Qwen Image 3. Seedream, FLUX and Grok Imagine make one image per request. More than a model's limit returns 400 invalid_parameter. Nano Banana returns one image per call, so n is clamped to 1.
response_formatstringNob64_json (default): the image as base64 in the response. url: a link to the image, valid 24 hours, then the image is deleted (see Getting a link). Any other value returns 400 unsupported_parameter at no charge.
imagesstring[]NoReference images for editing, as base64 or URLs. A request body can be up to 50 MB, and base64 adds about a third to each image: send large or many images as URLs (public https links). Accepted by Nano Banana, GPT Image, Seedream, FLUX 2, FLUX 3, Grok Imagine and Muse Image; the maximum depends on the model (16 for GPT Image, 14 for Nano Banana and Seedream 4.5/5 Lite, 10 for Seedream 5 Pro/Flash and FLUX 2 Flex, 8 for FLUX 2 Pro). FLUX 2 bills references by size: 32.925 credits per megapixel on Pro, 131.697 on Flex. Grok Imagine bills its one reference by size too: 21.95 credits per megapixel, 1 megapixel at least (about 263 credits for a 12-megapixel photo). On FLUX 2 and Grok Imagine, each reference is measured before the call and the credits held match its measured size. A reference whose size we cannot read (a link our server cannot open, or a format other than PNG, JPEG or WebP) returns 400 invalid_parameter naming it, before anything is charged.
userstringNoOptional end-user identifier for abuse monitoring.

Example

Swap model for any image model ID. Parameters beyond those shown below must match that model's API tab.

import Tchavi from '@tchavi/sdk';

const client = new Tchavi({ apiKey: 'YOUR_API_KEY' });

const result = await client.images.generations.create({
  model: 'YOUR_MODEL_ID',
  prompt: 'A colorful parrot on a branch, digital art',
});

console.log(result.data[0].b64_json);
console.log('Credits used:', result.tchavi.credits_used);

The response contains base64-encoded image data in data[0].b64_json, and its type in data[0].media_type: image/png, image/jpeg or image/webp. The format depends on the model: some return PNG, others JPEG, so read media_type rather than assuming one. tchavi.output_format gives the same answer for the response as a whole. Here's how to use it:

// Display the image in a browser
const img = document.createElement('img');
const image = data.data[0];
img.src = `data:${image.media_type};base64,${image.b64_json}`;
document.body.appendChild(img);

Send "response_format": "url" to receive a link instead of the image data. A high-resolution image is several megabytes of base64; a link keeps the response small and lets you download the file when you need it.

JSON
{
  "data": [
    {
      "url": "https://…/images/…-0.png?X-Amz-Signature=…",
      "media_type": "image/png"
    }
  ]
}
  • The link works for 24 hours. After that the link stops working, and the image is deleted from our storage shortly afterwards: download it if you need to keep it.
  • media_type tells you the format, as with base64.
  • The price is the same. If the image cannot be stored, the request fails with an error and you are not charged.
  • You can send the link back as a reference image (images) in a later request while it is still valid.

On this page