Error handling

Last updated: 2025-01-15
1 min read

Error Handling

Handle API errors gracefully in your applications.

Error Response Format

{
  "error": {
    "code": "error_code",
    "message": "Human-readable message",
    "details": {}
  }
}

Common Error Codes

Code HTTP Status Description
invalid_api_key 401 Invalid or missing API key
rate_limit_exceeded 429 Too many requests
quota_exceeded 402 Monthly quota exhausted
invalid_request 400 Malformed request
model_unavailable 503 Model temporarily unavailable
server_error 500 Internal server error

Best Practices

try {
  const response = await taskforceai.chat(message);
} catch (error) {
  if (error.code === 'rate_limit_exceeded') {
    // Wait and retry
    await sleep(error.retryAfter);
    return retry();
  }
  if (error.code === 'quota_exceeded') {
    // Upgrade or wait for reset
    notifyUser('Quota exceeded');
  }
  // Log and handle other errors
  console.error(error);
}

Retry Strategy

Implement exponential backoff:

  1. Wait 1 second, retry
  2. Wait 2 seconds, retry
  3. Wait 4 seconds, retry
  4. Give up after 5 attempts

Still need help?

Our support team is available to assist you.

Contact Support