Make images from a text prompt
https://api.stav.ai/v1/images/generationsMakes images from a text prompt with an image model and returns them
as base64. The request and answer shape are OpenAI's: change only the
base URL (https://api.stav.ai/v1) and the key. Scope
inference:images.
Name a model listed with the images surface on GET /v1/models;
auto and Routers are refused (router_not_supported). Any field not
listed here is refused by name (unsupported_parameter), and so are
stream and response_format: "url".
Billing: one unit per request, the one the endpoint is priced in —
per image (flat, or by size and quality), else per megapixel of the
returned image, else tokens, else per request. usage.cost is the
charge in the workspace currency, from Stav's own ledger (absent when
the workspace's own key served the call). A provider link is fetched
and inlined; nothing is stored.
Header-parametere
X-Stav-Runs-InstringWhere this request may run, as a header:
eu,eea, one ISO 3166 alpha-2 country code, or a comma-separated list of codes (NO, SE). The same values and the same meaning as theprovider.runs_inbody field, for clients that can set fixed headers but not body fields (an SDK'sdefault_headers). It filters the Provider Endpoints that may serve and every failover; when none passes, the request is refused (403 endpoint_not_admissible) and nothing is sent.It only ever narrows. Sent together with
provider.runs_in, both must hold:X-Stav-Runs-In: eeawith"runs_in": "NO"runs in Norway;X-Stav-Runs-In: euwith"runs_in": "NO"or"US"has no country in common and is400 invalid_value. It never widens your workspace policy. A value Stav cannot read, an empty one, or two header lines with different values is400 invalid_valuewithparamX-Stav-Runs-In; the same value sent twice counts once. The request log shows the region with its source.GET /v1/modelslists only models with an endpoint inside it, and a Router orautoonly when at least one of its candidates has one (without a key,autois not listed under the header);GET /v1/models/{model_id}/endpointslists only those endpoints./v1/messages/count_tokensreads it too: when the provider's own counter is outside it, the count is a local estimate and the prompt is never sent. The response headerX-Stav-Token-Count(andstav_token_countin the body) saysexact,estimate(the model's own tokenizer, run by Stav) orapproximate(no tokenizer for the model: characters / 4). Reading or cancelling a stored response (GET /v1/responses/{id},/input_items,/cancel) held by an endpoint outside it is refused with403 endpoint_not_admissible;DELETEis not refused, so data held outside the region can always be erased.
Forespørselsinnhold
modelstringpåkrevdpromptstringpåkrevdWhat the image should show.
providerobjectStav extension, region per request. Narrows where this one request may run and which Inference Providers may serve it, on top of your workspace policy — it can only narrow, never widen. It filters Provider Endpoints: the serving endpoint and every failover stay inside it, and when no endpoint of the model passes, the request is refused (
403 endpoint_not_admissible, orprovider_blockedwhen every endpoint is on a provider you named inignore) and nothing is sent. A provider pinned in the model id (creator/model/provider) that the filter excludes is400 invalid_valuewithparamprovider.Any other key is refused by name (
400 unsupported_parameter,paramprovider.<key>). Never forwarded to a provider.Vis 4 underfelt
runs_instring | array of stringWhere the request may run:
"eu","eea", one ISO 3166 alpha-2 country code, or a list of country codes (["NO", "SE"]). One region or countries, not both in one list.globalendpoints satisfy no region, so most Claude and Gemini endpoints are excluded by"eu". TheX-Stav-Runs-Inheader takes the same values; sent with this field, both must hold.regionstring | array of stringAlias of
runs_in, same meaning. Not a provider region code — those are chosen in the model id (creator/model/provider:<code>). Sending both with different values is400 invalid_value.onlyarray of stringOnly endpoints of these Inference Providers serve (slugs, as listed by
GET /v1/models/{model_id}/endpoints). Applies to the endpoint, whoever the model's provider of record is. An unknown slug is400 invalid_value.ignorearray of stringNo endpoint of these Inference Providers serves (slugs).
nintegerHow many images. A model that makes one image per request refuses more with
400 n_not_supported;stav_image_options.max_nsays so in advance.sizestringWIDTHxHEIGHT in pixels, or
auto.qualitystringThe provider's quality word.
output_formatenumpngjpegwebpbackgroundstringPassed to the provider as sent.
seedintegerPassed to the provider as sent.
response_formatenumOnly
b64_json;urlis refused.b64_jsonuserstringAccepted and never forwarded.
Merknader
POST https://api.stav.ai/v1/images/generations takes the same JSON as OpenAI's images API. Coming from OpenAI, change two things: the base URL (https://api.stav.ai/v1) and the key. The OpenAI SDKs' images.generate() work as they are.
Request
| Field | Type | Notes |
|---|---|---|
model | string | Required. A model listed with the images surface on GET /v1/models. auto and Routers do not apply. |
prompt | string | Required. At most 32,000 characters. |
n | integer | How many images, 1 to 4. Default 1. |
size | string | WIDTHxHEIGHT in pixels (1024x1024) or auto. The sizes a model is priced for are in stav_image_options on GET /v1/models/{model_id}. A size the model does not make is the provider's own 400, passed on. |
quality | string | The provider's quality word (low, medium, high, standard, hd, …). |
output_format | string | png, jpeg or webp, where the model takes it. |
background, seed | Passed to the provider as sent. | |
response_format | string | Only b64_json. url is refused with 400 unsupported_parameter: Stav always answers with the image itself. |
user | string | Accepted and never forwarded. |
provider | object | Narrows where this request may run — see region per request. |
Any other field, and stream, is refused by name with 400 unsupported_parameter. Nothing is dropped silently. Image edits are on /v1/images/edits; there are no image variations in this version.
Response
{
"created": 1794000000,
"data": [{"b64_json": "iVBORw0KGgo…"}],
"usage": {"images": 1, "megapixels": 1.048576, "input_tokens": 12, "output_tokens": 4160, "cost": 0.4100, "cost_currency": "NOK"}
}
Always base64. When a provider answers with a link on its own host, Stav fetches the image and puts the bytes in b64_json, so you never fetch from the provider and no link expires on you. Stav stores no image. Each image is checked to be a PNG, JPEG or WebP; an answer with the wrong count or a broken image is never returned in part — the next Provider Endpoint is tried, else 502 upstream_invalid_answer.
usage.images is the count that came back and usage.megapixels their measured size. input_tokens / output_tokens appear when the provider reports them. usage.cost is what your wallet is charged, in your workspace's currency, from Stav's own ledger — never the provider's own figure; it is absent when your workspace's own provider key (BYOK) served the call. The usual response headers come with it, with X-Stav-Cost.
Billing
One unit per request, the one the serving Provider Endpoint is priced in, in this order:
- Per image — flat, or by size and quality where the provider prices it so. The price is known before the image is made, so a balance below it is
402before anything is sent. A size or quality the endpoint has no price for is400 image_size_not_priced, naming what is priced. - Per megapixel — the measured pixels of the image that came back. We bill what the provider bills: a larger image than you asked for is billed as returned.
- Tokens — the text and image tokens the provider reports. A token-priced endpoint whose provider reports no counts is not callable.
- Per request.
A model priced in any other unit (per step, per tile) is shown in the catalogue and not callable yet. A failed request, and a content refusal, is not charged. See Credits and billing.
How it differs from chat
- Name the model.
autoand Routers serve the chat surfaces only. - Which models qualify. A model is callable here when a Provider Endpoint of it has been proven to make an image — Stav asks each endpoint for one small image and records the answer — and can be billed in its own unit. A chat model that also makes images is listed under both.
- The same policy wall. Compute country, zero data retention, no-training, the sovereignty floor and blocked providers apply exactly as on chat; the refusal says why.
- Content. Stav adds no filter of its own. When a provider refuses a prompt under its content policy, you get
400 content_policy_violationwith the provider's reason; Stav does not try another provider. - Your key needs the
inference:imagesscope. Without it:403 insufficient_scope. A key with no scopes has full access. - Your data. The prompt and the image are not kept in the request log, which records the count, megapixels, size and quality. Inside a capture window you opened, the request JSON is kept like a chat prompt, and the answer with each image replaced by its size and format — never the image.
Errors
| Status | When |
|---|---|
400 unsupported_parameter | An unknown field, stream, or response_format: "url"; or a field the model's Inference Provider has no place for (Gemini image models take no quality) — param names it |
400 invalid_value | A required field missing, n out of range, a malformed size — param names it |
400 image_size_not_priced | The endpoint prices by size or quality and yours has no price; the message names what is priced |
400 n_not_supported | n is above 1 and the model makes one image per request; stav_image_options.max_n on /v1/models says so in advance |
400 content_policy_violation | The provider refused the prompt; the message is its reason |
400 router_not_supported | model was auto or a Router |
402 | Not enough credits for the known price, or a spend limit was reached |
403 insufficient_scope | The key lacks inference:images |
404 images_not_enabled | Image generation is not enabled on this deployment |
404 model_not_found | The model is not an image model, or has no Provider Endpoint on this surface priced in a unit Stav can measure |
501 images_not_supported | The model's Inference Provider has no /images/generations door |
502 upstream_invalid_answer | No Provider Endpoint answered with exactly n readable images |
Full catalogue: Errors.
On the model page
An image model's page has a Try model button: a prompt, the sizes and qualities the model is priced for, the price before Run where the unit allows it, the image with Download, the receipt with the cost, and Get code for the call you just ran.
Svarheadere
| Header | Betydning |
|---|---|
X-Stav-Request-Id | Unique request identifier, identical to the completion |
X-Stav-Model | The model that actually served the request — not necessarily the one you asked for, when routing or failover intervened. |
X-Stav-Provider | The provider that served the request. |
X-Stav-Sovereignty-Level | The sovereignty level of the serving Provider Endpoint. |
X-Stav-Compute-Region | Where the serving Provider Endpoint computes, as a region. Always
sent. |
X-Stav-Compute-Countries | Every country the prompt may have been processed in, comma-separated ISO 3166-1 alpha-2, when known. |
X-Stav-Cost | The charge for this request in the workspace currency ( |
X-RateLimit-Limit | Per-minute request cap on this key. |
X-RateLimit-Remaining | Requests remaining in the current window. |
X-RateLimit-Reset | Unix timestamp (seconds) when the current window rolls over. |
Feil
| Status | Når |
|---|---|
| 400 |
|
| 401 | Missing or invalid API key. |
| 402 | The wallet or a spend limit refused the request. |
| 403 | API key lacks the required scope (e.g., |
| 404 |
|
| 429 | Per-key or per-IP rate limit exceeded. |
| 501 |
|
| 502 |
|
Alle feilkoder, hva de betyr og hva du gjør: Feil.