Error Codes
Complete reference of error codes returned by the Sazabi API.
Complete reference of error codes returned by the Sazabi API.
HTTP Status Codes
| Code | Meaning |
|---|---|
200 | Success |
201 | Created |
400 | Bad Request - Invalid parameters |
401 | Unauthorized - Invalid or missing API key |
403 | Forbidden - Insufficient permissions |
404 | Not Found - Resource does not exist |
429 | Too Many Requests - Rate limit exceeded |
500 | Internal Server Error |
Error Response Format
All errors return a consistent JSON structure:
{
"data": null,
"error": {
"code": "invalid_api_key",
"message": "The API key provided is invalid or expired.",
"doc_url": "https://sazabi.com/docs/developer/api/errors#invalid_api_key"
}
}| Field | Type | Description |
|---|---|---|
code | string | Machine-readable error identifier |
message | string | Human-readable error description |
doc_url | string | Link to documentation about this error |
Error Codes
Authentication Errors
These errors occur when there is a problem with your API key or authentication.
| Code | HTTP | Description | Resolution |
|---|---|---|---|
invalid_api_key | 401 | API key is malformed or does not exist | Check your API key format |
expired_api_key | 401 | API key has been revoked or expired | Generate a new API key |
missing_api_key | 401 | No API key provided in request | Add the appropriate header |
invalid_api_key
The API key provided is not valid. This can happen if:
- The key was copied incorrectly
- The key format is invalid (should start with
pk_orsk_) - The key does not exist
Example error:
{
"data": null,
"error": {
"code": "invalid_api_key",
"message": "The API key provided is invalid or expired."
}
}Resolution:
- Verify you are using the correct key from the dashboard
- Check that the key starts with
pk_(public) orsk_(secret) - Ensure the key has not been deleted
expired_api_key
The API key was valid but has been revoked or expired.
Resolution:
- Go to Settings > API Keys in the dashboard
- Create a new API key
- Update your application with the new key
missing_api_key
No API key was provided in the request headers.
Resolution:
Include the appropriate header:
# For public keys (intake endpoints)
-H "x-sazabi-key: pk_live_your_public_key"
# For secret keys (API endpoints)
-H "x-sazabi-secret-key: sk_live_your_secret_key"Permission Errors
These errors occur when your API key does not have access to the requested resource.
| Code | HTTP | Description | Resolution |
|---|---|---|---|
insufficient_permissions | 403 | API key lacks required scope | Use a key with appropriate permissions |
project_access_denied | 403 | Key does not have access to this project | Use a key scoped to this project |
organization_mismatch | 403 | Resource belongs to different org | Use a key from the correct organization |
insufficient_permissions
The API key does not have the required permissions for this operation.
Example: Using a public key (pk_) to access the threads API, which requires a secret key (sk_).
Resolution:
- For read/write API operations, use a secret key
- For data ingestion, use a public key
project_access_denied
The API key does not have access to the specified project. Public keys are scoped to a single project.
Resolution:
- Verify you are using a key created for this project
- For cross-project access, use a secret key (organization-scoped)
Rate Limiting
These errors occur when you exceed the API rate limits.
| Code | HTTP | Description | Resolution |
|---|---|---|---|
rate_limit_exceeded | 429 | Too many requests | Wait and retry with exponential backoff |
rate_limit_exceeded
You have exceeded the rate limit for this API key.
Example error:
{
"data": null,
"error": {
"code": "rate_limit_exceeded",
"message": "Too many requests. Please retry after 60 seconds."
}
}Response headers:
| Header | Description |
|---|---|
X-RateLimit-Limit | Maximum requests allowed per window |
X-RateLimit-Remaining | Requests remaining in current window |
X-RateLimit-Reset | Unix timestamp when the window resets |
Retry-After | Seconds to wait before retrying |
Resolution:
- Implement exponential backoff in your client
- Cache responses where possible
- Batch requests when the API supports it
- Contact support if you need higher limits
Validation Errors
These errors occur when request parameters are invalid.
| Code | HTTP | Description | Resolution |
|---|---|---|---|
invalid_parameter | 400 | Parameter value is invalid | Check parameter format and constraints |
missing_parameter | 400 | Required parameter not provided | Include all required parameters |
invalid_json | 400 | Request body is not valid JSON | Validate your JSON payload |
payload_too_large | 413 | Request body exceeds size limit | Reduce payload size or batch requests |
invalid_parameter
A parameter value does not match the expected format or constraints.
Example error:
{
"data": null,
"error": {
"code": "invalid_parameter",
"message": "Parameter 'limit' must be between 1 and 100"
}
}Resolution:
Check the API documentation for valid parameter values and formats.
missing_parameter
A required parameter was not included in the request.
Example error:
{
"data": null,
"error": {
"code": "missing_parameter",
"message": "Parameter 'content' is required"
}
}Resolution:
Include all required parameters as specified in the endpoint documentation.
invalid_json
The request body could not be parsed as valid JSON.
Resolution:
- Validate your JSON using a tool like
jq - Ensure proper escaping of special characters
- Check for trailing commas or missing quotes
Resource Errors
These errors occur when the requested resource cannot be found or accessed.
| Code | HTTP | Description | Resolution |
|---|---|---|---|
not_found | 404 | Resource does not exist | Verify the resource ID |
already_exists | 409 | Resource already exists | Use update instead of create |
conflict | 409 | Resource state conflict | Refresh and retry |
not_found
The requested resource does not exist or has been deleted.
Example error:
{
"data": null,
"error": {
"code": "not_found",
"message": "Thread 'thr_abc123' not found"
}
}Resolution:
- Verify the resource ID is correct
- Check that the resource has not been deleted
- Ensure you have access to this resource
Server Errors
These errors indicate a problem on the server side.
| Code | HTTP | Description | Resolution |
|---|---|---|---|
internal_error | 500 | Unexpected server error | Retry with exponential backoff |
service_unavailable | 503 | Service temporarily unavailable | Retry after a delay |
internal_error
An unexpected error occurred on the server.
Resolution:
- Retry the request with exponential backoff
- If the error persists, contact support with the request ID
Handling Errors
Recommended error handling
async function fetchWithRetry(url: string, options: RequestInit) {
const maxRetries = 3;
let lastError: Error;
for (let attempt = 0; attempt < maxRetries; attempt++) {
try {
const response = await fetch(url, options);
const data = await response.json();
if (data.error) {
// Handle specific error codes
switch (data.error.code) {
case "rate_limit_exceeded":
// Wait and retry
const retryAfter = response.headers.get("Retry-After") || "60";
await sleep(parseInt(retryAfter) * 1000);
continue;
case "invalid_api_key":
case "expired_api_key":
// Don't retry auth errors
throw new Error(`Authentication failed: ${data.error.message}`);
case "internal_error":
// Retry with backoff
await sleep(Math.pow(2, attempt) * 1000);
continue;
default:
throw new Error(data.error.message);
}
}
return data;
} catch (error) {
lastError = error as Error;
}
}
throw lastError!;
}Best practices
- Always check for errors in the response body, not just HTTP status codes
- Implement exponential backoff for transient errors (429, 500, 503)
- Log error codes for debugging and monitoring
- Do not retry authentication or validation errors
- Include request IDs when contacting support