Error Handling
This guide covers how to handle errors from the AgentGate API effectively.Error Response Format
All API errors follow a consistent format:Error Categories
Client Errors (4xx)
Errors caused by the request. Fix the request before retrying.| Status | Code | Description |
|---|---|---|
| 400 | INVALID_REQUEST | Request validation failed |
| 401 | INVALID_API_KEY | API key invalid or missing |
| 402 | INSUFFICIENT_CREDITS | Not enough credits |
| 403 | INSUFFICIENT_PERMISSIONS | API key lacks required scope |
| 404 | RESOURCE_NOT_FOUND | Resource doesn’t exist |
| 429 | RATE_LIMITED | Too many requests |
Server Errors (5xx)
Errors on AgentGate’s side. Safe to retry with backoff.| Status | Code | Description |
|---|---|---|
| 500 | INTERNAL_ERROR | Unexpected server error |
| 503 | SERVICE_UNAVAILABLE | Temporary unavailability |
Handling Specific Errors
Authentication Errors (401)
Insufficient Credits (402)
Rate Limiting (429)
Validation Errors (400)
Server Errors (5xx)
SDK Error Types
The TypeScript SDK provides typed error classes:Run Failures
Run failures are different from API errors. The API call succeeds, but the run itself fails.Checking Run Status
Webhook Error Handling
Error Monitoring
Logging Best Practices
Metrics to Track
- Error rate by type (4xx vs 5xx)
- Rate limit hits
- Run failure rate by error code
- Retry success rate