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 requestAiceForbiddenError 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.
| Field | Python | TypeScript |
|---|---|---|
| HTTP status | err.status_code | err.status |
| Service error code | err.code | err.code |
| Request ID | err.request_id | err.requestId |
| Details | err.details | err.details |
| Retry-After (429 only), in seconds | err.retry_after | err.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})
raisePassing 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, and429. - Never retried: any other
4xx. Retrying a bad request only repeats it. - Backoff: exponential with jitter, capped at 10 seconds. A
Retry-Afterheader wins when present. - Budget: 3 retries after the first attempt. Change it with
max_retries/maxRetrieson the client. - Timeouts: each attempt gets the client's
timeout: seconds in Python (default30.0), milliseconds in TypeScript (default30000). 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 anAPIConnectionError.
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:
| Call | Why it isn't retried |
|---|---|
Crawler jobs.create | a duplicate starts a second crawl |
Data Brain connections.process, connections.cleanup | processing twice, or a destructive cleanup twice |
KYC verify.start, face.create_capture_session, face.match, admin.accept, admin.recheck, admin.face_review | compliance actions, paid vendor sessions, and match attempts a retry would spend |
Sandbox session.create | each session holds quota |
Sandbox session.exec, session.install, session.cancel | a retry would run the command a second time |
Email senders.create, recipients.create, groups.create, templates.create, drafts.create, suppressions.create, imports.create | a 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.scopeand.limit),SessionNotFoundErrorandNetworkNotPermittedErrorare subclasses of it. See Sandbox. - Recommendation (Python):
RecommendationErroris the base, withAuthenticationError,ValidationError,NotFoundError,ConflictErrorandServerError. Each also derives from the matchingaice_coreclass. In TypeScript,RecommendationErroris justAiceError, andConflictError(a 409) is the one class of its own. - Email nests its error body under
error. The transport unwraps it (fromaice-core0.3.1 /@aiceafrica/core0.4.0), socode,detailsand 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.