supermemoryai/supermemory · critical · Error
SUPERMEMORY_API_KEY is not set — provide it via `options.api
Error message
SUPERMEMORY_API_KEY is not set — provide it via `options.apiKey` or set `process.env.SUPERMEMORY_API_KEY`
What it means
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.
Source
Thrown at packages/tools/src/vercel/index.ts:124
* })
*
* const result = await generateText({
* model: modelWithMemory,
* messages: [{ role: "user", content: "What's my favorite programming language?" }]
* })
* ```
*
* @throws {Error} When neither `options.apiKey` nor `process.env.SUPERMEMORY_API_KEY` are set
* @throws {Error} When supermemory memory retrieval fails and `skipMemoryOnError` is `false`
*/
const wrapVercelLanguageModel = <T extends LanguageModel>(
model: T,
options: WrapVercelLanguageModelOptions,
): T => {
const providedApiKey = options.apiKey ?? process.env.SUPERMEMORY_API_KEY
if (!providedApiKey) {
throw new Error(
"SUPERMEMORY_API_KEY is not set — provide it via `options.apiKey` or set `process.env.SUPERMEMORY_API_KEY`",
)
}
if (!options.customId) {
throw new Error(
"customId is required — provide a non-empty string to group messages into a single document",
)
}
const ctx = createSupermemoryContext({
containerTag: options.containerTag,
apiKey: providedApiKey,
customId: options.customId,
verbose: options.verbose ?? false,
mode: options.mode ?? "profile",
addMemory: options.addMemory ?? "always",
baseUrl: options.baseUrl,View on GitHub (pinned to d436792e77)
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
Example fix
// before
const model = wrapVercelLanguageModel(vercelModel, { customId: 'c1' })
// after
const model = wrapVercelLanguageModel(vercelModel, {
customId: 'c1',
apiKey: process.env.SUPERMEMORY_API_KEY!,
}) Defensive patterns
Strategy: validation
Validate before calling
if (!process.env.SUPERMEMORY_API_KEY && !options.apiKey) throw new Error('configure SUPERMEMORY_API_KEY') Prevention
- Add env var to Vercel/Next.js settings for every environment
- Fail fast at module load in server entrypoints
When it happens
Trigger: Calling wrapVercelLanguageModel(model, { customId, containerTag }) without an apiKey while SUPERMEMORY_API_KEY is unset in the process environment.
Common situations: 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.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- SUPERMEMORY_API_KEY is not set — provide it via `options.api
- SUPERMEMORY_API_KEY is not set — provide it via `options.api
- customId is required — provide a non-empty string to group m
- Supermemory tools config accepts either projectId or contain
- customId is required and must be a non-empty string — provid
AI-assisted analysis of supermemoryai/supermemory@d436792e77 (2026-08-28).
Data as JSON: /api/errors/a47cfdc8871db296.
Report an issue: GitHub.