StyleGrab API returns structured error responses with machine-readable codes.
{
"error": {
"code": "not_found",
"message": "Extraction not found",
"details": {}
}
}
Code HTTP Status Description
unauthorized401 Missing or invalid authentication
token_expired401 JWT token has expired
invalid_api_key401 API key is invalid or revoked
forbidden403 Valid auth but insufficient permissions
Code HTTP Status Description
validation_error422 Request body failed validation
invalid_url400 URL is malformed or unreachable
invalid_webhook_url400 Webhook URL must be HTTPS
missing_field400 Required field not provided
Example:
{
"error": {
"code": "validation_error",
"message": "Validation failed",
"details": {
"fields": {
"url": "must be a valid URL",
"events": "must include at least one event"
}
}
}
}
Code HTTP Status Description
not_found404 Resource does not exist
already_exists409 Resource already exists
conflict409 Operation conflicts with current state
Code HTTP Status Description
extraction_failed422 Browser failed to load the page
extraction_timeout422 Page load timed out
page_blocked422 Page blocked the extraction
invalid_content422 Page returned non-HTML content
Example:
{
"error": {
"code": "extraction_failed",
"message": "Failed to load page",
"details": {
"reason": "SSL certificate error",
"url": "https://example.com"
}
}
}
Code HTTP Status Description
rate_limited429 Too many requests
usage_limit_exceeded429 Monthly quota exceeded
Headers included:
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1705312800
Retry-After: 60
Code HTTP Status Description
subscription_required402 Feature requires paid plan
subscription_expired402 Subscription has ended
payment_failed402 Payment processing failed
Code HTTP Status Description
webhook_delivery_failed— Webhook endpoint returned non-2xx
webhook_timeout— Endpoint didn’t respond in time
webhook_disabled— Webhook was disabled after failures
Code HTTP Status Description
internal_error500 Unexpected server error
service_unavailable503 Service temporarily unavailable
For 5xx errors, retry with exponential backoff. If the error persists, contact support.
async function extractTokens(url) {
const response = await fetch('https://api.stylegrab.dev/api/extractions', {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ url })
});
if (!response.ok) {
const error = await response.json();
switch (error.error.code) {
case 'rate_limited':
const retryAfter = response.headers.get('Retry-After');
await sleep(retryAfter * 1000);
return extractTokens(url); // Retry
case 'unauthorized':
throw new Error('Invalid API key');
case 'extraction_failed':
console.error('Page could not be loaded:', error.error.details);
return null;
default:
throw new Error(error.error.message);
}
}
return response.json();
}
import requests
import time
def extract_tokens(url):
response = requests.post(
'https://api.stylegrab.dev/api/extractions',
headers={'Authorization': f'Bearer {API_KEY}'},
json={'url': url}
)
if response.status_code == 429:
retry_after = int(response.headers.get('Retry-After', 60))
time.sleep(retry_after)
return extract_tokens(url)
if not response.ok:
error = response.json()['error']
raise Exception(f"{error['code']}: {error['message']}")
return response.json()