Jobs & async generation
Generation is asynchronous. You submit a job, get a taskId, and the API server returns immediately. The actual work happens in the background.
State machine
waiting -> queuing -> generating -> success
\ -> fail
| State | Meaning |
|---|---|
waiting | Job accepted; not yet picked up by the generation service. |
queuing | Generation service acknowledged the job; waiting for a free worker slot. |
generating | Active -- the model is running. progress (0-100) updates during this phase. |
success | Done. resultJson contains the output URLs. |
fail | Terminal failure. failCode and failMsg explain why. |
A job in a terminal state (success or fail) never changes.
Polling
Poll GET /api/v1/jobs/recordInfo?taskId=... every 5 seconds until state is success or fail. The endpoint is free to call -- it does not consume credits.
curl -s "https://nokai.studio/api/v1/jobs/recordInfo?taskId=TASK_ID" \
-H "Authorization: Bearer $NOKAI_KEY" \
| jq '{state: .data.state, progress: .data.progress}'Do not poll faster than 2 seconds. Video generation typically takes 15-120 seconds depending on model and length.
Reading the result
When state is success, parse resultJson:
const info = await getRecordInfo(taskId);
if (info.data.state === 'success') {
const result = JSON.parse(info.data.resultJson);
const url = result.resultUrls[0];
}resultJson is a JSON-encoded string (not an object) with shape { resultUrls: string[] }.
Webhooks instead of polling
Register a webhook endpoint for job.completed and job.failed events:
curl -s https://nokai.studio/v1/webhook-endpoints \
-X POST \
-H "Authorization: Bearer $NOKAI_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://yourapp.com/webhooks/kinokai",
"events": ["job.completed", "job.failed"]
}'When the job completes, the API server POSTs a signed payload to your URL. No polling needed. See Webhooks -> Payloads for the exact shape.
Credits
Credits are prepaid currency. 1 credit = $0.02, so 50 credits to the dollar (1,000,000 microdollars = $1.00).
- Credits are reserved when a job is created.
- Credits are consumed when a job reaches
success. The amount increditsConsumedon therecordInforesponse is the integer credit count. - Credits are released (not charged) if a job fails with a non-retryable error from our side.
Check your balance:
curl -s https://nokai.studio/api/v1/balance \
-H "Authorization: Bearer $NOKAI_KEY"Response: { "customerId": "...", "balanceUsdMicro": 5000000, "lowBalanceThresholdUsdMicro": 1000000 }
balanceUsdMicro / 1_000_000 = balance in USD.
Retries
A request that fails for a passing reason (the service was busy or slow, or a safety filter gave a verdict that often flips on a second look) is sent again automatically, a small number of times, before the job is reported as failed. You are billed once, on success. A job only reaches fail after those tries are spent or the error cannot be fixed by trying again.
Failure codes
When state is fail:
{
"state": "fail",
"failCode": "content_policy_violation",
"failMsg": "The request was blocked by the content safety filter. Adjust the prompt or reference media and try again.",
"failReason": "content_blocked_reference",
"failDetail": { "subject": "reference", "referenceKind": "image", "cause": "real_person" },
"failRetryable": false,
"refunded": true
}failCode is the stable machine code and failMsg its fixed sentence:
| Code | Meaning |
|---|---|
content_policy_violation | The safety filter refused the prompt, a reference or the result. |
invalid_input | A parameter or attached file is not accepted by the model. |
invalid_media | An attached file could not be read. |
source_duration_exceeds_declared | Attached audio or video is longer than duration_seconds. |
timeout | Generation took too long. |
upstream_unavailable | The generation service was unavailable. |
generation_failed | The generation failed for another reason. |
cancelled | You cancelled the job. |
failReason says the same thing for a person, and failDetail adds what is known:
failReason | What happened | failDetail |
|---|---|---|
content_blocked_prompt | The filter refused the prompt text. | cause |
content_blocked_reference | The filter refused a reference file. | referenceKind, cause |
content_blocked | The filter refused the request or withheld the result. | subject: "output" when it was the result, cause |
input_invalid | An input rule was broken. | field, minSeconds, maxSeconds |
provider_busy | The model was overloaded. | |
provider_outage | The generation service was unavailable. | |
timeout | Generation took too long. | |
insufficient_balance | Not enough credits. | |
cancelled | You cancelled the job. | |
internal | Something failed on our side. |
cause is real_person, copyright, explicit or policy. field is duration_too_short, duration_too_long, duration_out_of_range, file_unreachable, file_unsupported, too_many_references, resolution or parameters.
failRetryable: true means sending the same request again can succeed. refunded: true means the reserved credits went back to your balance, which is the case for every failed job.
Idempotency
Pass an Idempotency-Key header (up to 128 chars) to safely replay requests without double-charging. If a job with the same key already exists for your account, the existing taskId is returned.
curl -s https://nokai.studio/api/v1/jobs/createTask \
-H "Authorization: Bearer $NOKAI_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: my-unique-request-id-abc123" \
-d '{ "model": "wan-i2v-480p", "input": { "prompt": "..." } }'