mem0-vercel-ai-sdk
Mem0 provider for Vercel AI SDK (@mem0/vercel-ai-provider). TRIGGER when: user mentions "vercel ai sdk", "@mem0/vercel-ai-provider", "createMem0", "retrieveMemories", "addMemories", "getMemories", "searchMemories", "mem0 vercel", "AI SDK provider", "AI SDK memory", or is using generateText/streamTex
By mem0ai · 440 installs
npx skills add mem0ai/mem0 --skill mem0-vercel-ai-sdk
Source repository · Upstream listing
Mem0 Vercel AI SDK Provider
Memory enhanced AI provider for Vercel AI SDK. Automatically retrieves and stores memories during LLM calls.
Step 1: Install
ai and the @ai sdk/ provider packages ship as regular dependencies of @mem0/vercel ai provider , so nothing else needs installing. The only peer dependency is zod (optional, ^3.0.0 ).
Step 2: Set up environment variables
Get a Mem0 API key at: https://app.mem0.ai/dashboard/api keys?utm source=oss&utm medium=skill mem0 vercel ai sdk
Pattern 1: Wrapped Model
The wrapped model approach is the simplest. createMem0 returns a provider that wraps any supported LLM with automatic memory retrieval and storage.
What happens under the hood:
1. The prompt is stored to Mem0 ( POST /v3/memories/add/ ), awaited before the LLM call (a failed write is logged and ignored)
2. The prompt is sent to Mem0 search ( POST /v3/memories/search/ ) to retrieve relevant memories
3. If any memories are found, they are injected as a system message at the start of the prompt
4. The underlying LLM (e.g., OpenAI gpt 5 mini) generates a response using the enriched prompt
For generateText , the retrieved memories are also attached to the result as a source:
The source has title: "Mem0 Memories" and providerMetadata.mem0 holds memories (array of memory objects) and memoriesText . It is only present when at least one memory was retrieved.
Pattern 2: Standalone Utilities
Use standalone utilities when you want full control over the memory retrieve/store cycle, or you want to use a provider that is already configured separately.
Pattern 3: Streaming
Use streamText for streaming responses with memory augmentation:
The wrapped model stores the conversation and retrieves memories before streaming begins.
Supported Providers
Provider Config value Required env var
OpenAI (default) "openai" OPENAI API KEY
Anthropic "anthropic" ANTHROPIC API KEY
Google "google" (alias "gemini" ) GOOGLE GENERATIVE AI API KEY
Groq "groq" GROQ API KEY
Cohere "cohere" COHERE API KEY
Select a provider when creating the Mem0 instance:
How It Works Internally
Wrapped model flow
Standalone flow
Key Differences Between the 4 Utility Functions
Function Returns Use when
retrieveMemories Formatted system prompt string Injecting directly into system parameter
getMemories Raw memory array Processing memories programmatically
searchMemories Raw search response (as returned by the API) Need scores and full metadata
addMemories API response Storing new messages to Mem0
retrieveMemories , getMemories , and searchMemories accept LanguageModelV3Prompt string as the first argument; addMemories is typed as LanguageModelV3Prompt (a string also works at runtime). All four take optional Mem0ConfigSettings as the second argument.
Common Edge Cases and Tips
Always provide user id (or agent id / app id / run id ) for consistent memory retrieval. The search endpoint requires at least one entity ID in filters ; the provider places these IDs there for you.
Standalone utilities require explicit API key : pass mem0ApiKey in the config object, or set the MEM0 API KEY environment variable.
This uses Vercel AI SDK v6 (LanguageModelV3 / ProviderV3 interfaces, @mem0/vercel ai provider 3.x). Provider 2.x targeted AI SDK v5. It is not compatible with AI SDK v4 or earlier.
processMemories awaits addMemories before searching and calling the LLM, so each wrapped call includes one memory write and one memory search. If either request fails, the error is logged and the LLM call proceeds without memories.
"google" and "gemini" are both accepted and map to @ai sdk/google .
Removed in 3.0.0 : org id , project id , org name , project name , output format , filter memories , async mode , enable graph , version , api version . Graph memory is now a Mem0 Platform project setting, not a provider option.
Default top k is 10. threshold and rerank are only sent when set (the API default for rerank is false ; threshold is a server side cutoff, not a floor on the returned score).
Custom host : set host in the config to point to a different Mem0 API endpoint (default: https://api.mem0.ai ).
References
Topic File
Provider API ( createMem0 , Mem0Provider , types) [local](references/provider api.md) / [GitHub](https://github.com/mem0ai/mem0/tree/main/skills/mem0 vercel ai sdk/references/provider api.md)
Memory utilities ( addMemories , retrieveMemories , etc.) [local](references/memory utilities.md) / [GitHub](https://github.com/mem0ai/mem0/tree/main/skills/mem0 vercel ai sdk/references/memory utilities.md)
Usage patterns and examples [local](references/usage patterns.md) / [GitHub](https://github.com/mem0ai/mem0/tree/main/skills/mem0 vercel ai sdk/references/usage patterns.md)
Related Mem0 Skills
Skill When to use Link
mem0 Python/TypeScript SDK, REST API, framework integrations [local](../mem0/SKILL.md) / [GitHub](https://github.com/mem0ai/mem0/tree/main/skills/mem0)
mem0 cli Terminal commands, scripting, CI/CD, agent tool loops [local](../mem0 cli/SKILL.md) / [GitHub](https://github.com/mem0ai/mem0/tree/main/skills/mem0 cli)