continuedev/continue · error · Error

await resp.text()

Error message

await resp.text()

What it means

Thrown by Cohere embedder._embed when the POST to the Cohere embeddings endpoint returns a non-2xx status; the raw response body text becomes the error message. The body typically contains Cohere's JSON error describing the actual failure (invalid API key, invalid model, too many inputs).

Source

Thrown at core/llm/llms/Cohere.ts:300

  protected async _embed(chunks: string[]): Promise<number[][]> {
    const resp = await this.fetch(new URL("embed", this.apiBase), {
      method: "POST",
      body: JSON.stringify({
        texts: chunks,
        model: this.model,
        input_type: "search_document",
        embedding_types: ["float"],
        truncate: "END",
      }),
      headers: {
        Authorization: `Bearer ${this.apiKey}`,
        "Content-Type": "application/json",
      },
    });

    if (!resp.ok) {
      throw new Error(await resp.text());
    }

    const data = (await resp.json()) as any;
    return data.embeddings.float;
  }

  async rerank(query: string, chunks: Chunk[]): Promise<number[]> {
    const resp = await this.fetch(new URL("rerank", this.apiBase), {
      method: "POST",
      headers: {
        Authorization: `Bearer ${this.apiKey}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        model: this.model,
        query,
        documents: chunks.map((chunk) => chunk.content),
      }),

View on GitHub (pinned to 5522c6f44c)

Solutions

  1. Read the response body in the message: it names the exact Cohere error (invalid api token, model not found, etc.)
  2. Verify COHERE_API_KEY is set and valid with a curl test against https://api.cohere.com/v2/embed
  3. Confirm the embedding model name exists on your Cohere account/tier
  4. Batch inputs to <=96 per call and chunk oversized text

Example fix

// before
const embeddings = await embedder.embed(allTexts);
// after
const embeddings = [];
for (let i = 0; i < allTexts.length; i += 96) {
  embeddings.push(...await embedder.embed(allTexts.slice(i, i + 96)));
}
Defensive patterns

Strategy: validation

Validate before calling

if (!process.env.COHERE_API_KEY) throw new Error('COHERE_API_KEY missing');
const inputs = texts.slice(0, 96); // Cohere batch limit

Type guard

function isCohereEmbedError(e: unknown): e is Error {
  return e instanceof Error && /invalid|embed|token|limit/i.test(e.message) && !(e instanceof TypeError);
}

Try / catch

try {
  await embedder.embed(batch);
} catch (e) {
  if (e instanceof Error && e.message.includes('invalid api token')) throw new ConfigError('Bad COHERE_API_KEY');
  throw e;
}

Prevention

When it happens

Trigger: Calling embed() with a bad/expired Cohere API key (401), using an embedding model name your key cannot access (404/400), exceeding batch size limits (inputs array too large, 400), or a rate-limited key (429).

Common situations: Wrong COHERE_API_KEY env var, using embed-english-v3.0 vs embed-v4.0 model name mismatches, embedding hundreds of chunks in one call exceeding the 96-input batch limit.

Related errors


AI-assisted analysis of continuedev/continue@5522c6f44c (2026-08-27). Data as JSON: /api/errors/7d7beaa9a4b307a7. Report an issue: GitHub.