{"record":{"id":"90d0d072ac46b89b","repo":"mem0ai/mem0","slug":"turbopuffer-api-key-is-required-provide-it-via-co","errorCode":null,"errorMessage":"Turbopuffer API key is required. Provide it via config.apiKey or the TURBOPUFFER_API_KEY environment variable.","messagePattern":"Turbopuffer API key is required\\. Provide it via config\\.apiKey or the TURBOPUFFER_API_KEY environment variable\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/vector_stores/turbopuffer.ts","lineNumber":25,"sourceCode":"  region?: string;\n  collectionName: string;\n  distanceMetric?: string;\n  batchSize?: number;\n}\n\nexport class TurbopufferDB implements VectorStore {\n  private clientInstance?: any;\n  private clientPromise?: Promise<any>;\n  private readonly apiKey: string;\n  private readonly region: string;\n  private readonly collectionName: string;\n  private readonly distanceMetric: string;\n  private readonly batchSize: number;\n\n  constructor(config: TurbopufferConfig) {\n    const apiKey = config.apiKey ?? process.env.TURBOPUFFER_API_KEY;\n    if (!apiKey) {\n      throw new Error(\n        \"Turbopuffer API key is required. Provide it via config.apiKey or the TURBOPUFFER_API_KEY environment variable.\",\n      );\n    }\n\n    this.apiKey = apiKey;\n    this.region = config.region ?? \"gcp-us-central1\";\n    this.collectionName = config.collectionName;\n    this.distanceMetric = config.distanceMetric ?? \"cosine_distance\";\n    this.batchSize = config.batchSize ?? 100;\n  }\n\n  /**\n   * Lazily construct (or reuse) the Turbopuffer client, importing the optional\n   * `@turbopuffer/turbopuffer` peer only when the store is first used so\n   * consumers that never touch Turbopuffer don't need it installed.\n   */\n  private async getClient(): Promise<any> {\n    if (this.clientInstance) return this.clientInstance;","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/vector_stores/turbopuffer.ts#L7-L43","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set TURBOPUFFER_API_KEY in the environment where the process runs (export it, add it to your platform's env settings).","Pass the key explicitly in config: new Memory({ vectorStore: { provider: 'turbopuffer', config: { apiKey: process.env.TURBOPUFFER_API_KEY!, ... } } }).","Get/verify the key from the Turbopuffer dashboard and confirm the exact variable name."],"exampleFix":"// before\nconst memory = new Memory({ vectorStore: { provider: 'turbopuffer', config: { collectionName: 'mem' } } });\n\n// after\nconst memory = new Memory({ vectorStore: { provider: 'turbopuffer', config: { collectionName: 'mem', apiKey: process.env.TURBOPUFFER_API_KEY! } } });","handlingStrategy":"validation","validationCode":"if (!process.env.TURBOPUFFER_API_KEY) throw new Error('TURBOPUFFER_API_KEY missing — set it before constructing Memory');","typeGuard":"const hasTurbopufferCredentials = (cfg?: { apiKey?: string }): boolean => Boolean(cfg?.apiKey ?? process.env.TURBOPUFFER_API_KEY);","tryCatchPattern":"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; }","preventionTips":["Fail fast at boot on missing env vars","Use a startup config validator in serverless deploys","Name the variable exactly TURBOPUFFER_API_KEY"],"tags":["turbopuffer","authentication","environment","config"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}