Skip to content
This page was translated from the Chinese original, which has changed since — it may be out of date. The Chinese version is authoritative. View the Chinese original →

Error Handling ​

All error responses follow a unified structure. Every error code comes with a code + message + suggested action, making automated handling straightforward.

The Golden Rule of Retries

Authentication errors (401): do not retry, raise immediately; rate limits (429): retry with exponential backoff of 2 ** attempt seconds; other API errors: retry up to the max_retries limit.

Error Response Format ​

All error responses follow a unified format:

json
{ "error": { "code": "error_code", "message": "Human readable error message", "type": "error_type", "param": "optional_parameter_name" } }

HTTP Status Codes ​

Status CodeMeaningDescription
200SuccessRequest processed successfully
400Bad RequestInvalid parameters or malformed format
401UnauthenticatedAPI Key invalid or missing
403ForbiddenNo permission to access this resource
404Not FoundRequested resource does not exist
429Too Many RequestsRate limit exceeded
500Server ErrorInternal server error
502Bad GatewayUpstream service unavailable
503Service UnavailableService temporarily unavailable

Common Errors ​

Quickly Locate by Symptom

If you want to start from "what error did I hit," with an item-by-item checklist, see Troubleshooting. This page is the authoritative reference for the complete set of error codes and retry strategies.
codetypemessage (example)Solution
invalid_api_keyauthentication_errorInvalid API key providedCheck that the Key was copied correctly, starts with sk-, and has no extra spaces
model_not_foundnew_api_errorNo available channel for model xxxCheck the model name; confirm a channel is configured for the model; contact the administrator to enable access
insufficient_quotabilling_errorInsufficient quota for this requestCheck your account balance; contact the administrator to top up
rate_limit_exceededrate_limit_errorRate limit exceeded. Please slow down.Lower your request rate; retry with exponential backoff; request a higher rate limit
context_length_exceededinvalid_request_errorThis model’s maximum context length is 8192 tokensReduce input length; switch to a model with a longer context; truncate history with a sliding window

model_not_found response body (HTTP 404, type: new_api_error):

json
{
  "error": {
    "code": "model_not_found",
    "message": "模型 gpt-5 无可用渠道",
    "type": "new_api_error"
  }
}

insufficient_quota response body (HTTP 402, type: billing_error):

json
{
  "error": {
    "code": "insufficient_quota",
    "message": "Insufficient quota for this request",
    "type": "billing_error"
  }
}

Error Handling Best Practices ​

Key points: authentication errors (401) are not retried and are raised immediately; rate limits (429) are retried after exponential backoff (2 ** attempt seconds); other API errors are retried up to the max_retries limit.

python
from openai import OpenAI, APIError, RateLimitError, AuthenticationError
import time

client = OpenAI(base_url="https://hub.lurus.cn/v1", api_key="sk-your-api-key")

def chat_with_retry(messages, max_retries=3):
    for attempt in range(max_retries):
        try:
            return client.chat.completions.create(model="deepseek-chat", messages=messages)
        except AuthenticationError as e:
            print(f"Authentication failed: {e}")  # Key 问题,不重试
            raise
        except RateLimitError:
            wait_time = 2 ** attempt
            print(f"Rate limited. Waiting {wait_time}s...")
            time.sleep(wait_time)
        except APIError as e:
            if attempt == max_retries - 1:
                raise
            print(f"API error: {e}. Retrying...")
            time.sleep(1)
    raise Exception("Max retries exceeded")
javascript
import OpenAI from 'openai';

const client = new OpenAI({ baseURL: 'https://hub.lurus.cn/v1', apiKey: 'sk-your-api-key' });

async function chatWithRetry(messages, maxRetries = 3) {
  for (let attempt = 0; attempt < maxRetries; attempt++) {
    try {
      return await client.chat.completions.create({ model: 'deepseek-chat', messages });
    } catch (error) {
      if (error.status === 401) throw error;  // 认证错误,不重试
      if (error.status === 429) {
        const wait = Math.pow(2, attempt) * 1000;
        console.log(`Rate limited. Waiting ${wait}ms...`);
        await new Promise(r => setTimeout(r, wait));
        continue;
      }
      if (attempt === maxRetries - 1) throw error;
      console.log(`Error: ${error.message}. Retrying...`);
      await new Promise(r => setTimeout(r, 1000));
    }
  }
}

Contact Support ​

Problem persists? Contact support@lurus.cn

Please provide the following information so we can locate the issue quickly:
  • The full error message
  • Request ID (response header X-Request-ID)
  • Time of occurrence
  • Steps to reproduce

Next Steps

Powered by Lurus Technologies