Mintplex-Labs/anything-llm · error
OpenRouter Failed to embed
Error message
OpenRouter Failed to embed: ${error} What it means
The aggregate wrapper thrown at the end of OpenRouterEmbedder.embedChunks() when one or more batched embedding requests to https://openrouter.ai/api/v1/embeddings failed. Distinct error messages are joined after the prefix and partial data is discarded. The suffix usually carries OpenRouter's own status text: 429 rate limit, 401/402 auth or credit issues, 404 unknown model, or upstream provider errors.
Solutions
- Read the suffix — it is OpenRouter's literal error message and determines the fix.
- On 402/401: add credit or refresh OPENROUTER_API_KEY.
- On 404/model errors: pick a model from OpenRouter's /api/v1/embeddings/models list (e.g. baai/bge-m3).
- On 429: slow down ingestion and retry; embedding requests count against the same limits as chat.
Defensive patterns
Strategy: retry
Try / catch
async function embedWithRetry(embedder, chunks, maxAttempts = 4) {
for (let i = 1; ; i++) {
try {
return await embedder.embedChunks(chunks);
} catch (err) {
const msg = err.message;
const transient = msg.includes("429") || msg.includes("Rate limit");
if (transient && i < maxAttempts) {
await new Promise((r) => setTimeout(r, i * 10_000));
continue;
}
throw err; // 401/402 (auth/credit) and 404 (model) are not retryable
}
}
} Prevention
- Confirm EMBEDDING_MODEL_PREF appears in OpenRouter's /api/v1/embeddings/models list.
- Keep OpenRouter credit topped up before bulk ingestion.
- Classify by the error suffix before retrying.
When it happens
Trigger: Out of OpenRouter credits (402); 429 when embedding a large document quickly; EMBEDDING_MODEL_PREF set to a model that is not an OpenRouter embedding model (404/no endpoints); the key was revoked; upstream provider outages surfaced through OpenRouter.
Common situations: First big workspace sync on a new OpenRouter account; switching EMBEDDING_MODEL_PREF to a chat model id; free-tier keys hitting RPM limits.
Related errors
- OpenAI Failed to embed
- error.message
- Gemini Failed to embed
- GenericOpenAI Failed to embed
- LiteLLM Failed to embed
AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18).
Data as JSON: /api/errors/11ab5ed75d4432a0.
Report an issue: GitHub.
Appendix: source
Thrown at server/utils/EmbeddingEngines/openRouter/index.js:94
.flat();
if (errors.length > 0) {
let uniqueErrors = new Set();
errors.map((error) =>
uniqueErrors.add(`[${error.type}]: ${error.message}`)
);
return {
data: [],
error: Array.from(uniqueErrors).join(", "),
};
}
return {
data: results.map((res) => res?.data || []).flat(),
error: null,
};
});
if (!!error) throw new Error(`OpenRouter Failed to embed: ${error}`);
return data.length > 0 &&
data.every((embd) => embd.hasOwnProperty("embedding"))
? data.map((embd) => embd.embedding)
: null;
}
}
async function fetchOpenRouterEmbeddingModels() {
return await fetch(`https://openrouter.ai/api/v1/embeddings/models`, {
method: "GET",
headers: { "Content-Type": "application/json" },
})
.then((res) => res.json())
.then(({ data = [] }) => {
const models = {};
data.forEach((model) => {
models[model.id] = {
id: model.id,View on GitHub (pinned to 3aec848f28)