Error Handling
Learn about Alaya Code API error codes and recommended handling strategies.
Error Response Format
When an API request fails, the response body contains error information in the following format:
{
"error": {
"message": "Error description",
"type": "error_type",
"code": "error_code"
}
}Error Code Reference
| Status Code | Status | Description | Common Cause | Solution |
|---|---|---|---|---|
| 400 | Bad Request | Bad request format | Invalid JSON body or missing required fields (e.g., model, messages) | Check request body format and ensure all required fields are present |
| 401 | Unauthorized | Authentication failed | Invalid, expired, or missing API Key | Check the Authorization header format and API Key |
| 402 | Payment Required | Insufficient quota | Account balance exhausted or monthly spend cap reached | Upgrade plan or purchase a booster pack |
| 403 | Forbidden | Permission denied | Current plan doesn't support the requested model or feature | Upgrade to a plan that supports the model |
| 404 | Not Found | Resource not found | Invalid API path or model name | Check the URL path and model name |
| 429 | Too Many Requests | Rate limit exceeded | Exceeded plan's RPM or TPM limit | Reduce request frequency or upgrade plan. Check Retry-After header |
| 500 | Internal Server Error | Internal server error | Server-side exception | Retry the request. Contact support if it persists |
| 502 | Bad Gateway | Upstream service error | LLM provider API temporarily unavailable | Retry later or switch to another model |
| 503 | Service Unavailable | Service unavailable | System maintenance or overload | Retry later |
Retry Strategy
For 429 and 5xx errors, implement exponential backoff retry:
async function callWithRetry(fn, maxRetries = 3) {
for (let i = 0; i < maxRetries; i++) {
try {
return await fn();
} catch (error) {
if (error.status === 429 || error.status >= 500) {
const delay = Math.pow(2, i) * 1000;
await new Promise(resolve => setTimeout(resolve, delay));
continue;
}
throw error;
}
}
throw new Error('Max retries exceeded');
}Common Troubleshooting Steps
- Verify API Key: Check in the console that the key is enabled. Watch for extra spaces when copying.
- Check Base URL: Ensure it's
https://codingplan.alayanew.com/v1(note the trailing/v1). - Check model name: Use
GET /v1/modelsto see the list of currently available models. - Check quota: View current window quota usage on the Usage page in the console.
- Review request logs: Check detailed API request records on the Logs page in the console.
Last updated on
Was this page helpful?
