{"record":{"id":"9aa072b77f33d700","repo":"rohitg00/agentmemory","slug":"openai-embedding-failed-response-status-er","errorCode":null,"errorMessage":"OpenAI embedding failed (${response.status}): ${err}","messagePattern":"OpenAI embedding failed \\((.+?)\\): (.+?)","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/providers/embedding/openai.ts","lineNumber":114,"sourceCode":"\n  async embedBatch(texts: string[]): Promise<Float32Array[]> {\n    const url = buildEmbeddingUrl(\n      this.baseUrl,\n      this.isAzure,\n      this.azureApiVersion,\n    );\n    const response = await fetchWithTimeout(url, {\n      method: \"POST\",\n      headers: buildAuthHeaders(this.apiKey, this.isAzure),\n      body: JSON.stringify({\n        model: this.model,\n        input: texts,\n      }),\n    });\n\n    if (!response.ok) {\n      const err = await response.text();\n      throw new Error(`OpenAI embedding failed (${response.status}): ${err}`);\n    }\n\n    const data = (await response.json()) as {\n      data: Array<{ embedding: number[] }>;\n    };\n\n    return data.data.map((d) => new Float32Array(d.embedding));\n  }\n}\n","sourceCodeStart":96,"sourceCodeEnd":124,"githubUrl":"https://github.com/rohitg00/agentmemory/blob/e04ba88819c365c9acf9d6661ea802143e728bd6/src/providers/embedding/openai.ts#L96-L124","documentation":"The OpenAI embedding endpoint (/v1/embeddings) returned a non-2xx HTTP status. embedBatch reads the raw response body into `err` and throws it with the status code, surfacing provider-side rejections such as auth failures, bad model names, or rate limits.","triggerScenarios":"Calling embed()/embedBatch() when the POST to the embeddings endpoint fails: 401 invalid key, 404 unknown model, 429 quota/rate limit, 400 malformed input (empty array, text too long), 5xx OpenAI outage.","commonSituations":"Revoked or wrong-project API key; model name typo (text-embedding-3-small vs -001 legacy); exceeding tokens-per-minute limits during bulk embedding; base URL pointing to a proxy that doesn't implement /embeddings; org blocked for region.","solutions":["Read the status and body in the message: 401 -> fix OPENAI_API_KEY; 404 -> fix model name; 429 -> add backoff/retry and reduce batch size","Verify the model id against current OpenAI docs and your project's access list","Reduce input batch size and total tokens per request","Check OPENAI_EMBEDDING_BASE_URL — ensure the endpoint actually serves /embeddings"],"exampleFix":"// before: bulk embed hits 429\nawait provider.embedBatch(thousandTexts);\n// after: bounded batches + retry on 429\nfor (const chunk of chunkArray(texts, 100)) {\n  await withRetry(() => provider.embedBatch(chunk), { retries: 3, on: 429 });\n}","handlingStrategy":"retry","validationCode":"if (!process.env.OPENAI_API_KEY && !process.env.OPENAI_EMBEDDING_API_KEY) throw new Error('OpenAI key missing');\nif (!/^text-embedding-\\d+/.test(model)) console.warn(`Suspicious embedding model id: ${model}`);","typeGuard":"const isOk = (r: Response): r is Response & { ok: true } => r.ok;","tryCatchPattern":"try {\n  return await provider.embedBatch(texts);\n} catch (err) {\n  const msg = String((err as Error).message);\n  const m = msg.match(/OpenAI embedding failed \\((\\d+)\\)/);\n  if (m) {\n    const status = Number(m[1]);\n    if (status === 429 || status >= 500) return withBackoff(() => provider.embedBatch(texts));\n    if (status === 401) throw new Error('Fix OPENAI_API_KEY');\n    if (status === 404) throw new Error(`Unknown embedding model: ${model}`);\n  }\n  throw err;\n}","preventionTips":["Map statuses to actions: 401 credentials, 404 model, 429/5xx retry with backoff","Cap batch size (~100 texts) to stay under token/rate limits","Monitor the embeddings endpoint status page during bulk jobs","Verify proxy OPENAI_EMBEDDING_BASE_URL implements /v1/embeddings"],"tags":["openai","http-error","network","embedding"],"backgroundTag":"upstream-http-error","analyzedSha":"e04ba88819c365c9acf9d6661ea802143e728bd6","analyzedAt":"2026-08-30T01:07:40.754Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}