Error handling
Both SDKs throw one error class per failure. Each carries the status code, the endpoint and the response body.
| Python | TypeScript | When |
|---|---|---|
AuthenticationError | AuthenticationError | 401: key missing, invalid or expired. |
NotFoundError | NotFoundError | 404: agent, app or squad not found. |
ValidationError | ValidationError | 422: bad request, or an invalid squad caught before sending. |
ServerError | ServerError | 5xx, after retries. |
APIConnectionError | APIConnectionError | Network failure or timeout, after retries. |
APIResponseError | APIResponseError | Any other 4xx, such as 429 when a limit is reached. |
AISDKError | CustodianError | Base class of all of the above. |
- Python
- TypeScript
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)
import {
Custodian, CustodianError, AuthenticationError, ValidationError,
ServerError, APIConnectionError,
} from "@custodianlabs/sdk";
try {
const app = await new Custodian({ model: "gpt-6-luna", systemPrompt: "You are helpful." }).deploy();
console.log((await app.chat("Hello"))?.response);
} catch (err) {
if (err instanceof AuthenticationError) console.error("Check CUSTODIAN_SDK_API_KEY.");
else if (err instanceof ValidationError) console.error(`Bad request: ${err.message}`);
else if (err instanceof ServerError || err instanceof APIConnectionError) console.error("Try again later.");
else if (err instanceof CustodianError) console.error(err.statusCode, err.endpoint, err.payload);
else throw err;
}
Retries and timeouts
Network errors and 5xx responses are retried with exponential backoff. 401, 404,
422 and other 4xx errors are not retried.
| Setting | Python default | TypeScript default |
|---|---|---|
timeout / timeout | 120 s | 30 s |
max_retries / maxRetries | 2 (3 attempts) | 2 (3 attempts) |
| Guardian Layer timeout | 60 s | 60 s |
- Python
- TypeScript
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
new Custodian({ model: "gpt-6-luna", systemPrompt: "...", timeout: 60, maxRetries: 4 });
new Custodian({ model: "gpt-6-luna", systemPrompt: "...", maxRetries: 0 }); // no retries
Common fixes
Missing API key · Invalid API key · Agent not found · Connection error · Request limit reached