Errors
The error envelope, every error code the API returns, job error codes, and how to retry.
Every failed request returns ok: false with a stable code and a human-readable message.
Envelope
{
"ok": false,
"error": {
"code": "feature_not_allowed",
"message": "This key does not allow: bp"
}
}Branch on error.code. The message is for logs and may change.
Every response, successful or not, carries an X-Request-Id header. Log it with every failure
and include it when you contact support. It also finds the call in the
usage log and in the console search.
Error codes
| HTTP | error.code | Meaning | What to do |
|---|---|---|---|
| 400 | validation_error | A field is missing, malformed or out of range. The message names it | Fix the request. Do not retry it unchanged |
| 400 | invalid_platform | platform is not web, ios or android | Send an allowed value |
| 400 | consent_required | consent is not true | Collect the user's consent, then send consent: true |
| 400 | invalid_duration | durationSec is outside 20–180 | Send a duration from 20 to 180 seconds |
| 400 | invalid_kind | kind is not video | Send kind: "video" |
| 400 | invalid_content_type | The video type is not supported | Use video/mp4, video/quicktime or video/webm |
| 401 | unauthorized | Missing or invalid signature, or an unknown, disabled or expired key | Read the reason in the usage log. See Authentication |
| 403 | feature_not_allowed | A requested metric set is not allowed for this key | Request only allowed sets, or change the key's sets in the console |
| 403 | quota_exceeded | The key's monthly quota of cloud seconds is used up | Raise the quota in the console or wait for the next month |
| 403 | token_quota_exceeded | The key's monthly spend cap is reached | Raise the cap in the console or wait for the next month |
| 403 | insufficient_tokens | The organization's balance does not cover the estimate for this measurement | Buy tokens in Console → Spend. See Pricing |
| 403 | on_device_not_authorized | The key is not an on-device key of an approved organization | Apply for on-device access and create an on_device key. See API keys |
| 403 | forbidden | Web model access is not enabled for this key or was revoked | Contact support |
| 404 | not_found | The endpoint does not exist, or the resource does not exist or belongs to another key | Check the path, the ID and the key you sign with |
| 404 | object_not_found | The upload does not exist, is not finished or has expired | Upload the file, then create the job. An upload expires 1 hour after you request its URL |
| 409 | idempotency_conflict | The idempotencyKey was already used with a different sha256 | Use a new idempotencyKey for each new file |
| 413 | object_too_large | The uploaded video is larger than 256 MiB | Shorten or re-record the video |
| 413 | payload_too_large | The JSON body is larger than 256 KB | Leave out the raw section or shorten it |
| 422 | sha256_mismatch | sha256 is malformed or does not match the uploaded bytes | Hash the exact file you uploaded, in lowercase hex |
| 429 | rate_limited | A request limit is reached | Wait for RateLimit-Reset seconds, then retry with backoff |
| 500 | internal_error | Unexpected server error | Retry with backoff. If it persists, contact support with the X-Request-Id |
| 503 | cloud_unavailable | Cloud processing is temporarily unavailable | Retry later. Check GET /api/v1/status |
Limits and quotas are described in Limits & quotas.
Job errors
A cloud session or video job that ends without a result reports why in its error.code. This is
part of the job object, not an HTTP error: GET /sdk/v1/cloud/jobs/{jobId} still returns 200.
| Status | error.code | Meaning |
|---|---|---|
failed | insufficient_frame_rate | The video is below 20 fps |
failed | too_short | Less than 20 seconds of video |
failed | face_not_detected | No face in more than 30% of frames |
failed | face_too_small | The median face width is below 100 px |
failed | unsupported_media | The codec or container is not supported |
failed | sha256_mismatch | The stored file no longer matches the declared sha256 |
failed | internal_error | Processing failed. Run the measurement or submit the job again |
failed | org_deleted | The organization was deleted before the job finished |
expired | object_expired | The upload expired before processing started |
aborted | stream_interrupted | The live connection dropped |
aborted | idle_timeout | The live session received no data for too long |
aborted | aborted | The session was ended before a result |
aborted | superseded | The SDK finished the session by upload. supersededBy points to the job with the result |
Treat any other code as internal_error. Recording requirements for video are in
Video processing.
Retry safely
Retry 429 and 5xx responses with exponential backoff. Do not retry other 4xx responses
unchanged. Sign every attempt again: a reused nonce fails with 401.
POST /sdk/v1/cloud/jobs is idempotent through idempotencyKey. Other POST requests can
create a second object when retried after a 5xx.
import { signHeaders } from './neccessory.js';
const RETRYABLE = new Set([429, 500, 502, 503, 504]);
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
export async function callWithRetry(method, pathWithQuery, payload, attempts = 5) {
const path = pathWithQuery.split('?')[0];
const body = payload === undefined ? '' : JSON.stringify(payload);
for (let attempt = 1; ; attempt += 1) {
const headers = signHeaders({
keyId: process.env.NECCESSORY_KEY_ID,
secret: process.env.NECCESSORY_SECRET,
method,
path,
body,
});
if (body) headers['content-type'] = 'application/json';
const res = await fetch(`https://neccessory.com${pathWithQuery}`, {
method,
headers,
body: body || undefined,
});
const json = await res.json().catch(() => null);
if (json?.ok) return json.data;
const requestId = res.headers.get('x-request-id');
const code = json?.error?.code ?? `http_${res.status}`;
if (!RETRYABLE.has(res.status) || attempt >= attempts) {
throw Object.assign(new Error(`${code} (${requestId})`), { status: res.status, code, requestId });
}
const resetSec = Number(res.headers.get('ratelimit-reset'));
const backoffMs = Math.min(30000, 500 * 2 ** (attempt - 1)) + Math.random() * 250;
await sleep(res.status === 429 && resetSec > 0 ? resetSec * 1000 : backoffMs);
}
}signHeaders is the helper from Authentication.
Details of a 401
401 unauthorized does not say which check failed. The usage log does: each refused call has
an errorCode such as invalid_signature or timestamp_out_of_window. The table of causes and
fixes is in Authentication.