{"record":{"id":"cd95fcd1992643e0","repo":"Mintplex-Labs/anything-llm","slug":"openai-failed-to-embed-error","errorCode":null,"errorMessage":"OpenAI Failed to embed: ${error}","messagePattern":"OpenAI Failed to embed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/EmbeddingEngines/openAi/index.js","lineNumber":92,"sourceCode":"        .flat();\n      if (errors.length > 0) {\n        let uniqueErrors = new Set();\n        errors.map((error) =>\n          uniqueErrors.add(`[${error.type}]: ${error.message}`)\n        );\n\n        return {\n          data: [],\n          error: Array.from(uniqueErrors).join(\", \"),\n        };\n      }\n      return {\n        data: results.map((res) => res?.data || []).flat(),\n        error: null,\n      };\n    });\n\n    if (!!error) throw new Error(`OpenAI Failed to embed: ${error}`);\n    return data.length > 0 &&\n      data.every((embd) => embd.hasOwnProperty(\"embedding\"))\n      ? data.map((embd) => embd.embedding)\n      : null;\n  }\n}\n\nmodule.exports = {\n  OpenAiEmbedder,\n};\n","sourceCodeStart":74,"sourceCodeEnd":103,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/EmbeddingEngines/openAi/index.js#L74-L103","documentation":"Thrown at the end of embedChunks after Promise.all when any concurrent batch to OpenAI failed. Batches of maxConcurrentChunks (500) are sent via embeddings.create; each rejection is caught and resolved as {data:[],error:e}, errors are deduplicated into [type]: message, and any error aborts the whole sequence to avoid gaps in the vector data. This is the canonical batched-embed failure path shared with the LiteLLM/LocalAI embedders.","triggerScenarios":"One or more batched /v1/embeddings calls rejecting: 401 bad/expired key; 429 rate limit / quota exhausted; 404 unknown model (e.g. EMBEDDING_MODEL_PREF set to a deprecated id); 400 input too long for the model's token limit; 5xx OpenAI outage; batch exceeding 8191 token embeddingMaxChunkLength for ada-002.","commonSituations":"Quota/billing exhaustion; deprecated model id (text-embedding-ada-002 replaced by v3); chunk size larger than the model's context; concurrent jobs spiking past the tokens-per-minute limit; org-level rate limits; transient api.openai.com 5xx.","solutions":["Decode the joined [type]: message — 401 -> fix OPEN_AI_KEY; 429 -> reduce batch size / add backoff / raise TPM limit; 404 -> switch EMBEDDING_MODEL_PREF to a current model (text-embedding-3-small/large)","Ensure document chunks are within the model's context (8191 tokens for ada-002; larger for v3)","Add bounded retry with exponential backoff in the caller for 429/5xx","Check status.openai.com for ongoing incidents"],"exampleFix":"// before\nEMBEDDING_MODEL_PREF=text-embedding-ada-002  // hits 429/404 depending on account\n\n// after\nEMBEDDING_MODEL_PREF=text-embedding-3-small","handlingStrategy":"retry","validationCode":"// confirm model + a working call before a large ingest\nasync function openAiEmbeds(openai, model, sample = 'hello') {\n  const r = await openai.embeddings.create({ model, input: sample });\n  return Array.isArray(r.data?.[0]?.embedding);\n}","typeGuard":"function isOpenAiEmbedError(e) {\n  return e instanceof Error && /OpenAI Failed to embed/.test(e.message);\n}","tryCatchPattern":"async function embedWithRetry(embedder, chunks, attempts = 3) {\n  for (let i = 0; i < attempts; i++) {\n    try { return await embedder.embedChunks(chunks); }\n    catch (e) {\n      const transient = /429|5\\d\\d|ETIMEDOUT|Failed to fetch/.test(e.message);\n      if (!transient || i === attempts - 1) throw e;\n      await new Promise(r => setTimeout(r, 2 ** i * 1000));\n    }\n  }\n}","preventionTips":["Keep chunk size within the model's token limit (8191 for ada-002).","Use a current model id (text-embedding-3-small/large) to avoid 404s.","Add backoff for 429/5xx; check status.openai.com before deep debugging."],"tags":["openai","embedding","runtime","auth","rate-limit","upstream"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}