Skip to content
OpenRelay is in early access, and the /v1 API is stable. New capabilities ship in the changelog.
Skip to Content
GuidesInference APIs

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/edits

Edit 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.jpg

Send 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 idModelAPI families
openrelay/flux.1-kontextFLUX.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:

FieldDescription
sizesEvery output size the model makes, as WxH in pixels.
maxNThe most images one request may ask for (n).
maxInputImagesThe most input images one edit may carry.
maxPromptCharsThe longest prompt, in characters.

openrelay/flux.1-kontext at preview:

LimitValue
PriceFree during the preview: every request bills $0. See Billing.
SizesThe 17 sizes in Sizes, all close to 1 megapixel
Images per request (n)1 to 4
Input images per edit1
Prompt1,500 characters
Each input imagePNG, 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:

FieldTypeDescription
modelstring (required)openrelay/flux.1-kontext.
promptstring (required)The edit to make, up to the model's maxPromptChars.
imagefile (multipart)The input image. Send one part named image, or one part named image[] per image.
imagesarray (JSON, required)The input images as [{ "image_url": "data:image/png;base64,..." }].
nintegerImages to return, 1 to the model's maxN. Default 1.
sizestringauto, 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_formatstringpng (default), jpeg or webp.
output_compressioninteger0 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.
seedinteger0 to 4294967295. The seed of the first image; image i uses seed + i. The server picks one when absent.
response_formatstringb64_json only.
backgroundstringauto or opaque.
input_fidelity, quality, moderationstringAccepted and ignored.
user, safety_identifierstringAccepted, not forwarded and not stored.
streambooleanfalse or absent.
partial_imagesinteger0 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:

  1. 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.
  2. The size is the listed WxH whose 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 ratioSizePixelsBilled blocks
1:11024x10241,048,5764,096
5:4, 4:51104x944, 944x11041,042,1764,071
4:3, 3:41184x880, 880x11841,041,9204,070
3:2, 2:31248x832, 832x12481,038,3364,056
16:9, 9:161392x752, 752x13921,046,7844,089
2:1, 1:21456x720, 720x14561,048,3204,095
21:9, 9:211568x672, 672x15681,053,6964,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" }
}
FieldDescription
data[i].b64_jsonImage i, base64 encoded in output_format.
data[i].seedThe 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_formatThe encoding of every image.
sizeThe size every image was made at.
usage.imagesImages delivered.
usage.pixelsWidth times height, summed over the images delivered. The request is billed on these pixels.
openrelay.cost_nano_usdWhat 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):

StepValue
One image at 1024x10241,048,576 pixels
Blocks1,048,576 / 256 = 4,096
Price4,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

LimitValue
Request body16 MiB (413 payload_too_large over it)
Each input image10 MiB, and the model's input pixel limit decoded (image_too_large over either)
Images per requestThe model's maxN (invalid_n outside it)
PromptThe model's maxPromptChars (prompt_too_long over it)
Megapixels per minuteYour 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_violation and is not billed. When an output is refused, no image of the request is returned, the others included, so a request with n above 1 can be sent again with n 1 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].

StatuscodeWhen
400invalid_sizesize is not on the model's list. The message lists the sizes.
400invalid_nn 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.
400prompt_too_longThe prompt is over the model's maxPromptChars.
400unsupported_valueA 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.
400invalid_imageAn input is not a PNG, JPEG or WebP image that decodes.
400image_too_largeAn input is over 10 MiB, or over the model's input pixel limit.
400too_many_imagesAn edit has more input images than the model's maxInputImages, or none.
400content_policy_violationThe content checks refused the prompt, an input or an output. See Safety.
400unknown_fieldA field this API does not define.
400unsupported_apiThe model does not serve this endpoint.
402insufficient_balanceThe balance does not cover the request.
404model_not_foundNo model with this id is available to your organization.
413payload_too_largeThe body is over 16 MiB.
429rate_limit_errorOver the megapixels per minute or request rate limit, or the model is at capacity. Wait Retry-After seconds.
502upstream_errorThe 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.
503upstream_unavailableNo 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.
503image_uploads_busyThe API is handling as many image edits as it can. Nothing started and nothing is billed; wait Retry-After seconds.
503image_responses_busyThe 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.

On this page