Error Handling & Retry
Exception Hierarchy
FaosError (base)
├── FaosAPIError (HTTP errors from API)
│ └── FaosAuthError (401/403)
├── FaosTimeoutError (request timeout)
└── FaosRetryExhaustedError (all retries failed)
Handling API Errors
from faos import FaosClient
from faos.exceptions import FaosAPIError, FaosAuthError, FaosTimeoutError
client = FaosClient(api_key="faos_sk_...")
try:
response = client.agents.invoke("analyst", {"query": "test"})
except FaosAuthError as e:
print(f"Auth failed: {e.message}")
# e.status_code == 401 or 403
except FaosAPIError as e:
print(f"API error {e.status_code}: {e.message}")
print(f"Error code: {e.error_code}")
print(f"Request ID: {e.request_id}")
except FaosTimeoutError:
print("Request timed out")
Retry Configuration
The SDK retries automatically on transient failures with exponential backoff.
Default behavior:
- 3 retries
- 0.5s base delay with exponential backoff + jitter
- Retries on: network errors, HTTP 429, 500, 502, 503
- Respects
Retry-Afterheader from 429 responses
from faos import FaosClient, RetryConfig
# Custom retry config
client = FaosClient(
api_key="faos_sk_...",
retry=RetryConfig(
max_retries=5,
base_delay=1.0,
max_delay=30.0,
retry_on=(429, 500, 502, 503),
),
)
# Disable retries
client = FaosClient(api_key="faos_sk_...", max_retries=0)
Backoff Formula
delay = base_delay * (2 ^ attempt) + random_jitter(0-25%)
Capped at max_delay. If Retry-After header is present on 429 responses, the SDK uses that value instead.
Non-Retryable Errors
Status codes not in retry_on are never retried (e.g., 400, 401, 403, 404).