{"record":{"id":"b21088461c56ec90","repo":"supermemoryai/supermemory","slug":"supermemory-api-key-is-not-set-provide-it-via-o","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/shared/context.ts","lineNumber":55,"sourceCode":"\t\tapiKey: options.apiKey,\n\t\t...(normalizedBaseUrl !== \"https://api.supermemory.ai\"\n\t\t\t? { baseURL: normalizedBaseUrl }\n\t\t\t: {}),\n\t})\n}\n\n/**\n * Validates that an API key is provided either via options or environment variable.\n *\n * @param apiKey - Optional API key from options\n * @returns The validated API key\n * @throws Error if no API key is available\n */\nexport function validateApiKey(apiKey?: string): string {\n\tconst providedApiKey = 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\treturn providedApiKey\n}\n","sourceCodeStart":37,"sourceCodeEnd":62,"githubUrl":"https://github.com/supermemoryai/supermemory/blob/d436792e777a99865939dd543c8d1a16d57f54ec/packages/tools/src/shared/context.ts#L37-L62","documentation":"validateApiKey resolves the Supermemory API key from the explicit argument or process.env.SUPERMEMORY_API_KEY and throws when neither is present. All Supermemory tools/middleware call this before any network request.","triggerScenarios":"Using any Supermemory SDK entry point without options.apiKey while SUPERMEMORY_API_KEY is unset or empty in the environment (missing .env, not loaded in edge runtime, CI without secrets).","commonSituations":"Forgot to add the key to .env(.local); env var not propagated to Cloudflare Workers/Vercel edge (must be configured as a secret/vars); running tests in CI without the secret.","solutions":["Set SUPERMEMORY_API_KEY in your environment (.env.local for dev, platform secrets for deploy)","Or pass apiKey explicitly: withSupermemory(openai, { apiKey, ... })","Verify the env var actually reaches the runtime (console.log at boot in dev only)","For serverless, register the key as a platform secret, not just a local file"],"exampleFix":"// before\nwithSupermemory(openai, { containerTag, customId })\n\n// after\nwithSupermemory(openai, { containerTag, customId, apiKey: process.env.SUPERMEMORY_API_KEY! })\n// and in .env.local: SUPERMEMORY_API_KEY=sm_...","handlingStrategy":"validation","validationCode":"if (!process.env.SUPERMEMORY_API_KEY && !options?.apiKey) throw new Error('Missing Supermemory API key — configure SUPERMEMORY_API_KEY')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add SUPERMEMORY_API_KEY to platform secrets for every deploy environment","Fail fast at boot with a clear message instead of at first request"],"tags":["env-var","auth","configuration","supermemory"],"backgroundTag":"missing-env-var","analyzedSha":"d436792e777a99865939dd543c8d1a16d57f54ec","analyzedAt":"2026-08-28T18:04:46.947Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}