Skip to Content
ZeroLeaksDocs
ZeroLeaks SDK

Errors

Handle typed SDK errors, rate limits, timeouts, cancellation, and failed scans.

The SDK throws typed errors. Every error extends ZeroLeaksError. See the API reference for each error's properties and the codes the client itself throws.

import {
  ZeroLeaksAbortError,
  ZeroLeaksError,
  ZeroLeaksScanError,
  ZeroLeaksTimeoutError,
} from "@zeroleaks/sdk";

try {
  await zeroleaks.runtimeScans.run(target);
} catch (error) {
  if (error instanceof ZeroLeaksScanError) {
    console.error(error.scanId, error.details);
  } else if (error instanceof ZeroLeaksAbortError) {
    console.error("Local polling was aborted");
  } else if (error instanceof ZeroLeaksTimeoutError) {
    console.error("The request or polling operation timed out");
  } else if (error instanceof ZeroLeaksError) {
    console.error(error.status, error.code, error.requestId);
  }
}

Error codes

HTTP statusCodeCauseSolution
400Invalid requestCorrect the named field before retrying
401Missing, invalid, or revoked API keyReplace the API key. Do not retry automatically.
403SUBSCRIPTION_LIMITNo access to scans: no active paid plan, trial scans used up, or an inactive workspaceChange the plan or workspace. Do not retry automatically.
404Resource is absent or inaccessibleVerify the ID and API-key owner
410PROMPT_SCANS_RETIREDEndpoint is retired, for example scans.run() and scans.create()Use a supported scan type. This error is terminal; do not retry.
429SCAN_CONCURRENCY_LIMIT, SCAN_HOURLY_LIMIT (plan rate limits)A plan rate limit or the hourly scan-creation abuse limitWait for a running scan to finish or for the time in the message or reset field
500 / 503Service or deployment configuration errorRetry later with bounded backoff

Where a row lists no code, read error.code.

The response body is JSON with error, code, message, hint, and docs. Existing error strings, codes, and operation-specific fields are preserved. Unknown API endpoints also return JSON with HTTP 404. The SDK copies them to error.message and error.code and keeps the full body in error.details.

Failed scans

Runtime target exceptions are submitted to the active relay event and rethrown as ZeroLeaksScanError. The hosted workflow fails with the same target error and does not score the partial run.

Rate limits

Scans are unlimited on paid plans; 429 only means too many scans are running or started in the last hour. Two limits apply independently:

LimitPolicy
Plan rate limitsConcurrent scans and scans started in a rolling hour. See CI rate limits.
Scan-creation abuse limitA sliding window of 120 scan creations per hour per user, shared across that user's API keys. Runtime and endpoint scans share a limiter; skill scans use a separate limiter.

When the scan-creation limiter runs, successful responses and errors after that check include the actual rate-limit snapshot. Requests that do not run a limiter do not advertise a remaining count.

RateLimit-Policy: "default";q=120;w=3600
RateLimit: "default";r=119;t=3540
RateLimit-Limit: 120
RateLimit-Remaining: 119
RateLimit-Reset: 3540

RateLimit and RateLimit-Policy follow the IETF HTTPAPI RateLimit draft. q is the request quota, w the window in seconds, r the remaining quota, and t the seconds until reset. Compatibility RateLimit-Reset is also a delay in seconds; the existing X-RateLimit-Reset remains a Unix timestamp in milliseconds.

A 429 includes Retry-After in seconds. For the scan-creation limiter it reflects the reset time. When a plan rate limit has no precise reset header, the API recommends a 60-second retry interval; read the error message and existing scan state before starting another scan. Credential-protection limits also return rate-limit headers on 429, and Shield keeps its own retry guidance. Limits are per caller and responses are not cached.

Retries

The SDK does not retry any request automatically. Do not automatically retry scan creation: it is not idempotent, so a retry could create duplicate scans.

Honor Retry-After before trying again. The SDK exposes it as error.retryAfterMs when the response provides the header. Reduce concurrency when the remaining count is low, and use bounded backoff for transient read failures.

Timeouts and cancellation

const controller = new AbortController();

const pending = zeroleaks.endpointScans.wait(scanId, {
  signal: controller.signal,
});

controller.abort();

Aborting a runtime scan or reaching its local timeout triggers best-effort cancellation of the hosted workflow. For endpoint scans, aborting only stops local polling; call endpointScans.cancel(scanId) to stop the hosted scan. runtimeScans.cancel(runtimeScanId) does the same for a runtime scan you no longer want to finish.

On this page