Errors and retries
On this page
What an error looks like
An error answer has a code for your program to act on, a message for people, and the request's id. When a field is wrong, fields says which, with its path; the value you sent is never repeated back.
{
"error": {
"code": "invalid_request",
"message": "Check the request fields.",
"fields": [
{
"path": "body.title",
"message": "String should have at most 160 characters"
}
]
},
"request_id": "5d1e0c2b9f6a4f0e8a3b7c21d4e9f611"
}Some refusals have no fields, because the request was well formed but the video is not possible. The message then says what to change:
{
"error": {
"code": "invalid_request",
"message": "Add at least 5,850 spoken characters to your script."
},
"request_id": "a07c3e9d1b2f4c6e8d0a1b3c5e7f9a2d"
}Every answer, error or not, has an X-Request-Id header with the same id, and Cache-Control: no-store. Log the id; it is the fastest way for us to find a request when you ask for help. The request log in Settings, API lists the requests of the last 30 days with their status. Let your program branch on code; the message is written for people and can change.
Should you send it again?
A request did not succeed
Look at the status first, then the code.
No answer, 500 or 503
Passing trouble.
- Wait 1 second, then 2, 4 and on, up to a minute
- Send it again unchanged, with the same Idempotency-Key
- Still failing: log the X-Request-Id and write to us
429
Too much at once.
- rate_limit_exceeded: wait the seconds in Retry-After
- queue_full: wait until one of your videos finishes
- Then send it again
409
Depends on the code.
- operation_pending: wait, then send it again with the same key
- idempotency_conflict: a different request needs a new key
- The rest: get the video, then do what its status allows
Any other 4xx
Something to fix.
- Read the code, the message and the fields
- Fix the request, the key, the plan or the balance
- Send it with a new key if you changed the body
Every code
| Status and code | What happened | What to do |
|---|---|---|
400idempotency_key_required | A call that creates, changes or deletes something came without an Idempotency-Key, or with one over 128 characters, or with spaces or other characters that are not plain and visible. | Add a key and send it again. |
400invalid_request | Completing an upload found a file whose contents are not what its extension says. | Delete the upload and start again with a good file. |
401invalid_api_key | No key, a key in the wrong form, or a revoked key. | Check the header and the key in Settings, API. |
402insufficient_credits | Your balance does not cover the estimate. | Add credits, then send it again. |
402plan_required | A live key, and the workspace has no active plan. | Choose a plan. |
403insufficient_scope | The key lacks the permission this call needs. The message names it. | Use a key with that permission. |
403workspace_access_deniedaccess_required | The key's maker is no longer an owner or manager, or (live keys) their account is still waiting for review. | Make a key with someone who has access. |
403forbidden | Something this workspace or this video may not have: maker notes for anything but a Cinematic video from a script or a recording, real clips with their own sound on a Fast video, a cast or product the avatar does not have, on_camera without a video of yourself, or no channel from a member who may use only some channels. | Leave it out of the request, or send the channel. |
404not_found | No video, render, upload, voice, avatar, clip, channel or Style with that id in this workspace and mode, or no such address. | Check the id, and that the key is in the same mode. |
405unavailable | The address exists, but not with this method. The message speaks of a retry, but a retry fails the same way. | Check the method in the reference. |
409invalid_state | The video's status does not allow that, it is being cancelled, or it has been in the making for more than 10 minutes, so it can no longer be cancelled or deleted until it is ready. | Get the video, then do what its status allows. |
409operation_pending | A render or resume of this video is still being sent on, or the same request is still running. | Wait a little, then send it again with the same key. |
409idempotency_conflict | This Idempotency-Key was used before with a different body. | Use a new key for a new request. |
409submission_unconfirmed | A retry of adding an avatar could not confirm whether the first request made it. The message carries a reference. | Send the reference to support before you try again, so the avatar is not made twice. |
409not_completeconflict | The video is not completed yet, or its file is not stored yet; a copied Style is not ready; a video is not waiting for approval; or a Generate later offer has changed. | Wait for the status the call needs, or ask for a new estimate. |
409upload_in_useupload_processing | An upload cannot go while videos are active, or is being completed by another request. | Wait, then try again. |
413request_too_large | The JSON body is over 512 KiB. | Send media as an upload, never inside JSON. |
413upload_too_largestorage_full | The file is over 4 GB or over what its use allows, or the workspace has no room for it. | Send a smaller file, or free some storage. |
422invalid_request | A field is wrong, or the video is not possible as asked: outside the length limits, a script too short to read for the minimum, over max_estimated_credits, an upload that is not ready, no voice and no channel that keeps one, a kind its channel does not make, a field an AI Avatar video does not take, a look on a documentary, footage that is not open yet, or a removed field such as sources. The message says which. | Fix the request. Do not send it unchanged. |
422unsupported_mediasize_mismatch | An upload of a type Kinema does not take, or a stored file that is not the size declared. | See Uploads. |
429rate_limit_exceeded | The workspace sent 120 requests this minute in this mode. | Wait the seconds in Retry-After. |
429queue_full | The workspace already has 20 active API videos in this mode. | Wait for one to finish. |
500internal_error | Something went wrong on Kinema's side. | Retry with the same Idempotency-Key. |
503unavailableapi_unavailableoutput_unavailablestorage_unavailableupload_unavailablefixture_unavailable | A part of Kinema is not reachable just now. | Retry after a pause, waiting longer each time. |
When a video fails
Some problems only show once a video is under way. The request that created it has already answered 202, and the video itself moves to failed with an error, and sends video.failed:
"status": "failed",
"error": {
"code": "generation_failed",
"message": "The video could not be completed. You can retry with resume or contact support using the video ID."
}| Code | Means | Then |
|---|---|---|
generation_failed | The video could not be made. Most failures are this one. | Resume it. If it fails again, write to us with the video's id. |
paused | The video is paused for now. Everything made so far is saved. | Resume it to carry on. |
render_failed | A video made in the app was made, but its render did not finish. | Render it again in the app. |
job_access_revoked | The key used to start the video was revoked. | Resume it with a key that works. |
cancellation_failed | A cancel could not be confirmed. | Cancel it again. |
| A code from the table above | The same problem, found while the video was being sent on: for example insufficient_credits, plan_required or workspace_access_denied. | Fix the cause, then resume it. |
Note: A long wait is not a failure
Keep the video ID and follow its status. There is no need to submit another video while this one is accepted or queued.
Rate limits
| Limit | Value | Over it |
|---|---|---|
| Requests | 120 a minute, per workspace and mode | 429 rate_limit_exceeded, with Retry-After |
| Active API videos | 20 per workspace and mode | 429 queue_full, with no Retry-After |
| A JSON body | 512 KiB | 413 request_too_large |
| A list page | 20 by default, up to 100 with limit | 422 |
All keys in a workspace share its limit for their mode. Test and live have separate limits. Wait the number of seconds in Retry-After before sending another request.
Active videos are those accepted, queued, generating or rendering. One more is refused with queue_full: wait for a webhook saying one has finished. How many are made at the same time is up to your plan: see how many at once.
Which requests are safe to send again
| Request | Send again? |
|---|---|
Any GET | Yes. Reading changes nothing. |
POST /v1/estimates | Yes. It starts nothing. |
POST /v1/videos | Yes, with the same Idempotency-Key and the same body: you get the same video back, as it is now, never a second one. |
| Render, resume, cancel | Yes, with the same key. A repeated render with the same key does not render, or charge, twice. |
| Approve, delete a video, delete a render | Yes, with the same key: you get the first answer back. |
| Clone a voice, add an avatar, add to the library, copy a Style | Yes, with the same key and body: you get the same answer back, never a second voice, avatar, file or Style. |
POST /v1/uploads | Careful: it takes no key, so a second request makes a second upload. List your uploads first. |
| Complete an upload | Yes. A ready upload answers with itself. |
| Delete an upload | Yes. Once it is gone the answer is not_found. |
Idempotency keys
- What a key is. 1 to 128 visible characters, no spaces, that name one request. Your own id for the video works well, such as
apollo-11-first-cut. - How long it lasts. For good, per workspace, mode and call. Each video has its own keys for render, resume, cancel, approve and delete, so
render-1on two videos are two keys. - Save it first. Store the key with your record before you send the request, so a retry after a crash uses the same one.
- A new request, a new key. The same key with a different body is refused with
idempotency_conflict. If you change the body after a refusal, use a new key. To render a video again later, use a new key too.
Retry with a pause
Send again after a dropped connection, a 5xx, or a 429 with Retry-After. Wait 1 second, then 2, 4 and so on up to a minute, and keep every header the same. Do not retry any other 4xx unchanged: it will fail the same way.
// Send one request; again after a dropped connection, a 5xx or a rate limit.
// init keeps the same Idempotency-Key header every time.
async function call(url, init = {}, tries = 6) {
for (let attempt = 0; ; attempt++) {
let wait = Math.min(60, 2 ** attempt);
try {
const res = await fetch(url, init);
const limited = res.status === 429 && res.headers.has("Retry-After");
if (!(res.status >= 500 || limited) || attempt === tries - 1) return res;
if (limited) wait = Number(res.headers.get("Retry-After"));
} catch (err) {
if (attempt === tries - 1) throw err;
}
await new Promise((r) => setTimeout(r, wait * 1000));
}
}import time
import requests
# Send one request; again after a dropped connection, a 5xx or a rate limit.
# kwargs keep the same Idempotency-Key header every time.
def call(method, url, tries=6, **kwargs):
for attempt in range(tries):
wait = min(60, 2 ** attempt)
try:
res = requests.request(method, url, timeout=60, **kwargs)
except (requests.ConnectionError, requests.Timeout):
if attempt == tries - 1:
raise
else:
limited = res.status_code == 429 and "Retry-After" in res.headers
if not (res.status_code >= 500 or limited) or attempt == tries - 1:
return res
if limited:
wait = int(res.headers["Retry-After"])
time.sleep(wait)Need a hand?
Ask on Discord, or write to hello@kinema.cc.