mem0ai/mem0 · error · Error

Turbopuffer API key is required. Provide it via config.apiKe

Error message

Turbopuffer API key is required. Provide it via config.apiKey or the TURBOPUFFER_API_KEY environment variable.

What it means

The Turbopuffer vector store constructor requires an API key, resolved from config.apiKey or the TURBOPUFFER_API_KEY environment variable. If neither is set it throws immediately at construction time — before any network call — so this is purely a configuration error.

Source

Thrown at mem0-ts/src/oss/src/vector_stores/turbopuffer.ts:25

  region?: string;
  collectionName: string;
  distanceMetric?: string;
  batchSize?: number;
}

export class TurbopufferDB implements VectorStore {
  private clientInstance?: any;
  private clientPromise?: Promise<any>;
  private readonly apiKey: string;
  private readonly region: string;
  private readonly collectionName: string;
  private readonly distanceMetric: string;
  private readonly batchSize: number;

  constructor(config: TurbopufferConfig) {
    const apiKey = config.apiKey ?? process.env.TURBOPUFFER_API_KEY;
    if (!apiKey) {
      throw new Error(
        "Turbopuffer API key is required. Provide it via config.apiKey or the TURBOPUFFER_API_KEY environment variable.",
      );
    }

    this.apiKey = apiKey;
    this.region = config.region ?? "gcp-us-central1";
    this.collectionName = config.collectionName;
    this.distanceMetric = config.distanceMetric ?? "cosine_distance";
    this.batchSize = config.batchSize ?? 100;
  }

  /**
   * Lazily construct (or reuse) the Turbopuffer client, importing the optional
   * `@turbopuffer/turbopuffer` peer only when the store is first used so
   * consumers that never touch Turbopuffer don't need it installed.
   */
  private async getClient(): Promise<any> {
    if (this.clientInstance) return this.clientInstance;

View on GitHub (pinned to 001c235229)

Solutions

  1. Set TURBOPUFFER_API_KEY in the environment where the process runs (export it, add it to your platform's env settings).
  2. Pass the key explicitly in config: new Memory({ vectorStore: { provider: 'turbopuffer', config: { apiKey: process.env.TURBOPUFFER_API_KEY!, ... } } }).
  3. Get/verify the key from the Turbopuffer dashboard and confirm the exact variable name.

Example fix

// before
const memory = new Memory({ vectorStore: { provider: 'turbopuffer', config: { collectionName: 'mem' } } });

// after
const memory = new Memory({ vectorStore: { provider: 'turbopuffer', config: { collectionName: 'mem', apiKey: process.env.TURBOPUFFER_API_KEY! } } });
Defensive patterns

Strategy: validation

Validate before calling

if (!process.env.TURBOPUFFER_API_KEY) throw new Error('TURBOPUFFER_API_KEY missing — set it before constructing Memory');

Type guard

const hasTurbopufferCredentials = (cfg?: { apiKey?: string }): boolean => Boolean(cfg?.apiKey ?? process.env.TURBOPUFFER_API_KEY);

Try / catch

try { new Memory({ vectorStore: { provider: 'turbopuffer', config } }); } catch (e) { if (e instanceof Error && e.message.includes('Turbopuffer API key')) { failFastStartup('Missing TURBOPUFFER_API_KEY'); } else throw e; }

Prevention

When it happens

Trigger: Instantiating Memory with vectorStore provider 'turbopuffer' without passing config.apiKey and without TURBOPUFFER_API_KEY in the environment; deploying to a platform (Vercel, Docker, CI) where the env var was not propagated.

Common situations: Env var set in a local .env file but not loaded in the deployment environment; variable named differently (TURBOPUFFER_KEY, TP_API_KEY); serverless functions that don't inherit local shell env.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/90d0d072ac46b89b. Report an issue: GitHub.