NeccessoryNeccessory
REST API

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

HTTPerror.codeMeaningWhat to do
400validation_errorA field is missing, malformed or out of range. The message names itFix the request. Do not retry it unchanged
400invalid_platformplatform is not web, ios or androidSend an allowed value
400consent_requiredconsent is not trueCollect the user's consent, then send consent: true
400invalid_durationdurationSec is outside 20–180Send a duration from 20 to 180 seconds
400invalid_kindkind is not videoSend kind: "video"
400invalid_content_typeThe video type is not supportedUse video/mp4, video/quicktime or video/webm
401unauthorizedMissing or invalid signature, or an unknown, disabled or expired keyRead the reason in the usage log. See Authentication
403feature_not_allowedA requested metric set is not allowed for this keyRequest only allowed sets, or change the key's sets in the console
403quota_exceededThe key's monthly quota of cloud seconds is used upRaise the quota in the console or wait for the next month
403token_quota_exceededThe key's monthly spend cap is reachedRaise the cap in the console or wait for the next month
403insufficient_tokensThe organization's balance does not cover the estimate for this measurementBuy tokens in Console → Spend. See Pricing
403on_device_not_authorizedThe key is not an on-device key of an approved organizationApply for on-device access and create an on_device key. See API keys
403forbiddenWeb model access is not enabled for this key or was revokedContact support
404not_foundThe endpoint does not exist, or the resource does not exist or belongs to another keyCheck the path, the ID and the key you sign with
404object_not_foundThe upload does not exist, is not finished or has expiredUpload the file, then create the job. An upload expires 1 hour after you request its URL
409idempotency_conflictThe idempotencyKey was already used with a different sha256Use a new idempotencyKey for each new file
413object_too_largeThe uploaded video is larger than 256 MiBShorten or re-record the video
413payload_too_largeThe JSON body is larger than 256 KBLeave out the raw section or shorten it
422sha256_mismatchsha256 is malformed or does not match the uploaded bytesHash the exact file you uploaded, in lowercase hex
429rate_limitedA request limit is reachedWait for RateLimit-Reset seconds, then retry with backoff
500internal_errorUnexpected server errorRetry with backoff. If it persists, contact support with the X-Request-Id
503cloud_unavailableCloud processing is temporarily unavailableRetry 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.

Statuserror.codeMeaning
failedinsufficient_frame_rateThe video is below 20 fps
failedtoo_shortLess than 20 seconds of video
failedface_not_detectedNo face in more than 30% of frames
failedface_too_smallThe median face width is below 100 px
failedunsupported_mediaThe codec or container is not supported
failedsha256_mismatchThe stored file no longer matches the declared sha256
failedinternal_errorProcessing failed. Run the measurement or submit the job again
failedorg_deletedThe organization was deleted before the job finished
expiredobject_expiredThe upload expired before processing started
abortedstream_interruptedThe live connection dropped
abortedidle_timeoutThe live session received no data for too long
abortedabortedThe session was ended before a result
abortedsupersededThe 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.