Mintplex-Labs/anything-llm · error · Error

e.message

Error message

e.message

What it means

GiteeAILLM.getChatCompletion rethrows e.message from the OpenAI SDK call to https://ai.gitee.com/v1. It is a passthrough of Gitee AI's HTTP errors: 401 invalid token, 404 unknown model id (this.model defaults to '' when no pref is set, guaranteeing a bad request), 429 rate limits, or network failures to the Gitee endpoint.

Solutions

  1. Set a valid model via GITEE_AI_MODEL_PREF or the workspace model picker (this class defaults the model to '' which always fails)
  2. If the inner message says 401/unauthorized, regenerate the Gitee AI token and update GITEE_AI_API_KEY
  3. If 429, respect Gitee AI rate limits / check quota
  4. Verify egress: curl -H "Authorization: Bearer $GITEE_AI_API_KEY" https://ai.gitee.com/v1/models

Example fix

# before (.env)
GITEE_AI_API_KEY=... # no model -> model:"" sent

# after (.env)
GITEE_AI_API_KEY=...
GITEE_AI_MODEL_PREF=Qwen2.5-72B-Instruct
Defensive patterns

Strategy: try-catch

Validate before calling

// this class defaults this.model to '' — never chat without an explicit model
const model = modelPreference || process.env.GITEE_AI_MODEL_PREF;
if (!model) return respond("Select a Gitee AI model first (GITEE_AI_MODEL_PREF or workspace setting).");
// optional: verify it against the live catalog
const r = await fetch("https://ai.gitee.com/v1/models", { headers: { Authorization: `Bearer ${process.env.GITEE_AI_API_KEY}` } });
if (r.status === 401) return respond("Gitee AI token invalid/expired.");

Try / catch

try {
  return await llm.getChatCompletion(messages);
} catch (err) {
  if (/401|Unauthorized/i.test(err.message)) return respond("Regenerate your Gitee AI access token.");
  if (/404|model/i.test(err.message)) return respond("Model id not found on Gitee AI — re-select it.");
  if (/429|rate/i.test(err.message)) return backoffAndRetry();
  throw err;
}

Prevention

When it happens

Trigger: Chat request where this.model is '' (no GITEE_AI_MODEL_PREF and no workspace preference), the token is expired/revoked, the model id isn't served by Gitee AI, or the server has no egress to ai.gitee.com.

Common situations: Provider configured with a key but no model pref, so the request carries model:''; Gitee token rotated but .env still holds the old one; model id copied from Gitee's docs pages with wrong casing.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18). Data as JSON: /api/errors/df2a4308dc0ed6a7. Report an issue: GitHub.

Appendix: source

Thrown at server/utils/AiProviders/giteeai/index.js:131

    let textResponse = message?.content;
    if (
      !!message?.reasoning_content &&
      message.reasoning_content.trim().length > 0
    )
      textResponse = `<think>${message.reasoning_content}</think>${textResponse}`;
    return textResponse;
  }

  async getChatCompletion(messages = null, { temperature = 0.7 }) {
    const result = await LLMPerformanceMonitor.measureAsyncFunction(
      this.openai.chat.completions
        .create({
          model: this.model,
          messages,
          temperature,
        })
        .catch((e) => {
          throw new Error(e.message);
        })
    );

    if (
      !result?.output?.hasOwnProperty("choices") ||
      result?.output?.choices?.length === 0
    )
      throw new Error(
        `Invalid response body returned from GiteeAI: ${JSON.stringify(result.output)}`
      );

    return {
      textResponse: this.#parseReasoningFromResponse(result.output.choices[0]),
      metrics: {
        prompt_tokens: result.output.usage.prompt_tokens || 0,
        completion_tokens: result.output.usage.completion_tokens || 0,
        total_tokens: result.output.usage.total_tokens || 0,
        outputTps: result.output.usage.completion_tokens / result.duration,

View on GitHub (pinned to 3aec848f28)