rohitg00/agentmemory · error · Error

VOYAGE_API_KEY is required

Error message

VOYAGE_API_KEY is required

What it means

VoyageEmbeddingProvider requires a Voyage AI API key from the constructor argument or the VOYAGE_API_KEY environment variable. If both are empty the constructor throws immediately.

Source

Thrown at src/providers/embedding/voyage.ts:14

import type { EmbeddingProvider } from "../../types.js";
import { getEnvVar } from "../../config.js";
import { fetchWithTimeout } from "../_fetch.js";

const API_URL = "https://api.voyageai.com/v1/embeddings";

export class VoyageEmbeddingProvider implements EmbeddingProvider {
  readonly name = "voyage";
  readonly dimensions = 1024;
  private apiKey: string;

  constructor(apiKey?: string) {
    this.apiKey = apiKey || getEnvVar("VOYAGE_API_KEY") || "";
    if (!this.apiKey) throw new Error("VOYAGE_API_KEY is required");
  }

  async embed(text: string): Promise<Float32Array> {
    const [result] = await this.embedBatch([text]);
    return result;
  }

  async embedBatch(texts: string[]): Promise<Float32Array[]> {
    const response = await fetchWithTimeout(API_URL, {
      method: "POST",
      headers: {
        Authorization: `Bearer ${this.apiKey}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        model: "voyage-code-3",
        input: texts,
        input_type: "document",

View on GitHub (pinned to e04ba88819)

Solutions

  1. Get a key at dashboard.voyageai.com and set VOYAGE_API_KEY in ~/.agentmemory/.env or the environment
  2. Pass it explicitly: new VoyageEmbeddingProvider(key)
  3. Verify the env var name is exactly VOYAGE_API_KEY and that dotenv loading happens before provider creation
  4. Choose a different provider type (openai/openrouter/local) if Voyage is not intended

Example fix

// before
const provider = new VoyageEmbeddingProvider(); // VOYAGE_API_KEY missing
// after
// ~/.agentmemory/.env: VOYAGE_API_KEY=pa-...
const provider = new VoyageEmbeddingProvider();
Defensive patterns

Strategy: validation

Validate before calling

const key = process.env.VOYAGE_API_KEY;
if (!key) throw new Error('Set VOYAGE_API_KEY before using the voyage embedding provider');
const provider = new VoyageEmbeddingProvider(key);

Type guard

const hasVoyageKey = (k: string | undefined): k is string => typeof k === 'string' && k.startsWith('pa-');

Try / catch

try {
  provider = new VoyageEmbeddingProvider();
} catch (err) {
  if (err instanceof Error && err.message === 'VOYAGE_API_KEY is required') {
    console.error('Get a key at dashboard.voyageai.com and set VOYAGE_API_KEY');
    process.exit(1);
  }
  throw err;
}

Prevention

When it happens

Trigger: Constructing `new VoyageEmbeddingProvider()` (or selecting type 'voyage' through createEmbeddingProvider) with no apiKey argument and VOYAGE_API_KEY unset in env or ~/.agentmemory/.env.

Common situations: Trying the voyage provider for its 1024-dim vectors without having a Voyage account/key; secrets provisioned for OpenAI but not Voyage; env var exported in one shell but not the service's environment; .env file path mismatch.

Understand the failure class

Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.

Related errors


AI-assisted analysis of rohitg00/agentmemory@e04ba88819 (2026-08-30). Data as JSON: /api/errors/ecd096738f52b722. Report an issue: GitHub.