Error Handling
The Char AI API uses conventional HTTP status codes and returns structured error responses.
HTTP Status Codes
| Code | Meaning |
|---|
200 | Success |
201 | Created |
204 | No Content |
400 | Bad Request |
401 | Unauthorized |
403 | Forbidden |
404 | Not Found |
422 | Validation Error |
429 | Rate Limited |
500 | Server Error |
All errors follow a consistent structure:
{
"code": "VALIDATION_ERROR",
"status": 422,
"message": "Invalid request parameters",
"errors": [
{
"field": "allowed_origins",
"message": "Must be an array of valid URLs"
}
]
}
Common Error Codes
Authentication
Authorization
Not Found
Validation
UNAUTHORIZED{
"code": "UNAUTHORIZED",
"status": 401,
"message": "Missing or invalid authentication token"
}
Check that your JWT token is valid and not expired.
FORBIDDEN{
"code": "FORBIDDEN",
"status": 403,
"message": "You don't have permission to access this resource"
}
Ensure your token includes the required organization context.
NOT_FOUND{
"code": "NOT_FOUND",
"status": 404,
"message": "Site not found"
}
Verify the resource ID and that it belongs to your organization.
VALIDATION_ERROR{
"code": "VALIDATION_ERROR",
"status": 422,
"message": "Invalid request parameters",
"errors": [...]
}
Check the errors array for specific field-level issues.
Rate Limiting
When rate limited, you’ll receive:
{
"code": "RATE_LIMITED",
"status": 429,
"message": "Too many requests",
"retry_after": 60
}
Respect the retry_after value and implement exponential backoff.
Handling Errors
try {
const response = await fetch('/api/sites', {
headers: { Authorization: `Bearer ${token}` }
});
if (!response.ok) {
const error = await response.json();
throw new Error(error.message);
}
return response.json();
} catch (error) {
console.error('API Error:', error.message);
}
import requests
try:
response = requests.get(
'https://app.meetchar.ai/api/sites',
headers={'Authorization': f'Bearer {token}'}
)
response.raise_for_status()
return response.json()
except requests.exceptions.HTTPError as e:
error = e.response.json()
print(f"API Error: {error['message']}")