Skip to main content
Send a prompt to POST /v1/images/generations and NagaAI returns the finished images as links or as inline base64. To change a picture you already have, send it with a prompt to POST /v1/images/edits. Both endpoints follow the OpenAI Images format, so the OpenAI SDK works unchanged.

Generate an image

Pick any model whose kinds include image in GET /v1/models, or browse them at naga.ac/models. The response lists one entry in data per image, and usage reports what NagaAI counted for the bill:

Set the size and count

size is WIDTHxHEIGHT, such as 1536x1024. There is no separate aspect ratio field, so you set the ratio through size. Each model takes its own sizes. NagaAI checks a GPT Image size before the request leaves. gpt-image-1 models take 1024x1024, 1024x1536, 1536x1024 and auto. Later GPT Image models take auto or a size within four limits. Both edges are multiples of 16, and no edge is above 3840. The ratio is up to 3:1, and the image has 655,360 to 8,294,400 pixels. n asks for several images in one request. The limit is limits.max_images on the model’s image_generation operation in GET /v1/models, usually 4. NagaAI ignores style, output_format and other fields, so setting them changes nothing. With url, each entry of data holds a link on media.naga.ac to a copy that NagaAI hosts for 24 hours and then deletes. Download the file when you receive the response, or store it in your own bucket. With b64_json, the image bytes come inline as base64 and NagaAI stores nothing. Vector models such as Ideogram Vector return SVG. A browser that opens the link downloads the file, and an <img> tag still shows it.

Stream the image

Set stream to true and the answer arrives as server-sent events in the OpenAI format, so code written for OpenAI image streaming runs unchanged. Each image comes in its own image_generation.completed event as base64, whatever response_format says, and the last event carries usage.
NagaAI sends no image_generation.partial_image events yet. The providers answer with the finished image, and it arrives as soon as the provider is done. OpenAI documents that fewer partial images may arrive than partial_images asks for, so a client that handles partials keeps working. When NagaAI refuses a request before the provider starts, the answer is the usual status and JSON error. A failure after the stream has opened comes as an error event with the same error object.

Fall back to another model

When the model you asked for can’t make the image, NagaAI can send the same request to another model. List up to three fallbacks in models, in the order to try them. The field has the shape OpenRouter uses on chat, so the same habit works for pictures.
POST /v1/images/edits takes the list as form parts, one models part per fallback, as in -F models=openai/gpt-image-2.5-flare-2026-09-08. The OpenAI SDKs send extra_body={"models": [...]} as models[] parts, and NagaAI reads both names. NagaAI moves to the next model when every provider of the model failed or the provider’s moderation refused the prompt. It also moves on when the model can’t take the request, for example an n above its max_images. An empty balance or a rate limit would fail on every model, so NagaAI stops there. You pay only for the model that made the images, at its own price, and attempts that failed cost nothing. A fallback that isn’t in the catalog fails the request with 400 model_not_found before anything runs, and more than three fail with 400 invalid_request_error. Routing explains fallbacks in detail.

Edit an image

POST /v1/images/edits takes a multipart form with the image, a prompt, and an optional mask. A transparent area of the mask marks what the model may repaint.
The response has the same shape as a generation. The model must have an image_edit operation in GET /v1/models.

Billing

Images are priced per token. usage.output_tokens is what the provider reports for the images it made. When a provider reports nothing, NagaAI counts the model’s published number for the picture’s resolution, for example 1,290 for google/gemini-2.5-flash-image. A model with no published number counts 2,048 per image. The output_image_token row of pricing in GET /v1/models holds the price per token. NagaAI checks every prompt with its own moderation before it picks a provider.

Draw with a chat model

Some chat models draw inside a chat request instead. They return the pictures through the chat endpoints, see Images in the answer. The image endpoints take these models too, such as google/gemini-2.5-flash-image. NagaAI sends the prompt and your images to the model as one chat turn and returns the picture it draws in the usual data list. NagaAI bills the picture from the chat answer’s usage, at the same output_image_token price. Three things work differently on this path. size reaches the model as a sentence in the prompt, so the model may come close to it rather than match it exactly. A mask goes to the model as one more image, with a line asking it to change only the transparent area. NagaAI sends n above 1 to the model’s image providers only, because one chat answer holds one picture.

Troubleshooting

NagaAI deletes hosted images 24 hours after it makes them. Download the image on arrival, or ask for b64_json.

400 with size must be in format

The message reads body.size: Value error, size must be in format "{width}x{height}", for example "1024x1024". Write the size as two numbers joined by a lowercase x, with no spaces and no ratio such as 16:9.

400 with size … is not available for this model

The model doesn’t take that size. The message lists the sizes it does take. A GPT Image model below 655,360 pixels, such as 256x256, is the usual case: ask for 1024x1024 and scale the image down yourself.

400 with Too many images

The message reads Too many images. This model supports up to 4, with the model’s own limit. Lower n, or send several requests.

400 with At least one image must be provided

An edit needs at least one image part. Check that the form is multipart/form-data and that the part is named image or image[].

400 model_not_found

The model does not exist or has no image_generation operation (image_edit for edits). Check its operations in GET /v1/models.

403 inappropriate_content

NagaAI’s moderation blocked the prompt. Change the prompt and send it again.

413

The request body is over 32 MiB. Send a smaller image.