Mintplex-Labs/anything-llm · error · RetryError
error.message
Error message
error.message
What it means
OpenRouterProvider.stream() catches failures from the streaming tool-call request to https://openrouter.ai/api/v1 and rethrows OpenAI RateLimitError, InternalServerError, or any APIError as aibitat's RetryError with the original message; AuthenticationError is rethrown raw; other errors pass through. The raw error is console.error'd first, so the console holds the full object. On OpenRouter, 429 can mean your key's limit OR the routed upstream provider's limit, and a 402 (insufficient credits, PaymentRequiredError extends APIError) also lands in this wrap.
Source
Thrown at server/utils/agents/aibitat/providers/openrouter.js:111
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;
}
}
/**
* Create a non-streaming completion with tool calling support.
* Uses native tool calling when enabled via ENV, otherwise falls back to UnTooled.
*/
async complete(messages, functions = []) {
const useNative = await this.supportsNativeToolCalling();
if (!useNative) {
return await UnTooled.prototype.complete.call(
this,
messages,
functions,
this.#handleFunctionCallChat.bind(this)View on GitHub (pinned to 3aec848f28)
Solutions
- Read the console log for the raw error: 402 -> add credits (retrying never helps), 429 -> check whether it's your key or the upstream model, 404 -> fix the slug
- Verify OPENROUTER_API_KEY and account credits in the OpenRouter dashboard
- Confirm the model slug exists at openrouter.ai/models (or fall back to openrouter/auto)
- For upstream 429s, pin a different provider variant of the same model or wait out the window
Example fix
# before OPENROUTER_API_KEY=<key> # account has 0 credits -> 402 -> RetryError every call # after: top up credits, and pin a valid slug # agent config: model = "openai/gpt-4o-mini"
Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-flight: key valid, credits available, slug listed
const res = await fetch("https://openrouter.ai/api/v1/models", {
headers: { Authorization: `Bearer ${process.env.OPENROUTER_API_KEY}` },
});
if (!res.ok) throw new Error(`OpenRouter pre-flight failed (${res.status}) — check OPENROUTER_API_KEY`);
// Also check credits: GET https://openrouter.ai/api/v1/credits Type guard
const { RetryError } = require("./server/utils/agents/aibitat/error.js");
const isRetryError = (e) => e instanceof RetryError;
const isCreditExhausted = (e) => isRetryError(e) && /402|credit|payment/i.test(String(e.message)); Try / catch
try {
return await provider.stream(messages, functions, eventHandler);
} catch (error) {
if (error instanceof OpenAI.AuthenticationError) throw error;
if (isCreditExhausted(error)) throw new Error("OpenRouter credits exhausted — top up (not retryable)");
if (error instanceof RetryError && /429|5\d\d/.test(error.message)) return withBackoff(retryStream);
throw error;
} Prevention
- Check the OpenRouter credits endpoint on a schedule; 402 wraps as RetryError but is never retryable
- Pin specific vendor slugs you've verified, or use openrouter/auto with fallbacks configured
- For 429s, look at the message to see if it's your key or the upstream provider that's limited, then switch variants
- Correlate with the console log — the raw error is printed at this site
When it happens
Trigger: Streaming chat.completions.create with OPENROUTER_API_KEY returning 429 (key rate limit or upstream provider rate limit passed through), 402 when the OpenRouter account is out of credits, 404/400 when this.model (default "openrouter/auto" or a pinned slug) is invalid or has no available upstream, 5xx on routing failures.
Common situations: Trial credit exhausted so every call returns 402 wrapped as RetryError; ':free' model slugs rate-limited per day; pinned model slug removed from the OpenRouter catalog; upstream provider (e.g. a specific vendor) down while openrouter/auto routes into it.
Related errors
AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18).
Data as JSON: /api/errors/4932d371c4685860.
Report an issue: GitHub.