Alaya NeW Cloud

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 CodeStatusDescriptionCommon CauseSolution
400Bad RequestBad request formatInvalid JSON body or missing required fields (e.g., model, messages)Check request body format and ensure all required fields are present
401UnauthorizedAuthentication failedInvalid, expired, or missing API KeyCheck the Authorization header format and API Key
402Payment RequiredInsufficient quotaAccount balance exhausted or monthly spend cap reachedUpgrade plan or purchase a booster pack
403ForbiddenPermission deniedCurrent plan doesn't support the requested model or featureUpgrade to a plan that supports the model
404Not FoundResource not foundInvalid API path or model nameCheck the URL path and model name
429Too Many RequestsRate limit exceededExceeded plan's RPM or TPM limitReduce request frequency or upgrade plan. Check Retry-After header
500Internal Server ErrorInternal server errorServer-side exceptionRetry the request. Contact support if it persists
502Bad GatewayUpstream service errorLLM provider API temporarily unavailableRetry later or switch to another model
503Service UnavailableService unavailableSystem maintenance or overloadRetry 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

  1. Verify API Key: Check in the console that the key is enabled. Watch for extra spaces when copying.
  2. Check Base URL: Ensure it's https://codingplan.alayanew.com/v1 (note the trailing /v1).
  3. Check model name: Use GET /v1/models to see the list of currently available models.
  4. Check quota: View current window quota usage on the Usage page in the console.
  5. Review request logs: Check detailed API request records on the Logs page in the console.

Last updated on

Was this page helpful?

On this page