Error Handling
Every SDK exception extends AISDKError and carries status_code, endpoint, and
payload.
| Exception | Raised on |
|---|---|
AuthenticationError | 401 — key missing, invalid, or expired |
NotFoundError | 404 — assistant / app / squad not found |
ValidationError | 422 — bad request body |
ServerError | 5xx, after retries |
APIConnectionError | network failure / timeout, after retries |
APIResponseError | any other 4xx |
AISDKError | base class |
from custodian_labs import (
Custodian, AISDKError, AuthenticationError, NotFoundError,
ServerError, ValidationError, APIConnectionError,
)
try:
app = Custodian(model="gpt-4o", system_prompt="You are helpful.").deploy()
print(app.chat("Hello").response)
except AuthenticationError:
print("Check CUSTODIAN_SDK_API_KEY.")
except ValidationError as e:
print(f"Bad request: {e}")
except (ServerError, APIConnectionError):
print("Backend or network problem — retry later.")
except AISDKError as e:
print(f"{e.status_code} {e.endpoint}: {e}")
Retries
Network errors and 5xx are retried with exponential backoff; 401 / 404 / 422
are not.
| Setting | Default |
|---|---|
timeout | 30.0 s |
max_retries | 2 (3 attempts total) |
retry_backoff | 0.25 s |
Custodian(model="gpt-4o", system_prompt="...", timeout=60.0, max_retries=4)
Custodian(model="gpt-4o", system_prompt="...", max_retries=0) # disable