Mintplex-Labs/anything-llm · error

OpenAI Failed to embed

Error message

OpenAI Failed to embed: ${error}

What it means

Thrown at the end of OpenAiEmbedder.embedChunks() when one or more chunked embeddings.create() requests failed. Distinct error messages from the batched requests are joined with commas after the prefix, and partial results are discarded. Typical suffixes are 429 rate limit, 401 invalid key, 400 invalid_request (chunk exceeds the model's token limit), or network errors.

Solutions

  1. Read the joined suffix — it contains the literal OpenAI error(s) and dictates the fix.
  2. On 429: back off and retry later; lower ingestion concurrency and consider text-embedding-3-small.
  3. On 401/403: update/rotate OPEN_AI_KEY and confirm billing is active.
  4. On 400 invalid input: reduce document chunk size so no chunk exceeds the model's token limit.
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") || msg.includes("timeout");
      if (transient && i < maxAttempts) {
        await new Promise((r) => setTimeout(r, i * 10_000)); // exponential-ish backoff
        continue;
      }
      throw err; // 401/400-class causes need human fixes, not retries
    }
  }
}

Prevention

When it happens

Trigger: 429 from OpenAI when embedding large documents (the engine sends up to 500 strings per request); 401/403 after the key was revoked or exhausted billing; invalid_request_error when a chunk exceeds the 8191-token embeddingMaxChunkLength of ada-002/3-small; connection timeouts on very large inputs.

Common situations: Bulk ingestion of big workspaces on a fresh key; using text-embedding-ada-002 with oversized chunks; multiple instances sharing one key during initial sync.

Related errors


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

Appendix: source

Thrown at server/utils/EmbeddingEngines/openAi/index.js:92

        .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(`OpenAI Failed to embed: ${error}`);
    return data.length > 0 &&
      data.every((embd) => embd.hasOwnProperty("embedding"))
      ? data.map((embd) => embd.embedding)
      : null;
  }
}

module.exports = {
  OpenAiEmbedder,
};

View on GitHub (pinned to 3aec848f28)