Error Response Format
All error responses follow a unified JSON format:Field Descriptions
| Field | Type | Required | Description |
|---|---|---|---|
| code | integer | ✅ | Error code (equals HTTP status code) |
| message | string | ✅ | Error message in format "<Category>: <detail>" |
- ❌
data.errornested field is no longer used - ✅
messagecontains both category and detailed information
Error Codes Reference
Response Code Rules
- Success:
code = 0, HTTP status code 200 - Error:
code = HTTP status code(e.g., 400, 401, 404, 429, 500, 503)
HTTP Status Codes
| HTTP Status | code | Description | Common Scenarios |
|---|---|---|---|
| 200 | 0 | Success | Request processed successfully |
| 400 | 400 | Bad Request | Missing required parameters, invalid format, invalid values |
| 401 | 401 | Unauthorized | Invalid API key, missing API key, expired API key |
| 404 | 404 | Not Found | Task ID not found, model not found, provider not found |
| 429 | 429 | Too Many Requests | Rate limit exceeded, quota exceeded |
| 500 | 500 | Internal Server Error | Internal processing error, unexpected error |
| 503 | 503 | Service Unavailable | Service temporarily unavailable, circuit breaker open |
400 - Bad Request
Error Categories
| Category | Use Case |
|---|---|
Invalid parameters | Parameter validation failed (general) |
Missing required parameter | Required parameter missing |
Invalid format | Parameter format error |
Value out of range | Parameter value out of range |
Examples
Missing required parameter:401 - Unauthorized
Error Categories
| Category | Use Case |
|---|---|
Authentication failed | Authentication failure |
Examples
Missing API key:404 - Not Found
Error Categories
| Category | Use Case |
|---|---|
Resource not found | Resource does not exist |
Examples
Task not found:429 - Too Many Requests
Error Categories
| Category | Use Case |
|---|---|
Rate limit exceeded | API rate limit |
Concurrent limit exceeded | Concurrent task limit |
Response Headers
When team rate limit is triggered, the response includes these headers:| Header | Type | Description |
|---|---|---|
| X-RateLimit-Limit | integer | Maximum requests per minute |
| X-RateLimit-Remaining | integer | Remaining quota in current window |
| X-RateLimit-Reset | timestamp | Rate limit reset time (Unix timestamp) |
Examples
Team rate limit exceeded:500 - Internal Server Error
Error Categories
| Category | Use Case |
|---|---|
Internal server error | Server internal error |
Example
Internal error:Note: 500 errors do not include technical details to avoid information disclosure.
503 - Service Unavailable
Error Categories
| Category | Use Case |
|---|---|
Service unavailable | Service unavailable |
Examples
Service unavailable:Best Practices
Retry Strategy
Retryable Error
- 429 - Too Many Requests:
- Team rate limit: Check
X-RateLimit-Resetheader, wait until reset time - Concurrent limit: Wait for running tasks to complete
- Use exponential backoff
- Team rate limit: Check
- 500 - Server Error: Retry after short wait (max 3 retries)
- 503 - Service Unavailable: Retry after longer wait (use exponential backoff)
Non-Retryable Errors
- 400 - Bad Request: Fix parameters and retry
- 401 - Unauthorized: Provide valid API key
- 404 - Not Found: Check resource ID
Exponential Backoff
Retry interval calculation:Error Logging
Log the following information for debugging:- Request timestamp
- Request parameters
- Error code
- Complete error message (including category and detail)
- Request ID (if provided)
User-Friendly Error Messages
Parse error category and provide user-friendly messages:Team-Level Rate Limiting
Monitor Response Headers
Proactive Rate Limiting
Best practices:- Monitor remaining quota: Check
X-RateLimit-Remainingregularly - Proactive throttling: Reduce request rate when quota is low
- Reserve buffer: Keep 10-20% quota as buffer
- Distribute requests: Avoid sending many requests in short time
Concurrent Task Management
Team concurrent task limit:- All API keys under same team share concurrent task quota
- Implement client-side concurrency control to avoid frequent limit triggers
- Wait for running tasks to complete when limit is reached
Timeout Settings
Set appropriate request timeout:- Text-to-image: 30-60 seconds recommended
- Text-to-video: 60-120 seconds recommended
- Task query: 10-30 seconds recommended
FAQ
Q1: Why do I always get 401 errors? A: Possible reasons:- API key not set or format error (should be
Authorization: Bearer YOUR_API_KEY) - API key expired or disabled
- API key doesn’t have permission to access this endpoint
Q2: Why do I get 429 errors? A: Rate limiting triggered. Check error message category:
Rate limit exceeded: Team rate limit- Check
X-RateLimit-Resetfor reset time - Reduce request rate
- Check
Concurrent limit exceeded: Team concurrent task limit- Wait for running tasks to complete
- Implement client-side concurrency control
- Check response headers for remaining quota
- Use retry strategy (exponential backoff)
- Contact support to upgrade team quota
Q3: Why does task query return 404? A: Possible reasons:
- Task ID doesn’t exist or typo
- Task expired and cleaned up (results typically retained for 24 hours)
- Task belongs to different API key, no access permission
Q4: How to distinguish client errors from server errors? A: Based on HTTP status code:
- 4xx: Client error, need to fix request parameters or authentication
- 5xx: Server error, can retry or contact support