Edit an image from a prompt
https://api.stav.ai/v1/images/editsEdits one input image from a text prompt, with an optional mask, and
returns the result as base64. The request and answer shape are
OpenAI's (client.images.edit): change only the base URL
(https://api.stav.ai/v1) and the key. Scope inference:images.
Name a model listed with the image_edits 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". One input image per request. A mask goes
only to a Provider Endpoint that takes one (mask_not_supported
otherwise). Each file is at most 50 MB, or the Provider Endpoint's
own smaller limit (413 upload_too_large).
Billing: callable only when the whole edit is priced — per image
with an edit price, or the text input, image input and image output
tokens the provider reports. usage.cost is the charge in the
workspace currency, from Stav's own ledger (absent when the
workspace's own key served the call). No image 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åkrevdA model listed with the
image_editssurface onGET /v1/models.imagestring (binary)påkrevdOne PNG, JPEG or WebP image, judged by its content, not its file name. At most 16,384 pixels on a side, and at most
stav_image_options.edits.max_upload_mb(50 MB unless the model takes less). Oneimage[]part counts asimage; a second image is refused.promptstringpåkrevdWhat to change.
maskstring (binary)Optional. One PNG with an alpha channel, the same width and height as
image: the transparent pixels mark what to edit. Only on a model whosestav_image_options.edits.maskis true; otherwise400 mask_not_supported.nintegerHow many images. A model that makes one image per edit refuses more with
400 n_not_supported;stav_image_options.edits.max_nsays so in advance.sizestringWIDTHxHEIGHT in pixels, or
auto.qualitystringThe provider's quality word.
output_formatenumpngjpegwebpbackgroundstringPassed to the provider as sent.
input_fidelitystringPassed to the provider as sent. Gemini image models take none (
400 unsupported_parameter).response_formatenumOnly
b64_json;urlis refused.b64_jsonuserstringAccepted and never forwarded.
providerstringStav extension, region per request: a JSON object in one form field, e.g.
{"runs_in":"eu"}. Same fields asRequestProviderFilter; never forwarded to the provider.
Merknader
POST https://api.stav.ai/v1/images/edits takes the same multipart/form-data request as OpenAI's image edits API: one input image, a prompt and, where the model takes one, a mask. Coming from OpenAI, change two things: the base URL (https://api.stav.ai/v1) and the key. The OpenAI SDKs' images.edit() work as they are.
Request
| Field | Type | Notes |
|---|---|---|
model | string | Required. A model listed with the image_edits surface on GET /v1/models. auto and Routers do not apply. |
image | file | Required. One PNG, JPEG or WebP image, judged by its content, not its file name. At most 16,384 pixels on a side, and within the upload limit below. One image[] part (how the OpenAI SDK names a list of one) is the image; a second image is refused. |
prompt | string | Required. What to change. At most 32,000 characters. |
mask | file | Optional. A PNG with an alpha channel, the same width and height as image. The transparent pixels mark what to edit. Only on models whose stav_image_options.edits.mask is true. |
n | integer | How many images, 1 to 4. Default 1. |
size | string | WIDTHxHEIGHT in pixels (1024x1024) or auto. The sizes a model's edits are priced for are in stav_image_options.edits. |
quality | string | The provider's quality word (low, medium, high, …). |
output_format | string | png, jpeg or webp, where the model takes it. |
background, input_fidelity | string | 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 | string | Stav extension: narrows where this request may run, as a JSON object in one form field, e.g. {"runs_in":"eu"} — see region per request. The X-Stav-Runs-In header works too. |
Any other field (seed, style, moderation, partial_images, output_compression, …), and stream, is refused by name with 400 unsupported_parameter. Nothing is dropped silently. A field sent twice, a file in a text field, or a body that is not multipart/form-data is 400 invalid_value. In curl, send the prompt with --form-string, not -F: -F reads a value that starts with @ or < as a file name.
Upload limits
- The deployment's limit: 50 MB per file (
imageormask) by default. Over it:413 upload_too_large, naming the field and the limit. - The Provider Endpoint's own limit, where the provider states a smaller one. Gemini image models take at most 14 MB. A file goes to an endpoint it fits; when none fits,
413 upload_too_largenames the limit. stav_image_options.edits.max_upload_mbonGET /v1/models/{model_id}is the largest file a model takes.- A body over 64 MB is stopped by the proxy before it reaches the gateway, with a plain
413page instead of a JSON error.
Masks
A mask tells the model which pixels to change: transparent where to edit, opaque where to keep. It must be one PNG with an alpha channel and exactly the size of image; anything else is 400 invalid_mask. Only some models take a mask — Gemini image models edit by prompt only. A mask sent to a model with no Provider Endpoint that takes one is 400 mask_not_supported before anything is sent or charged; Stav never drops the mask and edits without it. stav_image_options.edits.mask says which in advance.
Response
{
"created": 1794000000,
"data": [{"b64_json": "iVBORw0KGgo…"}],
"usage": {"images": 1, "megapixels": 1.048576, "input_images": 1, "input_tokens": 1290, "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. 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; usage.input_images is always 1. 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; 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
An edit sends an image in as well as making one, and providers price that input differently. A Provider Endpoint is callable on edits only when the whole edit is priced, so Stav never bills an estimate:
- Per image — only where the endpoint has an edit price (by size and quality, or flat). 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 edit price for is400 image_size_not_priced, naming what is priced. - Tokens — the text input, image input and image output tokens the provider reports, each at its catalogue price. An endpoint is callable only when all three are priced and the provider reports the image input count.
An endpoint priced per megapixel or per request, or per image with no edit price, is not callable on edits. A refused or failed edit, and a content refusal, is not charged. See Credits and billing.
How it differs from generation
- Which models qualify. A model is callable here when a Provider Endpoint of it has been proven to edit an image — Stav sends each endpoint one small image and records the answer, and whether it takes a mask — and its edit is priced as above.
- Name the model.
autoand Routers serve the chat surfaces only. - 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. The image goes only to the Provider Endpoint that serves the request.
- Content. Stav adds no filter of its own. When a provider refuses 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 — the same scope as generation. Without it:403 insufficient_scope. A key with no scopes has full access. - Your data. The input image, the mask and the result are never stored. The request log records counts, sizes, megapixels, the quality and whether a mask was sent — never an image or the prompt. Inside a capture window you opened, the form fields are kept like a chat prompt, and the input image, the mask and each result are replaced by their size and format.
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, output_format, background or input_fidelity) — param names it |
400 invalid_value | A required field missing, n out of range, a malformed size, a second image, a field sent twice, or a body that is not multipart — param names it |
400 invalid_image | image is not a PNG, JPEG or WebP, or a side is over 16,384 pixels |
400 invalid_mask | mask is not one PNG with an alpha channel the same size as image |
400 mask_not_supported | You sent a mask and no Provider Endpoint of the model takes one |
400 image_size_not_priced | The endpoint prices edits 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 edit; stav_image_options.edits.max_n says so in advance |
400 content_policy_violation | The provider refused; 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 image_edits_not_enabled | Image editing is not enabled on this deployment |
404 model_not_found | The model does not edit images, or has no Provider Endpoint whose edit is priced in a unit Stav can measure |
413 upload_too_large | image or mask is over the deployment's or the Provider Endpoint's upload limit; the message names it |
501 image_edits_not_supported | The model's Inference Provider has no edits door |
502 upstream_invalid_answer | No Provider Endpoint answered with exactly n readable images, or a token-priced endpoint reported no image input count |
Full catalogue: Errors.
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 image 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 |
|
| 413 |
|
| 429 | Per-key or per-IP rate limit exceeded. |
| 501 |
|
| 502 |
|
Alle feilkoder, hva de betyr og hva du gjør: Feil.