Image Generation
POST /v1/images/generations
Generate one or more images from a text prompt. Compatible (with extensions) with the OpenAI Images API.
Headers
| Header | Required | Description |
|---|---|---|
Authorization |
Yes | Bearer <api-key-or-jwt> |
Content-Type |
Yes | application/json |
X-Quantized-Provider |
No | Pin a provider by slug (openai or gemini), or one specific connection as <provider>/<connection>. The pin narrows the providers your license allows and never widens them. A malformed value or a disallowed provider returns 400. Otherwise resolved per-model from the catalog. |
X-Quantized-Metadata |
No | A flat JSON object of scalar values, recorded with the request for your own attribution. Invalid JSON or nested values return 400. See Authentication. |
Request body
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
model |
string | Yes | — | Model identifier (e.g. gpt-image-1.5, gpt-image-2, gemini-3.1-flash-image, imagen-4.0-fast-generate-001) |
prompt |
string | Yes | — | Text description of the image to generate |
n |
integer | No | 1 |
Number of images to generate. Range 1..10 at the serializer; per-model upper bounds are stricter (see Per-model constraints below). Ignored by Gemini Flash Image models, which return one image |
size |
string | No | "1024x1024" |
Image dimensions as WxH, or "auto". Sent as-is to OpenAI; mapped to the nearest supported aspect ratio and a 1K/2K size on Imagen; ignored by Gemini Flash Image models |
quality |
string | No | provider default | One of standard, hd, low, medium, high, auto |
style |
string | No | null | vivid or natural. Accepted for compatibility; no currently routable model uses it |
background |
string | No | null | transparent, opaque, auto. gpt-image-* only — stripped elsewhere |
output_format |
string | No | null | png, jpeg, webp. gpt-image-* only — stripped elsewhere |
output_compression |
integer | No | null | 0..100 JPEG/WebP quality. gpt-image-* only |
moderation |
string | No | null | auto or low. gpt-image-* only |
seed |
integer | No | null | Deterministic seed. Accepted for compatibility; no currently routable model accepts one — silently dropped |
negative_prompt |
string | No | null | Text describing what to avoid. Accepted for compatibility; no currently routable model accepts one — silently dropped |
user |
string | No | null | End-user identifier forwarded to OpenAI for abuse monitoring. Not sent to Gemini |
The serializer uses extra="forbid" — any field not listed above is rejected with 400 invalid_request. This keeps typos from being silently dropped.
Notable fields not accepted in this release: response_format (transport is forced to base64 — see below), messages, dimensions, image/mask (those belong to the not-yet-shipped /v1/images/edits endpoint).
The router returns b64_json for every response. Read images from data[].b64_json. There is no data[].url field. OpenAI itself removed the response_format parameter from /v1/images/generations in 2026, so even on the upstream side everything is base64. Gemini has always been base64 natively, so the contract is uniform across providers.
Examples
curl -X POST https://api.quantized.us/v1/images/generations \
-H "Authorization: Bearer sk-quantized-YOUR-KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-1.5",
"prompt": "A whimsical watercolor of a sleepy hedgehog under a mushroom",
"size": "1024x1024",
"quality": "low"
}'
curl -X POST https://api.quantized.us/v1/images/generations \
-H "Authorization: Bearer sk-quantized-YOUR-KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-1.5",
"prompt": "A logo on a fully transparent background, single hedgehog character",
"quality": "medium",
"background": "transparent",
"output_format": "png"
}'
curl -X POST https://api.quantized.us/v1/images/generations \
-H "Authorization: Bearer sk-quantized-YOUR-KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.1-flash-image",
"prompt": "A whimsical watercolor of a sleepy hedgehog under a mushroom"
}'
import base64
from openai import OpenAI
client = OpenAI(
api_key="sk-quantized-YOUR-KEY",
base_url="https://api.quantized.us/v1",
)
resp = client.images.generate(
model="gpt-image-1.5",
prompt="A whimsical watercolor of a sleepy hedgehog",
size="1024x1024",
quality="low",
)
img_bytes = base64.b64decode(resp.data[0].b64_json)
with open("hedgehog.png", "wb") as f:
f.write(img_bytes)
import base64
import httpx
response = httpx.post(
"https://api.quantized.us/v1/images/generations",
headers={"Authorization": "Bearer sk-quantized-YOUR-KEY"},
json={
"model": "gpt-image-1.5",
"prompt": "An overhead view of an open notebook with a pen",
"size": "1024x1024",
"quality": "low",
},
timeout=180,
)
data = response.json()
img_bytes = base64.b64decode(data["data"][0]["b64_json"])
print(f"image: {len(img_bytes)} bytes, watermark: {data['data'][0]['watermark']}")
Response
{
"created": 1787941342,
"model": "gpt-image-1.5",
"data": [
{
"b64_json": "iVBORw0KGgoAAAANSUhEUgAA...",
"revised_prompt": null,
"seed": null,
"watermark": "c2pa",
"flagged": false
}
],
"usage": {
"images": 1,
"input_tokens": 16,
"output_tokens": 272,
"total_tokens": 288,
"megapixels": null,
"credits_used": 109600
}
}
Response fields
| Field | Type | Description |
|---|---|---|
created |
integer | Unix timestamp from the upstream provider (0 if the provider doesn’t supply one — Gemini) |
model |
string | Model id echoed from the request (with any provider prefix preserved) |
data |
array | One entry per generated image, in upstream order |
data[].b64_json |
string | Base64-encoded image bytes (PNG by default, JPEG/WebP if requested on a gpt-image-* model) |
data[].revised_prompt |
string or null | Upstream-rewritten prompt. Gemini Flash Image returns mixed text and image parts, and the text part lands here when present, so the same model returns a string on one call and null on the next. null everywhere else |
data[].seed |
integer or null | Seed used by upstream when reported. No currently routable model reports one, so this is always null today |
data[].watermark |
string | One of c2pa, provenance, synthid, none — see Watermarking below |
data[].flagged |
boolean | true if upstream answered a moderation block with 200 and no image. No currently routable provider does this, so it is always false today |
usage.images |
integer | Number of images successfully generated. Equals data.length; on Gemini it can be lower than n, or 0 |
usage.input_tokens |
integer or null | Input token count — gpt-image-* and Gemini Flash Image. null on Imagen |
usage.output_tokens |
integer or null | Output (image) token count — gpt-image-* and Gemini Flash Image. null on Imagen |
usage.total_tokens |
integer or null | Sum of input + output tokens — gpt-image-* and Gemini Flash Image. null on Imagen |
usage.megapixels |
number or null | Megapixels rendered, as a surrogate when token counts aren’t available. null on every currently routable model |
usage.credits_used |
integer | Micro-credits consumed by this request |
Image generation endpoints are not streamable on any provider. stream: true is not accepted.
Watermarking
Different providers/models embed different provenance metadata. The watermark enum in each data[] entry lets clients disclose this to end users if needed.
| Value | Standard | Models |
|---|---|---|
c2pa |
C2PA Content Credentials | the gpt-image-* family |
provenance |
AWS provenance metadata | Reserved for Amazon Titan / Nova; not currently routable |
synthid |
Google SynthID | Gemini Flash Image, Imagen 4 |
none |
No watermark | No currently routable model returns this |
Quantized targets education customers. If your application surfaces images to students, consider rendering a disclosure when watermark != "none". The C2PA and SynthID standards are designed to be detectable downstream, but a textual disclosure removes ambiguity.
Per-model constraints
Each model has stricter limits than the serializer’s generic [1, 10] range for n and unrestricted size. The router does not enforce these. OpenAI and Imagen validate them upstream; Gemini Flash Image models ignore n, size and quality and return one image:
| Model | Provider | Max n |
Sizes | quality values |
Pricing |
|---|---|---|---|---|---|
gpt-image-2 |
openai | 1 | up to 3840px on the longer edge | low, medium, high, auto |
$5/M input + $40/M output tokens |
gpt-image-1.5 |
openai | 1 | up to 3840px on the longer edge | low, medium, high, auto |
$5/M input + $40/M output tokens |
gpt-image-1-mini |
openai | 1 | up to 3840px on the longer edge | low, medium, high, auto |
$5/M input + $40/M output tokens |
gemini-3-pro-image |
gemini | 1 | chat-style (no size knob) |
— | $0.040 per image |
gemini-3.1-flash-image |
gemini | 1 | chat-style (no size knob) |
— | $0.040 per image |
gemini-3.1-flash-lite-image |
gemini | 1 | chat-style (no size knob) |
— | $0.040 per image |
gemini-2.5-flash-image |
gemini | 1 | chat-style (no size knob) |
— | $0.039 per image |
imagen-4.0-fast-generate-001 |
gemini | 4 | 1K, or 2K when either requested edge is 2048px or more (aspect ratios: 1:1, 3:4, 4:3, 9:16, 16:9) |
— | $0.020 per image |
Billing for this endpoint uses the rates above, not price from /v1/models. That field is priced for the chat endpoints, so it shows token rates for the Gemini image models and null for most gpt-image-* models. Gemini image models are billed per image returned, even though usage reports their token counts. Imagen 4 is billed per image by tier: imagen-4.0-fast-generate-001 $0.020, imagen-4.0-generate-001 $0.040, imagen-4.0-ultra-generate-001 $0.060.
The gpt-image-* models accept background, output_format, output_compression and moderation, and require OpenAI org verification on our account. The Gemini Flash Image models route through :generateContent and return mixed text and image parts. Imagen routes through :predict.
gpt-image-1 is still resolvable but is deprecated in the catalog. DALL-E 2 and DALL-E 3 were retired by OpenAI in 2026 and are no longer served.
imagen-4.0-fast-generate-001 resolves and routes correctly, but Gemini’s :predict endpoint is not available on a free-tier API key, so requests currently come back 404 from Google. The Flash Image models are unaffected.
Discovery via /v1/models
Filter GET /v1/models on output_modality.image == true:
models = response.json()["data"] # GET /v1/models returns {"object": "list", "data": [...]}
image_models = [m for m in models if m["output_modality"]["image"]]
supported_features does not carry image_generation, so there is no semantic filter for this endpoint — a "image_generation" in supported_features check returns an empty list.
output_modality.image is the closest available signal, but it also matches models served only by OpenRouter, which cannot serve this endpoint. Cross-check against the table above until the catalog exposes which provider serves a model.
Providers
| Provider | Slug | Models |
|---|---|---|
| OpenAI Direct | openai |
gpt-image-2, gpt-image-1.5, gpt-image-1-mini, chatgpt-image-latest, gpt-image-1 (deprecated) |
| Google Gemini | gemini |
gemini-3-pro-image, gemini-3.1-flash-image, gemini-3.1-flash-lite-image, gemini-2.5-flash-image, imagen-4.0-fast-generate-001 |
These are the only two providers holding the image_generation capability, so X-Quantized-Provider: bedrock is not usable here. Routing is resolved per-model from the catalog, so requesting gemini-3.1-flash-image reaches Gemini with no header needed.
Unlike embeddings, image generation does not expose /v1/aws-bedrock/images/generations or /v1/gemini/images/generations native passthroughs. The unified /v1/images/generations is the only image endpoint — each provider adapts to that shape internally.
Errors
| Status | Code | Condition |
|---|---|---|
400 |
invalid_request |
Request body failed validation: a missing or invalid field, or an unrecognized field (e.g. unsupported enum value, out-of-range n or output_compression, response_format). param names the field |
400 |
invalid_request |
Malformed X-Quantized-Provider header (param: "X-Quantized-Provider") |
400 |
invalid_metadata_header |
Invalid X-Quantized-Metadata header |
400 |
invalid_request |
The provider rejected the request, including OpenAI content-policy rejections; the provider’s message is returned |
400 |
no_provider_available |
No provider available for the model or endpoint (e.g. X-Quantized-Provider names a provider that cannot serve this endpoint, or a pin your license doesn’t allow) |
401 |
missing_api_key, invalid_api_key, api_key_expired, license_inactive |
Missing, invalid, or expired API key, or an inactive license |
402 |
budget_exhausted |
Your license is out of budget. metadata names the limit that blocked the request |
403 |
policy_denied |
Your license’s policy does not allow this service or parameter value (param names the parameter) |
403 |
content_policy_violation |
Request blocked by a guardrail |
404 |
model_not_found |
Modality mismatch — the model resolves but no provider serving it can produce image output (e.g. an LLM or embedding model id) |
400 or 404 |
invalid_request or model_not_found |
Unknown model id — forwarded to a provider, which decides. See below |
429 |
rate_limit_exceeded |
The provider rate-limited the request. retry-after is set when the provider sent one |
500 |
internal_error |
Unexpected error, or a budget configuration error |
502 |
provider_error |
The provider returned a 5xx or an invalid response, or the connection dropped |
503 |
provider_misconfigured |
Our credentials for the provider are missing or were rejected (including OpenAI org-verification failures) |
503 |
policy_unavailable |
Your license’s policy can’t be evaluated |
504 |
upstream_timeout |
The provider timed out |
Every error uses the standard error body. Branch on the status and code; see the Error reference for each.
Model validation belongs to the provider (see “Who validates the model” in Errors overview). An id the catalog cannot resolve is forwarded as sent, and because this endpoint has two eligible providers with nothing to choose between them, the same request can reach either one:
reached Gemini 404 models/<id> is not found for API version v1beta ...
reached OpenAI 400 The model '<id>' does not exist.
Pin X-Quantized-Provider if you need a predictable failure. Requests naming a model the catalog resolves are unaffected: the model selects its provider.
OpenAI answers a content-policy block with a normal error response (400 with the upstream message), which the router returns as 400 invalid_request with OpenAI’s message.
Gemini may return fewer images than requested (possibly none); check len(data) / usage.images. data[].flagged is always false today.
The following are not accepted by /v1/images/generations in this release:
- Image edits (
/v1/images/edits) — requires multipart upload and mask handling - Image variations (
/v1/images/variations) response_format: "url"— transport is forced tob64_json- Streaming — no provider streams image bytes
- CDN rehosting — base64 only, no signed URLs
These may be added in a future release.