{"record":{"id":"e1c6874f67769415","repo":"mem0ai/mem0","slug":"pinecone-api-key-required-pass-apikey-or-set-pine","errorCode":null,"errorMessage":"Pinecone API key required: pass apiKey or set PINECONE_API_KEY env var","messagePattern":"Pinecone API key required: pass apiKey or set PINECONE_API_KEY env var","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"mem0-ts/src/oss/src/vector_stores/pinecone.ts","lineNumber":54,"sourceCode":"  private readonly batchSize: number;\n  private readonly namespace: string;\n  private readonly serverlessConfig?: { cloud: string; region: string };\n  private readonly podConfig?: {\n    environment: string;\n    podType?: string;\n    pods?: number;\n    replicas?: number;\n    shards?: number;\n  };\n  private readonly extraParams: Record<string, any>;\n  private _index?: Index;\n  private _initPromise?: Promise<void>;\n\n  constructor(config: PineconeDBConfig) {\n    if (!config.client) {\n      const apiKey = config.apiKey || process.env.PINECONE_API_KEY;\n      if (!apiKey) {\n        throw new Error(\n          \"Pinecone API key required: pass apiKey or set PINECONE_API_KEY env var\",\n        );\n      }\n    }\n\n    this.config = config;\n    this.collectionName = config.collectionName;\n    this.dimension = config.embeddingModelDims || config.dimension || 1536;\n    this.metric = config.metric || \"cosine\";\n    this.batchSize = config.batchSize || 100;\n    this.namespace = config.namespace || \"\";\n    this.serverlessConfig = config.serverlessConfig;\n    this.podConfig = config.podConfig;\n    this.extraParams = config.extraParams || {};\n\n    this.initialize().catch(console.error);\n  }\n","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/vector_stores/pinecone.ts#L36-L72","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set PINECONE_API_KEY in the environment: export PINECONE_API_KEY=pckey_...","Or pass it explicitly: new Pinecone({ apiKey: process.env.PINECONE_API_KEY, collectionName: 'x' })","If you already have a configured Pinecone client, pass it via the client config field to skip key resolution","In containers/CI, add the variable to the environment/secrets configuration and verify with printenv PINECONE_API_KEY"],"exampleFix":"// before\nconst vs = new Pinecone({ collectionName: 'memories' });\n\n// after\nconst vs = new Pinecone({\n  apiKey: process.env.PINECONE_API_KEY!,\n  collectionName: 'memories',\n});","handlingStrategy":"validation","validationCode":"function assertPineconeConfig(c: any): void {\n  if (!c?.client && !c?.apiKey && !process.env.PINECONE_API_KEY) {\n    throw new Error('Missing Pinecone API key: set PINECONE_API_KEY or pass apiKey/client');\n  }\n}\nassertPineconeConfig(pineconeConfig);","typeGuard":"const hasPineconeAuth = (c: any): boolean =>\n  !!c?.client || !!c?.apiKey || !!process.env.PINECONE_API_KEY;","tryCatchPattern":"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; }","preventionTips":["Load dotenv before any store construction","Add a startup check listing all required env vars and fail with a clear message","Pass apiKey explicitly in code that runs in multiple environments instead of relying on ambient env"],"tags":["pinecone","api-key","authentication","configuration","environment","typescript"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}