Skip to content

Get started

How the API works ​

Generation is asynchronous: a launch returns an id at once, the result comes later. Video takes minutes, an image is usually faster.

text
GET /models ──► POST /estimate ──► POST /generations ──► GET /generations/{id} … ──► done / failed
 (what exists)   (price, free)       (charge, 202)           (polling)                  (outputs / refund)

Steps ​

  1. Model. GET /models returns the models open in the API with the lowest price and capabilities. A model switched off right now stays in the list with available: false, a reason and alternatives.
  2. Price. POST /estimate with the same body as the launch. Answer: credits, cost_usd (REST), applied (parameters the price was calculated for) and exceeds_daily_limit.
  3. Launch. POST /generations with Idempotency-Key. Money is charged when the launch is accepted. Answer 202 with the generation.
  4. Polling. GET /generations/{id} until status is done or failed.
  5. Result. On done · outputs: file link, kind, MIME, preview and thumbnail. On failed · error with a code and retryable; the price is refunded.

Strict request body ​

The API never adjusts anything silently:

  • an unknown field or a wrong type · 422 invalid_parameters;
  • a known field that does not apply to the type or model (duration for music, upscale_factor on a model without upscaling) · 422 unsupported_input;
  • in both cases error.details.param names the field.

Each type takes only its own fields:

TypeFields besides type, model, prompt, max_credits
imageaspect, resolution, upscale_factor, reference_ids, mask_target, negative, seed
videoaspect, resolution, duration, sound, upscale_factor, video_mode, reference_ids, negative, seed
musicmode, instrumental, style, title, vocal_gender
voicevoice_id, speed
3dreference_ids, seed

Money ​

  • Paid from the API balance in dollars: the price in credits as on the site, without plan discounts and promos, times the API credit price.
  • max_credits in a request is your cap: a more expensive run is refused and nothing is charged.
  • A failed generation is fully refunded (refunded: true). When the model delivers fewer results than ordered, the difference is refunded (partial_refund).

See Billing and storage.

Response format ​

Success · the object in data, lists also have meta:

json
{ "data": { "id": 123, "status": "running", "cost_credits": 8 } }

Error · always an error object:

json
{
  "error": {
    "code": "max_credits_exceeded",
    "message": "The price 12 is above your max_credits 10. Nothing was charged.",
    "retryable": false,
    "details": { "price": 12, "max_credits": 10 }
  }
}

Values of your input are never echoed in errors. The codes are in Errors and retries.