Skip to main content

Error handling

Both SDKs raise typed errors so you can branch on cause. Every error carries a short code and, when applicable, an HTTP status_code.

Python

The Python SDK exposes a full exception hierarchy under toothfairyai.errors. All errors derive from ToothFairyError.

from toothfairyai import ToothFairyClient
from toothfairyai.errors import ApiError, NetworkError, ToothFairyError

try:
agent = client.agents.create(label="…", mode="retriever", ...)
except ApiError as e:
# HTTP error from the API
print(e.status_code, e.response) # e.g. 400, {"message": "..."}
except NetworkError as e:
# connection / timeout
print("network:", e)
except ToothFairyError as e:
# anything else from the SDK
print(e.code, e)
ExceptioncodeRaised when
ToothFairyErrorUNKNOWN_ERRORBase class; uncategorised SDK errors.
MissingApiKeyErrorMISSING_API_KEYapi_key not supplied to the client.
MissingWorkspaceIdErrorMISSING_WORKSPACE_IDworkspace_id not supplied to the client.
ApiErrorAPI_ERRORThe API returned a non-2xx response. Carries status_code + response.
NetworkErrorNETWORK_ERRORConnection error or request timeout.
ValidationErrorVALIDATION_ERRORClient-side input validation failed.
StreamErrorSTREAM_ERRORA streaming session failed.
JsonDecodeErrorJSON_DECODE_ERRORAn SSE/data payload could not be parsed.
FileSizeErrorFILE_SIZE_ERRORAn uploaded file exceeds the max size (default 15 MB).
FileNotFoundErrorFILE_NOT_FOUNDA local file passed to an upload helper does not exist.

ToothFairyError attributes: message, code, status_code (optional), response (optional — the parsed API body).

Node.js

The Node.js SDK throws a single ToothFairyError class (from @toothfairyai/sdk) with code and status_code properties.

import { ToothFairyClient, ToothFairyError } from "@toothfairyai/sdk";

try {
const agent = await client.agents.create({ label: "…", mode: "retriever", ... });
} catch (e) {
const err = e as ToothFairyError;
console.log(err.code, err.statusCode, err.message);
}
codeRaised when
MISSING_API_KEYapiKey not supplied to the client.
MISSING_WORKSPACE_IDworkspaceId not supplied to the client.
API_ERRORThe API returned a non-2xx response. Carries statusCode + the response body.
NETWORK_ERRORA network/connection error occurred (no response received).
UNKNOWN_ERRORAny other failure.

Retries

Neither SDK retries automatically. For transient NETWORK_ERROR / 5xx API_ERROR, wrap calls in your own retry loop with backoff. The client's testConnection() / test_connection() helper already retries internally because an unbounded list probe can 502 on cold starts.