Error Handling
Understanding API errors and how to handle them
The Expand API uses conventional HTTP response codes to indicate the success or failure of a request.
HTTP Status Codes
| Code | Description |
|---|---|
200 |
Understanding API errors and how to handle them
The Expand API uses conventional HTTP response codes to indicate the success or failure of a request.
| Code | Description |
|---|---|
200 |
| Success - The request completed successfully |
400 | Bad Request - Invalid parameters or request body |
401 | Unauthorized - Invalid or missing API key |
429 | Too Many Requests - Rate limit exceeded |
500 | Internal Error - Server error, includes fetch failures |
503 | Service Unavailable - The service is temporarily unavailable |
All errors follow a consistent format with a _tag field identifying the error type:
{
"_tag": "ErrorType",
// Additional fields depend on error type
}Returned when the request body doesn't match the expected schema:
{
"_tag": "HttpApiDecodeError",
"message": "Invalid request parameters",
"issues": [
{
"_tag": "Missing",
"path": ["url"],
"
Common validation issues:
url fieldhttp:// or https://)include.links.includePatternssearch.queryReturned when authentication fails:
{
"_tag": "AuthFailed",
"reason": "InvalidApiKey",
"description": "The provided API key is not valid"
}| Reason | Description |
|---|---|
InvalidApiKey | The API key is missing or invalid |
InvalidToken | The bearer token is invalid |
InvalidSession | The session has expired |
InvalidTenant |
Returned when you exceed your rate limit. See Rate Limiting for details.
{
"_tag": "TooManyRequests"
}Returned when content extraction fails:
{
"_tag": "FetchError",
"cause": "Navigation timeout: page took too long to load"
}Common causes:
Returned when the service is temporarily unavailable:
{
"_tag": "ServiceUnavailable"
}This typically indicates a temporary issue. Retry your request after a short delay.
import Expand, { ExpandError, APIError, RateLimitError } from 'expandai'
const client = new Expand({ apiKey: '{{API_KEY}}' })
try {
const result = await client.fetch({ url: 'https://example.com' })
} catch (error) {
if (error instanceof RateLimitError) {
// Handle rate limiting - wait and retry
console.log('Retry after:', error.retryAfter)
} else
When using cURL or raw HTTP, check the response status code and parse the JSON body for error details:
response=$(curl -s -w "\n%{http_code}" -X POST https://api.expand.ai/v1/fetch \
-H "x-expand-api-key: {{API_KEY}}" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com"}')
status_code=$(echo "$response" | tail -n 1)
body=$(echo "$response" | sed '$d')
_tag field for debugging429, 503)400 errors| The organization was not found |
from expandai import Expand, ExpandError, APIError, RateLimitError
client = Expand(api_key="{{API_KEY}}")
try:
result = client.fetch(url="https://example.com")
except RateLimitError as e:
# Handle rate limiting - wait and retry
print(f"Retry after: {e.retry_after}")
except APIError as e:
# Handle API errors (4xx, 5xx)