{"record":{"id":"5ba32e0bab48f92d","repo":"rohitg00/agentmemory","slug":"cohere-embedding-failed-response-status-er","errorCode":null,"errorMessage":"Cohere embedding failed (${response.status}): ${err}","messagePattern":"Cohere embedding failed \\((.+?)\\): (.+?)","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/providers/embedding/cohere.ts","lineNumber":38,"sourceCode":"  }\n\n  async embedBatch(texts: string[]): Promise<Float32Array[]> {\n    const response = await fetchWithTimeout(API_URL, {\n      method: \"POST\",\n      headers: {\n        Authorization: `Bearer ${this.apiKey}`,\n        \"Content-Type\": \"application/json\",\n      },\n      body: JSON.stringify({\n        model: \"embed-english-v3.0\",\n        texts,\n        input_type: \"search_document\",\n      }),\n    });\n\n    if (!response.ok) {\n      const err = await response.text();\n      throw new Error(`Cohere embedding failed (${response.status}): ${err}`);\n    }\n\n    const data = (await response.json()) as {\n      embeddings: number[][];\n    };\n\n    return data.embeddings.map((e) => new Float32Array(e));\n  }\n}\n","sourceCodeStart":20,"sourceCodeEnd":48,"githubUrl":"https://github.com/rohitg00/agentmemory/blob/e04ba88819c365c9acf9d6661ea802143e728bd6/src/providers/embedding/cohere.ts#L20-L48","documentation":"`embedBatch` calls Cohere's embedding HTTP API and throws this error when the response status is not ok, embedding the HTTP status code plus the raw response body. Unlike the constructor error, this is a runtime/network failure: the key existed but the API rejected the request (or the server returned 5xx).","triggerScenarios":"Any `embed()`/`embedBatch()` call where Cohere returns a non-2xx: invalid or revoked API key (401/403), model name not entitled (400/404), rate limit or quota exceeded (429), malformed input (empty texts, too-long input), or 5xx service errors.","commonSituations":"Key rotated/revoked in the Cohere dashboard while the process still holds the old one; free-trial trial-key limits on the embed model; sending batches exceeding Cohere's size limits; regional endpoint/network errors surfacing as 5xx; test key used in prod tenant.","solutions":["Read the embedded response body in the message — it contains Cohere's exact reason (invalid key, model not found, quota).","If 401/403: rotate to a fresh COHERE_API_KEY and restart the process.","If 429: add exponential backoff/retry with jitter around embedBatch calls, and reduce batch size/frequency.","If 400: check the `model` and `texts` payload — non-empty strings within length limits — and pin a model your key can access.","If 5xx: retry after a delay; if persistent, check Cohere's status page or switch providers."],"exampleFix":"// before\nconst vec = await provider.embed(text); // throws on 429/401 with raw body\n// after\ntry {\n  const vec = await provider.embed(text);\n} catch (e) {\n  if (/\\(429\\)/.test(e.message)) await sleep(backoff()); // then retry\n  else if (/\\((401|403)\\)/.test(e.message)) rotateCohereKey();\n  else throw e;\n}","handlingStrategy":"retry","validationCode":"// Preflight: cheap check that the key is at least shaped correctly\nif (!/^\\S{20,}$/.test(process.env.COHERE_API_KEY ?? \"\")) {\n  console.warn(\"COHERE_API_KEY looks invalid; API calls will likely 401\");\n}","typeGuard":null,"tryCatchPattern":"async function embedWithRetry(text: string, tries = 3) {\n  for (let i = 0; i < tries; i++) {\n    try { return await provider.embed(text); }\n    catch (e) {\n      const m = e instanceof Error ? e.message : String(e);\n      const status = Number(/Cohere embedding failed \\((\\d+)\\)/.exec(m)?.[1]);\n      if (status === 401 || status === 403 || (status >= 400 && status < 500 && status !== 429)) throw e;\n      await new Promise(r => setTimeout(r, 2 ** i * 500 + Math.random() * 250));\n    }\n  }\n  throw new Error(\"Cohere embed: retries exhausted\");\n}","preventionTips":["Rotate keys before expiry and reload config instead of holding long-lived processes with stale keys.","Respect Cohere rate limits: batch texts and add client-side throttling.","Log the response body from the error message — it names the exact API rejection reason.","Monitor 429 rates and back off globally (circuit breaker) rather than hammering."],"tags":["network","http","api-error","embeddings","cohere"],"backgroundTag":"http-api-error","analyzedSha":"e04ba88819c365c9acf9d6661ea802143e728bd6","analyzedAt":"2026-08-30T01:07:40.754Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}