Images
Edit an image from a text instruction with POST /v1/images/edits in the OpenAI Images shape, returned as base64 and billed per megapixel of output.
Preview
The Images API is in preview for selected organizations. To ask for access, contact us. FLUX.1 Kontext [dev] is free during the preview: its requests bill $0, and each one still counts against your organization's megapixels per minute.
Edit an image from a text instruction in the OpenAI Images shape. The OpenAI
SDKs' images.edit works against this endpoint. Every image comes back inline
as base64, and a request is billed on the pixels it delivers.
POST https://inference.openrelay.inc/v1/images/editsEdit your first image
Send a photo and say what to change. Each example writes the edited image to
bike-blue.jpg.
curl https://inference.openrelay.inc/v1/images/edits \
-H "Authorization: Bearer $OPENRELAY_API_KEY" \
--form-string 'model=openrelay/flux.1-kontext' \
--form-string 'prompt=Make the bicycle blue' \
--form-string 'size=auto' \
--form-string 'output_format=jpeg' \
--form-string 'output_compression=85' \
--form-string 'seed=7' \
-F 'image=@bike.jpg' \
| jq -r '.data[0].b64_json' | base64 --decode > bike-blue.jpgSend every text field with --form-string: with -F, a ; cuts the value
short and a leading @ or < reads a file instead.
The OpenAI SDKs send a single file as one image part. seed is not an
OpenAI field, so it goes in extra_body in Python and past the type check in
TypeScript; both SDKs send it as a form field. The full request and response
schemas are in the API reference: Edit an image.
Prompting
The model changes what the prompt names and tries to keep the rest of the image as it is. Prompts that work:
- Say what to change, specifically: "change the car to red", not "make it better".
- Say what to keep: "keep the person's face, pose and the background unchanged".
- Quote text to replace, exactly as it appears:
replace "OPEN" with "CLOSED". - Edit in steps: make one change per request, then send the result back as the next input for the next change.
Change the bicycle's frame to matte blue. Keep the rider, the street and the
lighting exactly as they are.Black Forest Labs' Kontext image editing guide has more examples.
Models
| Model id | Model | API families |
|---|---|---|
openrelay/flux.1-kontext | FLUX.1 Kontext [dev] by Black Forest Labs: edits an input image as a text instruction asks, keeping the rest of the scene. | images_edits |
Check a model's supported_apis on GET /v1/models
for images_edits.
An image model on GET /v1/models carries an images object with what one
request may ask for. It is the authority for a model's sizes and limits:
| Field | Description |
|---|---|
sizes | Every output size the model makes, as WxH in pixels. |
maxN | The most images one request may ask for (n). |
maxInputImages | The most input images one edit may carry. |
maxPromptChars | The longest prompt, in characters. |
openrelay/flux.1-kontext at preview:
| Limit | Value |
|---|---|
| Price | Free during the preview: every request bills $0. See Billing. |
| Sizes | The 17 sizes in Sizes, all close to 1 megapixel |
Images per request (n) | 1 to 4 |
| Input images per edit | 1 |
| Prompt | 1,500 characters |
| Each input image | PNG, JPEG or WebP, at most 10 MiB and 16,777,216 pixels (4096x4096) decoded |
Each image runs a fixed number of denoising steps at a fixed guidance scale. A request cannot change either, so its price is known before it runs.
Edit an image
POST /v1/images/edits takes multipart/form-data, with the image as a file
part (what the OpenAI SDKs send), or application/json, with the image as a
base64 data URL. The fields are the same in both forms:
| Field | Type | Description |
|---|---|---|
model | string (required) | openrelay/flux.1-kontext. |
prompt | string (required) | The edit to make, up to the model's maxPromptChars. |
image | file (multipart) | The input image. Send one part named image, or one part named image[] per image. |
images | array (JSON, required) | The input images as [{ "image_url": "data:image/png;base64,..." }]. |
n | integer | Images to return, 1 to the model's maxN. Default 1. |
size | string | auto, or one of the model's sizes. auto and no size take the listed size nearest the input image's aspect ratio. See Sizes. |
output_format | string | png (default), jpeg or webp. |
output_compression | integer | 0 to 100, for jpeg and webp; ignored for png. As in the OpenAI API, 100 (the default) keeps the most detail and lower values make smaller files. |
seed | integer | 0 to 4294967295. The seed of the first image; image i uses seed + i. The server picks one when absent. |
response_format | string | b64_json only. |
background | string | auto or opaque. |
input_fidelity, quality, moderation | string | Accepted and ignored. |
user, safety_identifier | string | Accepted, not forwarded and not stored. |
stream | boolean | false or absent. |
partial_images | integer | 0 or absent. |
An input image must be the image itself: a URL to fetch, a file id and a mask
are refused with unsupported_value. Any field the table does not list,
such as num_inference_steps, guidance_scale or negative_prompt, is
refused with unknown_field.
Sizes
Sizes are a closed list per model. A size that is not on the model's list is
refused with invalid_size, never resized to a near size, so the size you are
billed for is the size you asked for.
openrelay/flux.1-kontext makes the sizes FLUX.1 Kontext is tuned at, all on
a 16-pixel grid:
672x1568, 688x1504, 720x1456, 752x1392, 800x1328, 832x1248,
880x1184, 944x1104, 1024x1024, 1104x944, 1184x880, 1248x832,
1328x800, 1392x752, 1456x720, 1504x688, 1568x672.
size: auto matches the input
size auto, or no size, returns the listed size whose aspect ratio is
nearest the input image's, so a portrait photo comes back portrait:
- The width and height are read from the image's header, after its EXIF orientation is applied. Orientations 5 to 8 swap them: a phone photo stored 4032x3024 with orientation 6 is a 3024x4032 portrait.
- The size is the listed
WxHwhose ratio is closest to the input's, compared exactly. On a tie, the narrower size wins.
The phone photo above has a ratio of 3:4 and resolves to 880x1184. The
response's size names the size the request resolved to.
The billed blocks column is what one image is metered in (see Billing).
| Input aspect ratio | Size | Pixels | Billed blocks |
|---|---|---|---|
| 1:1 | 1024x1024 | 1,048,576 | 4,096 |
| 5:4, 4:5 | 1104x944, 944x1104 | 1,042,176 | 4,071 |
| 4:3, 3:4 | 1184x880, 880x1184 | 1,041,920 | 4,070 |
| 3:2, 2:3 | 1248x832, 832x1248 | 1,038,336 | 4,056 |
| 16:9, 9:16 | 1392x752, 752x1392 | 1,046,784 | 4,089 |
| 2:1, 1:2 | 1456x720, 720x1456 | 1,048,320 | 4,095 |
| 21:9, 9:21 | 1568x672, 672x1568 | 1,053,696 | 4,116 |
The input is scaled to the output size without cropping. With size auto
the stretch is only the gap between the input's ratio and the nearest listed
one; with an explicit size of another shape, the input is stretched to it, so
crop the image yourself first if you want a different framing.
Response
{
"created": 1764000000,
"data": [{ "b64_json": "iVBORw0KGgo...", "seed": 7 }],
"output_format": "png",
"size": "1024x1024",
"usage": { "images": 1, "pixels": 1048576 },
"openrelay": { "cost_nano_usd": 0, "priced_at": "online" }
}| Field | Description |
|---|---|
data[i].b64_json | Image i, base64 encoded in output_format. |
data[i].seed | The seed image i was made from: the request's seed plus i, wrapping past 4294967295 to 0, or the seed the server picked. Send it back as seed with n 1 to make the same image again. |
output_format | The encoding of every image. |
size | The size every image was made at. |
usage.images | Images delivered. |
usage.pixels | Width times height, summed over the images delivered. The request is billed on these pixels. |
openrelay.cost_nano_usd | What the request is billed, in nanoUSD, also sent as the OpenRelay-Cost-Nano-USD header: 0 for a free model, as in the example. See Cost on every response. |
usage has no token counts. A request returns all n images or an error,
never fewer: if one image fails, the whole request fails and nothing is billed.
Images are returned inline only; there is no url output. Requests are
answered on the open connection: images do not stream, and the
Batch API and Async API do not
take them.
Billing
An image model has one price, in USD per megapixel (1,000,000 pixels) of
output. Input images are not billed. The output is metered in 16x16-pixel
blocks, usage.pixels / 256, so you pay for the exact area delivered, not a
whole number of megapixels. Every listed size is a whole number of blocks.
openrelay/flux.1-kontext is free during the preview: its price reads 0 on
the API, every request bills $0 (openrelay.cost_nano_usd is 0), and each
request still counts against your organization's
megapixels per minute.
Read a model's price from images.perMegapixel on
GET /v1/models for a model served only to your
organization, or from the image list of
GET /v1/public/pricing for a public one.
A worked example for a priced model, at an example rate of $0.01 per megapixel (10,000,000 nanoUSD per megapixel, which is 2,560 nanoUSD per block):
| Step | Value |
|---|---|
One image at 1024x1024 | 1,048,576 pixels |
| Blocks | 1,048,576 / 256 = 4,096 |
| Price | 4,096 x 2,560 = 10,485,760 nanoUSD, $0.01048576 |
n: 2 at the same size bills 8,192 blocks, 20,971,520 nanoUSD. A model's
price can differ from this example: read it from the API as above.
Before a request runs, your available balance must cover its price and stay
at or above the spending floor, a
free request included; below that, the answer is 402 insufficient_balance.
A request that fails or is refused, a content check refusal
included, bills nothing.
Limits
| Limit | Value |
|---|---|
| Request body | 16 MiB (413 payload_too_large over it) |
| Each input image | 10 MiB, and the model's input pixel limit decoded (image_too_large over either) |
| Images per request | The model's maxN (invalid_n outside it) |
| Prompt | The model's maxPromptChars (prompt_too_long over it) |
| Megapixels per minute | Your organization's image rate limit, on Organization > Limits in the dashboard |
The rate limit counts the megapixels each request asks for, n times its size,
when it is admitted. Over it, or over your request rate limit, the answer is
429 rate_limit_error with a Retry-After header in seconds.
Safety
The policy is no sexual content. The prompt, every input image and every output
image pass content checks, and a request cannot turn them off or tune them:
moderation is ignored.
- A refused request answers
400 content_policy_violationand is not billed. When an output is refused, no image of the request is returned, the others included, so a request withnabove 1 can be sent again withn1 to get the images that pass. - A refusal of the prompt or an input image comes before any image is made, and does not count against your megapixels per minute. A refusal of an output comes after the images were made, so it does count.
- Every output image carries a C2PA manifest that marks it as AI-generated.
If your product shows edited images to other people, takedown laws may apply to you: the US TAKE IT DOWN Act requires a covered platform to remove an image within 48 hours of a valid request.
Errors
Every error has the OpenAI-style body, and param
names the field when there is one, such as size or images[0].
| Status | code | When |
|---|---|---|
400 | invalid_size | size is not on the model's list. The message lists the sizes. |
400 | invalid_n | n is outside 1 to the model's maxN, or the request is more megapixels than your per-minute limit, so it can never be admitted. Ask for fewer images. |
400 | prompt_too_long | The prompt is over the model's maxPromptChars. |
400 | unsupported_value | A value this API does not serve: stream: true, partial_images, response_format: "url", background: "transparent", a mask, or an input image given as a URL or a file id. |
400 | invalid_image | An input is not a PNG, JPEG or WebP image that decodes. |
400 | image_too_large | An input is over 10 MiB, or over the model's input pixel limit. |
400 | too_many_images | An edit has more input images than the model's maxInputImages, or none. |
400 | content_policy_violation | The content checks refused the prompt, an input or an output. See Safety. |
400 | unknown_field | A field this API does not define. |
400 | unsupported_api | The model does not serve this endpoint. |
402 | insufficient_balance | The balance does not cover the request. |
404 | model_not_found | No model with this id is available to your organization. |
413 | payload_too_large | The body is over 16 MiB. |
429 | rate_limit_error | Over the megapixels per minute or request rate limit, or the model is at capacity. Wait Retry-After seconds. |
502 | upstream_error | The model failed after it started on the request. Nothing is billed, and the request is not retried for you because the model may have run: send it again. |
503 | upstream_unavailable | No server for the model can take the request now, or every server was busy and none started it. Nothing is billed; wait Retry-After seconds. |
503 | image_uploads_busy | The API is handling as many image edits as it can. Nothing started and nothing is billed; wait Retry-After seconds. |
503 | image_responses_busy | The API is holding as many image responses as it can. Nothing started and nothing is billed; wait Retry-After seconds. |
On a failed image request the response carries X-Should-Retry: false when the model may
already have run, so a retry would run it again and count against your rate limit again; true
when nothing started and a retry is safe. The OpenAI SDKs follow it.
Mobile clients
Ask for jpeg or webp with output_compression, not the default png. A
1-megapixel JPEG at output_compression 85 is about 150 to 400 KB, while the
same image as PNG can be about 3 MB, and base64 adds a third to either. Send
the input as JPEG as well: the model works at about 1 megapixel, so a
full-resolution photo spends upload time on detail the model does not use.
Decisions
POST /v1/decisions answers typed questions (choice, score, yes/no) about one input, with probabilities per question. Shapes, limits, billing, errors.
Streaming
Stream chat completions as Server-Sent Events with stream:true, the SSE format, the [DONE] sentinel, and usage and cost in the final chunk.