{"record":{"id":"a47cfdc8871db296","repo":"supermemoryai/supermemory","slug":"supermemory-api-key-is-not-set-provide-it-via-o-a47cfd","errorCode":null,"errorMessage":"SUPERMEMORY_API_KEY is not set — provide it via `options.apiKey` or set `process.env.SUPERMEMORY_API_KEY`","messagePattern":"SUPERMEMORY_API_KEY is not set — provide it via `options\\.apiKey` or set `process\\.env\\.SUPERMEMORY_API_KEY`","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/tools/src/vercel/index.ts","lineNumber":124,"sourceCode":" * })\n *\n * const result = await generateText({\n *   model: modelWithMemory,\n *   messages: [{ role: \"user\", content: \"What's my favorite programming language?\" }]\n * })\n * ```\n *\n * @throws {Error} When neither `options.apiKey` nor `process.env.SUPERMEMORY_API_KEY` are set\n * @throws {Error} When supermemory memory retrieval fails and `skipMemoryOnError` is `false`\n */\nconst wrapVercelLanguageModel = <T extends LanguageModel>(\n\tmodel: T,\n\toptions: WrapVercelLanguageModelOptions,\n): T => {\n\tconst providedApiKey = options.apiKey ?? process.env.SUPERMEMORY_API_KEY\n\n\tif (!providedApiKey) {\n\t\tthrow new Error(\n\t\t\t\"SUPERMEMORY_API_KEY is not set — provide it via `options.apiKey` or set `process.env.SUPERMEMORY_API_KEY`\",\n\t\t)\n\t}\n\n\tif (!options.customId) {\n\t\tthrow new Error(\n\t\t\t\"customId is required — provide a non-empty string to group messages into a single document\",\n\t\t)\n\t}\n\n\tconst ctx = createSupermemoryContext({\n\t\tcontainerTag: options.containerTag,\n\t\tapiKey: providedApiKey,\n\t\tcustomId: options.customId,\n\t\tverbose: options.verbose ?? false,\n\t\tmode: options.mode ?? \"profile\",\n\t\taddMemory: options.addMemory ?? \"always\",\n\t\tbaseUrl: options.baseUrl,","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/supermemoryai/supermemory/blob/d436792e777a99865939dd543c8d1a16d57f54ec/packages/tools/src/vercel/index.ts#L106-L142","documentation":"wrapVercelLanguageModel resolves the Supermemory API key from options.apiKey or process.env.SUPERMEMORY_API_KEY and throws before wrapping when neither exists. This is a fail-fast setup check, not a network failure.","triggerScenarios":"Calling wrapVercelLanguageModel(model, { customId, containerTag }) without an apiKey while SUPERMEMORY_API_KEY is unset in the process environment.","commonSituations":"Next.js/Vercel AI app where the env var is set locally but not added to Vercel project settings; .env not loaded in edge middleware; CI tests without secrets.","solutions":["Add SUPERMEMORY_API_KEY to your Vercel/Next.js environment (and redeploy)","Or pass apiKey in the options object","Verify with a boot-time check that the var is defined in the deploying runtime"],"exampleFix":"// before\nconst model = wrapVercelLanguageModel(vercelModel, { customId: 'c1' })\n\n// after\nconst model = wrapVercelLanguageModel(vercelModel, {\n  customId: 'c1',\n  apiKey: process.env.SUPERMEMORY_API_KEY!,\n})","handlingStrategy":"validation","validationCode":"if (!process.env.SUPERMEMORY_API_KEY && !options.apiKey) throw new Error('configure SUPERMEMORY_API_KEY')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add env var to Vercel/Next.js settings for every environment","Fail fast at module load in server entrypoints"],"tags":["env-var","auth","configuration","vercel","supermemory"],"backgroundTag":"missing-env-var","analyzedSha":"d436792e777a99865939dd543c8d1a16d57f54ec","analyzedAt":"2026-08-28T18:04:46.947Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}