Skip to main content
The SDK throws two error classes. Always check both when handling failures.
import { DeytaError, DeytaConnectionError } from "@deyta-ai/sdk";

try {
  await deyta.namespaces.get("nonexistent");
} catch (err) {
  if (err instanceof DeytaError) {
    err.code;     // e.g. "NOT_FOUND"
    err.status;   // e.g. 404
    err.message;  // human-readable message
  } else if (err instanceof DeytaConnectionError) {
    // Network failure, timeout, or caller-side abort.
    err.cause;    // the underlying error if available
  }
}

DeytaError

Thrown when the API responds with a non-2xx status. Fields:
code
ErrorCode
Machine-readable error code (see below).
status
number
HTTP status code from the response.
message
string
Human-readable error message from the API.

Error codes

CodeHTTP statusTypical cause
BAD_REQUEST400Invalid input or missing fields
UNAUTHORIZED401Missing or invalid API key
FORBIDDEN403API key lacks required scope
NOT_FOUND404Resource does not exist
CONFLICT409Conflicting state (e.g., duplicate external ref)
INTERNAL_ERROR500Unexpected server-side failure
BAD_GATEWAY502Upstream gateway error
SERVICE_UNAVAILABLE503Service temporarily unavailable
GATEWAY_TIMEOUT504Upstream request timed out

DeytaConnectionError

Thrown when the request never received a response — network failures, the SDK’s timeout firing, or caller-side AbortSignal cancellation. Fields:
message
string
Description of the failure.
cause
unknown
The original error from fetch or the AbortSignal, when available.

Distinguishing timeouts from real network errors

If you’ve configured a per-call timeout or passed your own AbortSignal, both surface as DeytaConnectionError. Inspect the cause to differentiate:
try {
  await deyta.memory.recall(input, { signal: controller.signal });
} catch (err) {
  if (err instanceof DeytaConnectionError) {
    if (controller.signal.aborted) {
      console.log("Caller cancelled the request.");
    } else {
      console.log("Network/timeout failure:", err.cause);
    }
  }
}