Skip to main content

Error Handling

Every SDK exception extends AISDKError and carries status_code, endpoint, and payload.

ExceptionRaised on
AuthenticationError401 — key missing, invalid, or expired
NotFoundError404 — assistant / app / squad not found
ValidationError422 — bad request body
ServerError5xx, after retries
APIConnectionErrornetwork failure / timeout, after retries
APIResponseErrorany other 4xx
AISDKErrorbase 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.

SettingDefault
timeout30.0 s
max_retries2 (3 attempts total)
retry_backoff0.25 s
Custodian(model="gpt-4o", system_prompt="...", timeout=60.0, max_retries=4)
Custodian(model="gpt-4o", system_prompt="...", max_retries=0) # disable

Next​

Authentication · Reference: SDK exceptions