Mintplex-Labs/anything-llm · error · RetryError

error.message

Error message

error.message

What it means

MoonshotAiProvider.stream() wraps failures from the streaming tool-call request to https://api.moonshot.ai/v1: OpenAI RateLimitError, InternalServerError, or any APIError is rethrown as aibitat's RetryError carrying the original message; AuthenticationError (invalid MOONSHOT_AI_API_KEY) is rethrown unwrapped; other errors pass through. The full error object is printed first via console.error, so the console log is the diagnostic source. RetryError tells the agent engine the failure is retryable, though non-transient 4xx causes (bad model id) get wrapped too.

Source

Thrown at server/utils/agents/aibitat/providers/moonshotAi.js:93

    try {
      return await tooledStream(
        this.client,
        this.model,
        messages,
        functions,
        eventHandler,
        { provider: this }
      );
    } catch (error) {
      console.error(error.message, error);
      if (error instanceof OpenAI.AuthenticationError) throw error;
      if (
        error instanceof OpenAI.RateLimitError ||
        error instanceof OpenAI.InternalServerError ||
        error instanceof OpenAI.APIError
      ) {
        throw new RetryError(error.message);
      }
      throw error;
    }
  }

  async complete(messages, functions = []) {
    const useNative = this.supportsNativeToolCalling();

    if (!useNative) {
      return await UnTooled.prototype.complete.call(
        this,
        messages,
        functions,
        this.#handleFunctionCallChat.bind(this)
      );
    }

    try {

View on GitHub (pinned to 3aec848f28)

Solutions

  1. Read the console log (raw error is printed here) and the status in the message: 429 -> back off and retry, 4xx -> fix model or key, 5xx -> retry later
  2. Verify MOONSHOT_AI_API_KEY with a direct curl to https://api.moonshot.ai/v1/models
  3. Pin a currently valid model id (e.g. from Moonshot's model list) in the provider config instead of an old default
  4. For repeated 429s, throttle agent tool-call concurrency or upgrade the key's rate tier

Example fix

# before
MOONSHOT_AI_API_KEY=<key>
# provider config model: moonshot-v1-32k (retired) -> 404 -> RetryError

# after
new MoonshotAiProvider({ model: "moonshot-v1-128k" })  # id confirmed via GET /v1/models
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-flight key + model
if (!process.env.MOONSHOT_AI_API_KEY) throw new Error("MOONSHOT_AI_API_KEY not set");
const models = await fetch("https://api.moonshot.ai/v1/models", {
  headers: { Authorization: `Bearer ${process.env.MOONSHOT_AI_API_KEY}` },
}).then(r => r.json());
if (!Array.isArray(models.data) || !models.data.some(m => m.id === provider.model)) throw new Error(`Unknown moonshot model ${provider.model}`);

Type guard

const { RetryError } = require("./server/utils/agents/aibitat/error.js");
const isRetryError = (e) => e instanceof RetryError;

Try / catch

try {
  return await provider.stream(messages, functions, eventHandler);
} catch (error) {
  if (error instanceof OpenAI.AuthenticationError) throw error; // 401: fix key, do not retry
  if (error instanceof RetryError && /429|5\d\d/.test(error.message)) return withBackoff(retryStream);
  throw error;
}

Prevention

When it happens

Trigger: Streaming chat.completions.create with apiKey process.env.MOONSHOT_AI_API_KEY returning 429 (Moonshot RPM/TPM tier limits — agent tool loops burst quickly), 5xx provider incidents, or 404/400 when this.model (default "moonshot-v1-32k") names a deprecated or non-existent model for the key's account.

Common situations: Moonshot renaming/retiring v1 model ids so the default stops resolving; free-tier keys hitting RPM limits as the agent fires tool-call round trips back-to-back; expired API key raising rejections on every request; transient 5xx during Moonshot maintenance windows.

Related errors


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