Skip to content
会nokai.studio

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
StateMeaning
waitingJob accepted; not yet picked up by the generation service.
queuingGeneration service acknowledged the job; waiting for a free worker slot.
generatingActive -- the model is running. progress (0-100) updates during this phase.
successDone. resultJson contains the output URLs.
failTerminal 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 in creditsConsumed on the recordInfo response 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:

CodeMeaning
content_policy_violationThe safety filter refused the prompt, a reference or the result.
invalid_inputA parameter or attached file is not accepted by the model.
invalid_mediaAn attached file could not be read.
source_duration_exceeds_declaredAttached audio or video is longer than duration_seconds.
timeoutGeneration took too long.
upstream_unavailableThe generation service was unavailable.
generation_failedThe generation failed for another reason.
cancelledYou cancelled the job.

failReason says the same thing for a person, and failDetail adds what is known:

failReasonWhat happenedfailDetail
content_blocked_promptThe filter refused the prompt text.cause
content_blocked_referenceThe filter refused a reference file.referenceKind, cause
content_blockedThe filter refused the request or withheld the result.subject: "output" when it was the result, cause
input_invalidAn input rule was broken.field, minSeconds, maxSeconds
provider_busyThe model was overloaded.
provider_outageThe generation service was unavailable.
timeoutGeneration took too long.
insufficient_balanceNot enough credits.
cancelledYou cancelled the job.
internalSomething 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": "..." } }'