{"record":{"id":"360ff021173fe66d","repo":"Mintplex-Labs/anything-llm","slug":"genericopenai-failed-to-embed-error-message","errorCode":null,"errorMessage":"GenericOpenAI Failed to embed: ${error.message}","messagePattern":"GenericOpenAI Failed to embed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/EmbeddingEngines/genericOpenAi/index.js","lineNumber":156,"sourceCode":"          .create({\n            model: this.model,\n            input: chunk,\n          })\n          .then((result) => resolve({ data: result?.data, error: null }))\n          .catch((e) => {\n            e.type =\n              e?.response?.data?.error?.code ||\n              e?.response?.status ||\n              \"failed_to_embed\";\n            e.message = e?.response?.data?.error?.message || e.message;\n            resolve({ data: [], error: e });\n          });\n      });\n\n      // If any errors were returned from OpenAI abort the entire sequence because the embeddings\n      // will be incomplete.\n      if (error)\n        throw new Error(`GenericOpenAI Failed to embed: ${error.message}`);\n      allResults.push(...(data || []));\n      reportEmbeddingProgress(allResults.length, textChunks.length);\n      if (this.apiRequestDelay) await this.runDelay();\n    }\n\n    return allResults.length > 0 &&\n      allResults.every((embd) => embd.hasOwnProperty(\"embedding\"))\n      ? allResults.map((embd) => embd.embedding)\n      : null;\n  }\n}\n\nmodule.exports = {\n  GenericOpenAiEmbedder,\n};\n","sourceCodeStart":138,"sourceCodeEnd":172,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/EmbeddingEngines/genericOpenAi/index.js#L138-L172","documentation":"Thrown from GenericOpenAiEmbedder.embedChunks when any single chunk request fails; the loop aborts the whole sequence because partial embeddings would be incomplete. The error object is normalized first (type from error.code/status, message from the response body), so the thrown text after the colon is the upstream endpoint's own message.","triggerScenarios":"401 from a server that requires a key when GENERIC_OPEN_AI_EMBEDDING_API_KEY is null or wrong; POST {EMBEDDING_BASE_PATH}/embeddings returning 404 because the base path is wrong (missing /v1 or points at a non-OpenAI route); model name in EMBEDDING_MODEL_PREF unknown to the server; 429 rate limiting on small self-hosted or shared endpoints; input text longer than the server's context window.","commonSituations":"Self-hosted single-threaded backends that 429 under AnythingLLM's batch load; pointing at Ollama's /v1 with a model id that is not pulled; using an OpenAI-compatible facade that does not implement /embeddings; very large documents blowing the max chunk length.","solutions":["Inspect error.message — it is the literal response body from your server","For 401s, set GENERIC_OPEN_AI_EMBEDDING_API_KEY (or fix it) to a valid key for that endpoint","For 404s, correct EMBEDDING_BASE_PATH so it is the OpenAI-compatible root (commonly ends in /v1)","For 429s, set GENERIC_OPEN_AI_EMBEDDING_API_DELAY_MS (minimum 500) to throttle between batches","For context-length errors, lower EMBEDDING_MODEL_MAX_CHUNK_LENGTH","Verify EMBEDDING_MODEL_PREF exactly matches a model id the endpoint serves"],"exampleFix":"# before\nEMBEDDING_BASE_PATH=http://localhost:8080\n# 404: SDK posts to /embeddings at server root\n\n# after\nEMBEDDING_BASE_PATH=http://localhost:8080/v1\nGENERIC_OPEN_AI_EMBEDDING_API_DELAY_MS=500","handlingStrategy":"try-catch","validationCode":"// Smoke-test the endpoint before a bulk run: one tiny embedding must round-trip\nasync function genericOpenAiEmbedderHealthy(openai, model) {\n  try {\n    const res = await openai.embeddings.create({ model, input: [\"ping\"] });\n    return Array.isArray(res?.data?.[0]?.embedding);\n  } catch (e) {\n    console.error(\"Embedding pre-flight failed:\", e.status, e.message);\n    return false;\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  const vectors = await embedder.embedTextInput(text);\n} catch (e) {\n  if (e.message.startsWith(\"GenericOpenAI Failed to embed:\")) {\n    const msg = e.message;\n    if (/401|unauthorized/i.test(msg)) { /* fix GENERIC_OPEN_AI_EMBEDDING_API_KEY; do not retry */ }\n    else if (/429|rate/i.test(msg)) { /* wait, then retry; consider GENERIC_OPEN_AI_EMBEDDING_API_DELAY_MS */ }\n    else if (/404|not found/i.test(msg)) { /* fix EMBEDDING_BASE_PATH or EMBEDDING_MODEL_PREF; do not retry */ }\n    else throw e;\n  } else throw e;\n}","preventionTips":["Set GENERIC_OPEN_AI_EMBEDDING_API_DELAY_MS (>=500) when the backend is rate-limit-prone","Keep EMBEDDING_MODEL_MAX_CHUNK_LENGTH within the target model's context so oversized chunks never reach the API","Remember the loop aborts on first error — after a fix, re-embed the whole document, not the remainder"],"tags":["generic-openai","embeddings","api-error","rate-limit","base-url"],"backgroundTag":"embedding-api-request-failed","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}