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
- Model.
GET /modelsreturns the models open in the API with the lowest price andcapabilities. A model switched off right now stays in the list withavailable: false, a reason and alternatives. - Price.
POST /estimatewith the same body as the launch. Answer:credits,cost_usd(REST),applied(parameters the price was calculated for) andexceeds_daily_limit. - Launch.
POST /generationswithIdempotency-Key. Money is charged when the launch is accepted. Answer202with the generation. - Polling.
GET /generations/{id}untilstatusisdoneorfailed. - Result. On
done·outputs: file link, kind, MIME, preview and thumbnail. Onfailed·errorwith a code andretryable; 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 (
durationfor music,upscale_factoron a model without upscaling) · 422unsupported_input; - in both cases
error.details.paramnames the field.
Each type takes only its own fields:
| Type | Fields besides type, model, prompt, max_credits |
|---|---|
image | aspect, resolution, upscale_factor, reference_ids, mask_target, negative, seed |
video | aspect, resolution, duration, sound, upscale_factor, video_mode, reference_ids, negative, seed |
music | mode, instrumental, style, title, vocal_gender |
voice | voice_id, speed |
3d | reference_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_creditsin 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.