mem0ai/mem0 · critical · Error

Pinecone API key required: pass apiKey or set PINECONE_API_K

Error message

Pinecone API key required: pass apiKey or set PINECONE_API_KEY env var

What it means

The Pinecone vector store requires an API key. At construction it checks config.client (a pre-built Pinecone client), then config.apiKey, then the PINECONE_API_KEY environment variable. If none is present it throws immediately, because every subsequent Pinecone HTTP call needs the key.

Source

Thrown at mem0-ts/src/oss/src/vector_stores/pinecone.ts:54

  private readonly batchSize: number;
  private readonly namespace: string;
  private readonly serverlessConfig?: { cloud: string; region: string };
  private readonly podConfig?: {
    environment: string;
    podType?: string;
    pods?: number;
    replicas?: number;
    shards?: number;
  };
  private readonly extraParams: Record<string, any>;
  private _index?: Index;
  private _initPromise?: Promise<void>;

  constructor(config: PineconeDBConfig) {
    if (!config.client) {
      const apiKey = config.apiKey || process.env.PINECONE_API_KEY;
      if (!apiKey) {
        throw new Error(
          "Pinecone API key required: pass apiKey or set PINECONE_API_KEY env var",
        );
      }
    }

    this.config = config;
    this.collectionName = config.collectionName;
    this.dimension = config.embeddingModelDims || config.dimension || 1536;
    this.metric = config.metric || "cosine";
    this.batchSize = config.batchSize || 100;
    this.namespace = config.namespace || "";
    this.serverlessConfig = config.serverlessConfig;
    this.podConfig = config.podConfig;
    this.extraParams = config.extraParams || {};

    this.initialize().catch(console.error);
  }

View on GitHub (pinned to 001c235229)

Solutions

  1. Set PINECONE_API_KEY in the environment: export PINECONE_API_KEY=pckey_...
  2. Or pass it explicitly: new Pinecone({ apiKey: process.env.PINECONE_API_KEY, collectionName: 'x' })
  3. If you already have a configured Pinecone client, pass it via the client config field to skip key resolution
  4. In containers/CI, add the variable to the environment/secrets configuration and verify with printenv PINECONE_API_KEY

Example fix

// before
const vs = new Pinecone({ collectionName: 'memories' });

// after
const vs = new Pinecone({
  apiKey: process.env.PINECONE_API_KEY!,
  collectionName: 'memories',
});
Defensive patterns

Strategy: validation

Validate before calling

function assertPineconeConfig(c: any): void {
  if (!c?.client && !c?.apiKey && !process.env.PINECONE_API_KEY) {
    throw new Error('Missing Pinecone API key: set PINECONE_API_KEY or pass apiKey/client');
  }
}
assertPineconeConfig(pineconeConfig);

Type guard

const hasPineconeAuth = (c: any): boolean =>
  !!c?.client || !!c?.apiKey || !!process.env.PINECONE_API_KEY;

Try / catch

try { const vs = new Pinecone(config); } catch (e) { if (e instanceof Error && e.message.includes('Pinecone API key required')) { /* surface config error to operator; not retryable */ } throw e; }

Prevention

When it happens

Trigger: new Pinecone({ collectionName: 'x' }) with no apiKey and no PINECONE_API_KEY in the environment; running locally where .env is not loaded; deploying to a container whose secrets/env config omitted the variable; CI runs without the env var.

Common situations: Forgetting to export PINECONE_API_KEY in a new shell; dotenv file present but not imported before constructing the store; environment variable name typo (PINECONE_TOKEN); rotating keys and removing the old var before adding the new one.

Related errors


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