Image generation
Generate images through the gateway with routing, fallback, budgets and per-token cost tracking
OpenAI-compatible image generation. Calls to this endpoint go through the same API keys, budgets, usage limits and usage reporting as chat requests, so agents and apps that generate images show up in your usage data instead of bypassing it.
The request body is forwarded to the provider as raw JSON and the provider's response comes back unchanged. Provider-specific parameters such as output_format, quality or Gemini's aspect_ratio work as the provider defines them.
Choosing a model
Use a model from GET /v1/models whose output includes image, in author/model format, for example openai/gpt-image-2.5-flare. Image models appear in the console with an Image generation badge.
An image-only model sent to a chat endpoint, or a chat model sent to /v1/images/generations, is rejected with a 400 and the code model_not_supported.
Gemini models
Gemini image models, such as google/gemini-3-pro-image, are served through Google's Interactions API. The gateway translates your OpenAI-style request into it and translates the answer back, so you send and receive the same shapes as for any other image model. What that API offers shapes a few parameters:
- One image per request.
nmust be1, otherwise the request is rejected with a400. - JPEG only.
output_formatmust bejpegif you send it, andresponse_formatmust beb64_json. A transparentbackgroundis also rejected. - Size.
size(for example1536x1024) maps to the closest supported aspect ratio and rounds up to the next of 1K, 2K and 4K. You can send Gemini's ownaspect_ratioandimage_sizeinstead, and they win oversize. - Ignored.
quality,moderation,output_compressionanduserdo not change what Gemini draws, so they are accepted and ignored. - Refusals. If Gemini answers without an image, because it declined the prompt or replied in text, the request returns a
400with the codecontent_filter.
Thinking tokens are billed as text output, at the text rate.
Streaming
Streaming is not supported yet. A request with stream: true returns a 400 and nothing is sent to a provider. Leave stream out, or set it to false.
Retries and fallback
Each provider is tried once. Image generation is slow and billed per token, so a generation that failed after the provider started work may already have been charged, and repeating it would charge it again.
If a provider fails, the gateway falls back to another provider of the same model. It never falls back to a different model, and routing strategies do not reroute this endpoint. The X-Edgee-Provider response header names the provider that served the request, and X-Edgee-Fallback-Used is present when a fallback served it.
A moderation or safety block is a verdict on your prompt, not on the provider, so it is returned to you as a 400 with the provider's message and is not retried elsewhere.
Usage and cost
Image models are billed per token, and the rates differ by kind of token. Text input, text output, image input and image output are priced separately. A model with no image rate bills image tokens at its regular input or output rate. The gateway reads the provider's usage, splits it the same way, and prices each part at its own rate, so a request that mostly produces image tokens is not priced as if it produced text.
The usage record keeps the split. It carries image_input_tokens and image_output_tokens (subsets of the input and output tokens) with their costs, and the operation is recorded as image_generation. The rates for a model are in the model catalog and on its page in the console. Requests count against the same organization budgets and usage limits as chat requests.
Response size
Every image comes back base64 encoded in the same response. As a guide, four high-quality 1536x1024 images from n: 4 came to about 20 MB and took around 25 seconds. Large n at high resolution produces proportionally larger responses, so set client timeouts and body limits accordingly.
The in-docs request playground relays responses of up to 64 KB, so it cannot show an image. Use the generated curl command instead.
Debug logs
When debug logging is enabled for a request, each b64_json image in the response is replaced by a size marker such as [redacted: base64, 1028000 chars] before the log is stored. The request, including the prompt, is kept.
Generate images from a text prompt, OpenAI-compatible. The request body is forwarded as raw JSON and the provider's response is returned unchanged, so provider-specific parameters (`output_format`, `quality`, `aspect_ratio`) work as the provider defines them. Only models whose output includes `image` are accepted here, and image-only models are rejected on the chat endpoints. Streaming is not supported yet: `stream: true` returns a 400. Each provider is tried once, because a retried generation may already have been billed; if it fails the gateway falls back to another provider of the same model, but a moderation or safety block is returned to the client without a fallback. Usage is billed per token with separate text input, image input and image output rates. Responses carry base64 images and can reach tens of MB for a large `n` at high resolution; the base64 data is replaced by a size marker in debug logs.
https://edgee.io/v1/images/generationsTry this endpoint
Configure your request, then run the curl command in your terminal or send it from this page.
Run in your terminal
Set EDGEE_API_KEY to your Gateway API key in your terminal, then copy and run this command. Gateway requests may consume credits.
curl --include --no-buffer --globoff --request POST 'https://edgee.io/v1/images/generations' \
--header "Authorization: Bearer $EDGEE_API_KEY" \
--header 'Content-Type: application/json' \
--data-raw '{
"model": "openai/gpt-image-2.5-flare",
"prompt": "A minimalist flat icon of a red fox",
"n": 1,
"size": "1024x1024",
"quality": "low"
}'Send from browser
Your request is relayed through the Edgee documentation server to the Gateway. Your key is used only for this request and is not stored.
Authentication
Use an Edgee Gateway API key. Send it as Authorization: Bearer <key>.
Request body
modelstringrequiredImage model identifier from GET /v1/models, in author/model format, or a configured global alias. Append :provider to request a specific provider route.
promptstringrequiredText description of the image to generate. The maximum length depends on the model (32000 characters for the GPT image models).
nintegerNumber of images to generate. Every image is billed in output tokens and returned in the same response, so a large `n` at high resolution produces a very large response. Gemini image models accept only 1.
sizestringImage size, for example `1024x1024`, `1536x1024`, `1024x1536` or `auto`. The supported values depend on the model and are validated by the provider. Gemini models map it to the closest aspect ratio and the next size up of 1K, 2K or 4K.
qualitystringRendering quality, for example `auto`, `low`, `medium` or `high`. Higher quality uses more output tokens.
output_formatstringImage file format, for example `png`, `jpeg` or `webp`. Gemini image models return JPEG only.
output_compressionintegerCompression level for `jpeg` and `webp` output.
backgroundstringBackground of the generated image, for example `transparent`, `opaque` or `auto`, on models that support it.
moderationstringContent moderation level, on models that support it.
response_formatstringOnly for DALL-E models. The GPT image models always return base64 (`b64_json`).
streambooleanStreaming is not supported. `true` returns a 400.
userstringOptional end-user identifier forwarded to the provider.
tagsarrayGateway extension: tags recorded on the usage row. Removed before the request reaches the provider.
Show schema
stringaspect_ratiostringGemini image models only: the aspect ratio, for example `16:9`. Wins over `size`. Google validates the value.
image_sizestringGemini image models only: `1K`, `2K` or `4K` (uppercase K). Wins over `size`. Google validates the value.
{
"model": "openai/gpt-image-2.5-flare",
"prompt": "A minimalist flat icon of a red fox",
"n": 1,
"size": "1024x1024",
"quality": "low"
}Responses
200Images generated successfully. The body is the provider's response.
application/json
createdintegerUnix timestamp (seconds) of when the images were created.
dataarrayThe generated images.
Show schema
b64_jsonstringThe image as a base64 string. GPT image models always answer with this.
urlstringA URL to the image, for DALL-E models with `response_format: url`.
revised_promptstringThe prompt the model actually used, when it rewrote yours.
backgroundstringoutput_formatstringqualitystringsizestringusageobjectToken usage reported by the provider. The gateway prices text input, image input and image output at separate rates.
Show schema
input_tokensintegeroutput_tokensintegertotal_tokensintegerinput_tokens_detailsobjectPrompt tokens by kind.
Show schema
text_tokensintegerimage_tokensintegeroutput_tokens_detailsobjectOutput tokens by kind. When a provider omits this breakdown, all output counts as image tokens.
Show schema
text_tokensintegerimage_tokensinteger{
"created": 1792426685,
"data": [
{
"b64_json": "iVBORw0KGgoAAAANSUhEUgAA..."
}
],
"output_format": "png",
"quality": "low",
"size": "1024x1024",
"usage": {
"input_tokens": 14,
"input_tokens_details": {
"text_tokens": 14,
"image_tokens": 0
},
"output_tokens": 196,
"output_tokens_details": {
"text_tokens": 0,
"image_tokens": 196
},
"total_tokens": 210
}
}400Malformed request, `stream: true`, a model that does not produce images, an invalid/disabled model or provider, a prompt the provider's moderation blocked, or a parameter the provider rejects.
application/json
OpenAI-shaped Gateway error. Native upstream errors can retain provider-specific details.
errorobjectrequiredShow schema
messagestringrequiredA human-readable error message.
typestringrequiredHigh-level error category, including billing_error for exhausted Edgee credits (HTTP 402).
codestringMachine-readable error code, for example unauthorized, invalid_json, bad_model_id, model_disabled, provider_disabled, credit_balance_exhausted, usage_limit_exceeded, usage_unavailable, provider_error or internal_error. Not an exhaustive enum.
paramstringName of the request parameter that caused the error, when applicable.
401Missing or invalid API credentials.
application/json
OpenAI-shaped Gateway error. Native upstream errors can retain provider-specific details.
errorobjectrequiredShow schema
messagestringrequiredA human-readable error message.
typestringrequiredHigh-level error category, including billing_error for exhausted Edgee credits (HTTP 402).
codestringMachine-readable error code, for example unauthorized, invalid_json, bad_model_id, model_disabled, provider_disabled, credit_balance_exhausted, usage_limit_exceeded, usage_unavailable, provider_error or internal_error. Not an exhaustive enum.
paramstringName of the request parameter that caused the error, when applicable.
403Key inactive, expired, model restriction or other permission failure.
application/json
OpenAI-shaped Gateway error. Native upstream errors can retain provider-specific details.
errorobjectrequiredShow schema
messagestringrequiredA human-readable error message.
typestringrequiredHigh-level error category, including billing_error for exhausted Edgee credits (HTTP 402).
codestringMachine-readable error code, for example unauthorized, invalid_json, bad_model_id, model_disabled, provider_disabled, credit_balance_exhausted, usage_limit_exceeded, usage_unavailable, provider_error or internal_error. Not an exhaustive enum.
paramstringName of the request parameter that caused the error, when applicable.
429Usage limit or routing-strategy budget exhausted, or provider rate limit.
application/json
OpenAI-shaped Gateway error. Native upstream errors can retain provider-specific details.
errorobjectrequiredShow schema
messagestringrequiredA human-readable error message.
typestringrequiredHigh-level error category, including billing_error for exhausted Edgee credits (HTTP 402).
codestringMachine-readable error code, for example unauthorized, invalid_json, bad_model_id, model_disabled, provider_disabled, credit_balance_exhausted, usage_limit_exceeded, usage_unavailable, provider_error or internal_error. Not an exhaustive enum.
paramstringName of the request parameter that caused the error, when applicable.
502Upstream provider failure, or no provider is available for the model.
application/json
OpenAI-shaped Gateway error. Native upstream errors can retain provider-specific details.
errorobjectrequiredShow schema
messagestringrequiredA human-readable error message.
typestringrequiredHigh-level error category, including billing_error for exhausted Edgee credits (HTTP 402).
codestringMachine-readable error code, for example unauthorized, invalid_json, bad_model_id, model_disabled, provider_disabled, credit_balance_exhausted, usage_limit_exceeded, usage_unavailable, provider_error or internal_error. Not an exhaustive enum.
paramstringName of the request parameter that caused the error, when applicable.