Errors and retries

One error hierarchy across every client, and what the transport retries for you.

Every service client raises the same typed errors, from aice-core / @aiceafrica/core. Catch the base class to handle all of them, or a subclass to handle one case.

The hierarchy

AiceError                  base
├── APIConnectionError     no response at all: DNS, refused, timed out
├── AuthenticationError    401  key missing, invalid or expired
├── AiceForbiddenError     403  authenticated, but not allowed
├── NotFoundError          404
├── ValidationError        400 / 422, with field-level details
├── RateLimitError         429, with the server's Retry-After
├── ServerError            5xx
└── InsufficientScopeError raised in the client, before any request

AiceForbiddenError is named that way so it doesn't shadow Python's built-in PermissionError.

Every error carries the HTTP status, the service's error code, the request ID the server stamped on the response, and any details. Quote the request ID in a support request: it pins down the exact call.

FieldPythonTypeScript
HTTP statuserr.status_codeerr.status
Service error codeerr.codeerr.code
Request IDerr.request_iderr.requestId
Detailserr.detailserr.details
Retry-After (429 only), in secondserr.retry_aftererr.retryAfter
from aice_core import AiceError, NotFoundError, ValidationError

try:
    client.recommend("user-1", n=10)
except NotFoundError:
    ...  # the user doesn't exist yet: create it, or show an empty state
except ValidationError as err:
    log.warning("bad request", extra={"details": err.details, "request_id": err.request_id})
except AiceError as err:
    log.error("AICE call failed", extra={"status": err.status_code, "request_id": err.request_id})
    raise

Passing your own idempotency key

POST and PATCH get an automatic key by default. To opt a single call out (one attempt, no retry), or to reuse a key you manage, pass it explicitly. In Python this is the idempotency_key argument on the calls that expose it; the transport accepts None to opt out and a string to supply your own. In TypeScript it is idempotencyKey, where null opts out.

What gets retried

The transport retries for you. You don't need your own retry loop around an SDK call.

  • Retried: network errors, every 5xx, and 429.
  • Never retried: any other 4xx. Retrying a bad request only repeats it.
  • Backoff: exponential with jitter, capped at 10 seconds. A Retry-After header wins when present.
  • Budget: 3 retries after the first attempt. Change it with max_retries / maxRetries on the client.
  • Timeouts: each attempt gets the client's timeout: seconds in Python (default 30.0), milliseconds in TypeScript (default 30000). A timed-out attempt counts as a network error and is retried when the call is retry-eligible; once the budget is spent you get an APIConnectionError.

Retries and writes

A retried POST could create something twice. So POST and PATCH requests get an automatically generated Idempotency-Key header, and the transport only retries them when that key is present. GET, PUT and DELETE are safe to repeat and always retry.

Some calls opt out on purpose, making exactly one attempt, because their service doesn't yet deduplicate on the key and a duplicate would be costly:

CallWhy it isn't retried
Crawler jobs.createa duplicate starts a second crawl
Data Brain connections.process, connections.cleanupprocessing twice, or a destructive cleanup twice
KYC verify.start, face.create_capture_session, face.match, admin.accept, admin.recheck, admin.face_reviewcompliance actions, paid vendor sessions, and match attempts a retry would spend
Sandbox session.createeach session holds quota
Sandbox session.exec, session.install, session.cancela retry would run the command a second time
Email senders.create, recipients.create, groups.create, templates.create, drafts.create, suppressions.create, imports.createa retry would answer 409 for the thing the first attempt already made

Email's sends (campaigns.create, drafts.send, threads.send, threads.reply) are the opposite: the service honours the key, so they retry safely, and you can pass your own idempotency_key / idempotencyKey to make a send safe to repeat from a different process.

For these, a transient failure reaches you immediately. Decide at the call site whether to try again.

Service-specific error classes

A few clients re-raise the shared errors as their own subclasses, so you can catch either:

  • Sandbox (Python): every error derives from SandboxSDKError. AuthenticationError, ForbiddenError, QuotaExceededError (with .scope and .limit), SessionNotFoundError and NetworkNotPermittedError are subclasses of it. See Sandbox.
  • Recommendation (Python): RecommendationError is the base, with AuthenticationError, ValidationError, NotFoundError, ConflictError and ServerError. Each also derives from the matching aice_core class. In TypeScript, RecommendationError is just AiceError, and ConflictError (a 409) is the one class of its own.
  • Email nests its error body under error. The transport unwraps it (from aice-core 0.3.1 / @aiceafrica/core 0.4.0), so code, details and the request ID are filled in as for every other service.

Everything else raises the plain aice-core errors.

Pagination

Most list calls return a single page from one request. Email is the exception: its lists return {"items", "next_cursor"} and you pass the cursor back. The shared Page iterator in aice-core exists but no client uses it yet.

Agent Platform is different

The Agent Platform client has two halves. Its management calls (agents, skills, usage, suggestions) raise the errors above. Its conversation calls (threads, runs, assistants, crons) come straight from the LangGraph SDK, which has its own error types and retry policy. And some successful runs are refusals, with no error at all. See Agent Platform errors.

On this page