CloseRouter

Images reference

Price checks, file limits, statuses and result delivery.

Estimate the reservation

Use the model, operation, provider_option_id and input_schema fields from GET /media/models. This illustrates the structure, not a universal operation schema.

curl
curl https://api.closerouter.dev/v1/media/quote \
  -H "Authorization: Bearer $CLOSEROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "YOUR_IMAGE_MODEL_ID",
  "operation": "YOUR_OPERATION",
  "input": {
    "prompt": "A minimal product photo"
  },
  "provider": {
    "option_id": "YOUR_PROVIDER_OPTION_ID"
  }
}'

Choose an operation and estimate

GET /media/models returns enabled operations, input_schema, source field names, provider_option_id, and our rates with their units and conditions.

POST /media/quote accepts model, operation, input, and provider.option_id. It does not run a model or debit funds. reserved_usd is the maximum reserve; pending means the final amount is uncertain.

Send the same fields to the endpoint from the metadata and set max_cost_usd to the quoted reserved_usd. A higher required reserve returns 409 before dispatch.

Inputs and reservation

For multipart, send input as a JSON string and files under their input_image_fields names; repeat a name with [] for arrays. Each file is limited to 20 MB (20,000,000 bytes), with at most 16 sources; the operation schema may impose a lower limit. JSON requests are limited to 20 MiB total, so use multipart for larger inputs.

Public HTTPS sources are downloaded and validated before dispatch. Previous results are available only to their owner. Operations that do not require prompt can be sent without text.

Reservation applies only to these image operations. The charge is settled after all results are stored with us, and the unused reserve is released. The total includes every applicable item, including extra inputs.

Receive the result

For asynchronous generation routes, POST /images/generations waits up to 120 seconds from receipt for a completed image. HTTP 200 contains URL or b64_json and usage.cost_usd. Cancellation or expiry before atomic settlement prevents a later customer debit; accepted source submissions are never replayed automatically.

For other paths and previously accepted jobs, a 202 response with object=image.request means delivery is still pending. Read GET /media/requests/{id}; another POST creates a new generation. outcome_unknown is never retried automatically. Results that cannot be delivered are not charged to the customer.

Outputs preserve order and layer/mask labels. Operations allow up to 64 MiB per output file and 256 MiB in total. URLs identify our resources only; response_format=b64_json returns the stored bytes.

Image parameters

GPT Image and Gemini image both use /images/generations and /images/edits. Gemini image models are not available on /chat/completions.

n, size, quality, style, background, moderation, output_compression and output_format are accepted on every image route and translated into the operation schema. size sets the aspect ratio only and is written solely to a field that prices nothing, so it cannot raise the reservation.

Pass operation-specific values directly or inside input; they take precedence. Gemini Pro and Flash Preview take input.resolution 1K, 2K or 4K; google/gemini-3.1-flash-lite-image supports 1K only.

Input validation

A value outside the ones an operation declares falls back to its default, except on a control the operation prices or requires, which is refused with the supported values. A field that is in neither the schema nor the list above is refused too, and the error metadata names the field and the accepted ones.

For edits, use multipart image[] uploads or JSON images as inline data: URLs.

For ordinary inference inputs, send files as data URLs or multipart uploads. The image operations described below also accept public HTTPS URLs and links to your previous results.

Delivery and retention

CloseRouter rehosts externally linked image results before responding. The returned URL is controlled by CloseRouter and never redirects to a provider.

That URL is available for exactly 30 days from creation and is unavailable at expiry.

Ordinary image routes keep b64_json inline. New image operations store the result first and can then return its bytes as b64_json.

File limits

DataLimit
MultipartUp to 16 inputs, each at most 20,000,000 bytes. The schema may impose a lower limit.
JSON20 MiB; use multipart for larger inputs.
Output64 MiB per file, 256 MiB total.
LinkAvailable for 30 days.

Check an unfinished task

For a 202 response with object: image.request, use the returned ID. Do not automatically repeat POST on outcome_unknown: it may create a new generation.

curl
curl https://api.closerouter.dev/v1/media/requests/REQUEST_ID \
  -H "Authorization: Bearer $CLOSEROUTER_API_KEY"