Platform notice: all DeepSeek models are now live. New users receive trial credits on sign-up.
Api reference

Image generation and editing

OpenAI-compatible text-to-image, image edit, and image variation endpoints, callable with API Keys.

Generation, editing, and variations all use Authorization: Bearer sk-tp-... and share the same Key authentication, rate limiting, and billing pipeline as chat completions.

Image generation

POST /api/v1/images/generations
  • Auth: Authorization: Bearer sk-tp-...
  • Content-Type: application/json

Request body

ParameterTypeRequiredDescription
modelstringYesPlatform image model name, see Models
promptstringYesImage description prompt
nnumberNoNumber of images, defaults to 1
sizestringNoImage size, e.g. 1024x1024; allowed values depend on the model
response_formatstringNourl (default) or b64_json
Other params-NoPassed through per the OpenAI protocol and model support

Response

OpenAI Images JSON: a data array where each item contains url or b64_json. The url is provided by the upstream provider and is usually valid for 24 hours; download and store it promptly.

curl https://api.openruler.ai/api/v1/images/generations \
  -H "Authorization: Bearer sk-tp-..." \
  -H "Content-Type: application/json" \
  -d '{"model":"flux-dev","prompt":"Sunset by the sea, film grain","n":1}'

Image edits

POST /api/v1/images/edits
  • Auth: Authorization: Bearer sk-tp-...
  • Content-Type: multipart/form-data
FieldTypeRequiredDescription
imagefileYesSource image; repeat the image field to send multiple images, support depends on the model
maskfileNoMask image; transparent areas are edited
modelstringYesPlatform image model name
promptstringYesEdit description
nnumberNoNumber of images, defaults to 1
sizestringNoOutput size
response_formatstringNourl (default) or b64_json
curl https://api.openruler.ai/api/v1/images/edits \
  -H "Authorization: Bearer sk-tp-..." \
  -F "model=flux-dev" \
  -F "prompt=Replace the background with snowy mountains" \
  -F "image=@./input.png"

Image variations

POST /api/v1/images/variations
  • Content-Type: multipart/form-data
  • image is required (single file); model, n, size, and response_format are optional
  • Response and billing match image generation
curl https://api.openruler.ai/api/v1/images/variations \
  -H "Authorization: Bearer sk-tp-..." \
  -F "model=flux-dev" \
  -F "n=2" \
  -F "image=@./input.png"

Direct reference-image upload (optional)

Get a presigned URL, upload the file straight to object storage, then use the returned url as a request parameter.

POST /api/v1/uploads/presign
  • Auth: Authorization: Bearer sk-tp-...
  • Content-Type: application/json
  • Body: { "filename": "ref.png", "size": 102400 } (PNG/JPG/WEBP/GIF only, max 10MB)
  • Response: { key, url, uploadUrl, headers, expiresIn }

Send the file with PUT to uploadUrl and include the Content-Type from headers; then use url.

Billing

  • Generation, edits, and variations are billed per returned image at "yuan per image"; the model must use per-call pricing.
  • Responses include X-Cost-Yuan (cost) and X-Bill-Units (image count) headers.

Pre-checks

  1. Key valid and not revoked (including all parents), account active → otherwise 401
  2. Model exists and is live (LIVE), priced per call with a unit price → otherwise 400
  3. Edit/variation request missing an image file → otherwise 400
  4. Balance above zero and Key chain quota not exhausted → otherwise 402

Errors

For error format and troubleshooting see FAQ · Error codes. Upstream errors are passed through unchanged; if the model or channel does not support edits/variations, the upstream error is returned to the caller.

On this page

OpenRuler