Skip to main content

Error handling

Both SDKs throw one error class per failure. Each carries the status code, the endpoint and the response body.

PythonTypeScriptWhen
AuthenticationErrorAuthenticationError401: key missing, invalid or expired.
NotFoundErrorNotFoundError404: agent, app or squad not found.
ValidationErrorValidationError422: bad request, or an invalid squad caught before sending.
ServerErrorServerError5xx, after retries.
APIConnectionErrorAPIConnectionErrorNetwork failure or timeout, after retries.
APIResponseErrorAPIResponseErrorAny other 4xx, such as 429 when a limit is reached.
AISDKErrorCustodianErrorBase class of all of the above.
from custodian_labs import (
Custodian, AISDKError, AuthenticationError, ValidationError,
ServerError, APIConnectionError,
)

try:
app = Custodian(model="gpt-6-luna", 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. Try again later.")
except AISDKError as e:
print(e.status_code, e.endpoint, e.payload)

Retries and timeouts​

Network errors and 5xx responses are retried with exponential backoff. 401, 404, 422 and other 4xx errors are not retried.

SettingPython defaultTypeScript default
timeout / timeout120 s30 s
max_retries / maxRetries2 (3 attempts)2 (3 attempts)
Guardian Layer timeout60 s60 s
Custodian(model="gpt-6-luna", system_prompt="...", timeout=60.0, max_retries=4)
Custodian(model="gpt-6-luna", system_prompt="...", max_retries=0) # no retries

Common fixes​

Missing API key · Invalid API key · Agent not found · Connection error · Request limit reached