New to Claude Skills? Learn how to install them →

mem0ai on GitHub

Mem0 Vercel AI SDK Provider

Free

Memory-enhanced AI for Vercel applications.

by mem0ai63k stars on mem0ai/mem0
4 views
Updated Aug 7, 2026
Get this skill

Free · Opens the source repo

What Mem0 Vercel AI SDK Provider does

The Mem0 Vercel AI SDK Provider enables developers to integrate memory capabilities into AI applications built on the Vercel platform. By utilizing this skill, you can enhance your AI interactions with memory retrieval and storage, allowing for more contextually aware responses. This is particularly useful for applications that require continuity in user interactions, such as chatbots or recommendation systems.

To get started, you simply install the package via npm and set up your environment variables with the necessary API keys. Once configured, you can use the createMem0 function to wrap any supported language model, enabling automatic memory management during your AI calls. This means that when a user prompts the AI, relevant memories are fetched and injected into the conversation, enriching the context and improving the quality of responses.

The SDK also provides standalone utilities for developers who prefer more granular control over the memory lifecycle. With functions like retrieveMemories and addMemories, you can explicitly manage how memories are fetched and stored, offering flexibility depending on your application's needs. Additionally, the SDK supports streaming responses, allowing for real-time interactions while still leveraging memory capabilities.

Overall, this skill is designed for developers looking to build intelligent applications on Vercel that require memory augmentation to enhance user experience and engagement. It simplifies the process of incorporating memory into AI workflows, making it a valuable addition for those using the Vercel AI SDK.

When to use it

Use this skill when developing applications on Vercel that require memory-augmented AI capabilities, especially for chatbots or interactive systems.

When not to use it

This skill is not suitable for direct Python or TypeScript SDK calls without Vercel, nor for CLI terminal commands.

What you can build with it

Enhancing Chatbots

Integrate memory capabilities into your chatbot to provide more contextually relevant responses based on previous interactions.

Personalized Recommendations

Use the SDK to remember user preferences and past choices, allowing your application to make tailored suggestions.

Real-time Streaming Interactions

Leverage the streaming capabilities to provide users with immediate feedback while maintaining context through memory.

How to install Mem0 Vercel AI SDK Provider

View source

1. Install with the skills CLI

npx skills add mem0ai/mem0/mem0-vercel-ai-sdk --agent claude-code

2. Or install it manually

Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.

Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs

Inside SKILL.md

Written by mem0ai

Mem0 Vercel AI SDK Provider

Memory-enhanced AI provider for Vercel AI SDK. Automatically retrieves and stores memories during LLM calls.

Step 1: Install

npm install @mem0/vercel-ai-provider ai

Step 2: Set up environment variables

export MEM0_API_KEY="m0-xxx"
export OPENAI_API_KEY="sk-xxx"   # or ANTHROPIC_API_KEY, GOOGLE_API_KEY, etc.

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.

import { generateText } from "ai";
import { createMem0 } from "@mem0/vercel-ai-provider";

const mem0 = createMem0();
const { text } = await generateText({
  model: mem0("gpt-5-mini", { user_id: "alice" }),
  prompt: "Recommend a restaurant",
});

What happens under the hood:

  1. The prompt is sent to Mem0 search (POST /v3/memories/search/) to retrieve relevant memories
  2. Retrieved memories are injected as a system message at the start of the prompt
  3. The underlying LLM (e.g., OpenAI gpt-5-mini) generates a response using the enriched prompt
  4. The conversation is stored back to Mem0 (POST /v3/memories/add/) as a fire-and-forget async call (no await)

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.

import { openai } from "@ai-sdk/openai";
import { generateText } from "ai";
import { retrieveMemories, addMemories } from "@mem0/vercel-ai-provider";

const prompt = "Recommend a restaurant";

// Retrieve memories -- returns a formatted system prompt string
const memories = await retrieveMemories(prompt, {
  user_id: "alice",
  mem0ApiKey: "m0-xxx",
});

// Generate using any provider with injected memories
const { text } = await generateText({
  model: openai("gpt-5-mini"),
  prompt,
  system: memories,
});

// Optionally store the conversation back
await addMemories(
  [
    { role: "user", content: [{ type: "text", text: prompt }] },
    { role: "assistant", content: [{ type: "text", text }] },
  ],
  { user_id: "alice", mem0ApiKey: "m0-xxx" }
);

Pattern 3: Streaming

Use streamText for streaming responses with memory augmentation:

import { streamText } from "ai";
import { createMem0 } from "@mem0/vercel-ai-provider";

const mem0 = createMem0();
const result = streamText({
  model: mem0("gpt-5-mini", { user_id: "alice" }),
  prompt: "What should I cook for dinner?",
});

for await (const chunk of result.textStream) {
  process.stdout.write(chunk);
}

The wrapped model handles memory retrieval before streaming begins and stores the conversation after.

Supported Providers

ProviderConfig valueRequired env var
OpenAI (default)"openai"OPENAI_API_KEY
Anthropic"anthropic"ANTHROPIC_API_KEY
Google"google"GOOGLE_GENERATIVE_AI_API_KEY
Groq"groq"GROQ_API_KEY
Cohere"cohere"COHERE_API_KEY

Select a provider when creating the Mem0 instance:

const mem0 = createMem0({ provider: "anthropic" });
const { text } = await generateText({
  model: mem0("gpt-5-mini", { user_id: "alice" }),
  prompt: "Hello!",
});

How It Works Internally

Wrapped model flow

User prompt
  --> searchInternalMemories (POST /v3/memories/search/)
  --> memories injected as system message at start of prompt
  --> underlying LLM generates response (doGenerate or doStream)
  --> processMemories fires addMemories as fire-and-forget (no await)
  --> response returned to caller

Standalone flow

User controls each step:
  1. retrieveMemories / getMemories / searchMemories -> fetch memories
  2. inject into system prompt manually
  3. call generateText / streamText with any provider
  4. addMemories -> store new conversation to Mem0

Key Differences Between the 4 Utility Functions

FunctionReturnsUse when
retrieveMemoriesFormatted system prompt stringInjecting directly into system parameter
getMemoriesRaw memory arrayProcessing memories programmatically
searchMemoriesFull search response (results + relations)Need relations, scores, metadata
addMemoriesAPI responseStoring new messages to Mem0

All four accept LanguageModelV2Prompt | string as the first argument and optional Mem0ConfigSettings as the second.

Common Edge Cases and Tips

  • Always provide user_id (or agent_id/app_id/run_id) for consistent memory retrieval. Without an entity identifier, memories cannot be scoped.
  • 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 v5 (LanguageModelV2 / ProviderV2 interfaces). It is not compatible with AI SDK v3 or v4.
  • processMemories fires addMemories as fire-and-forget (.then() without await). Memory storage happens asynchronously and does not block the LLM response.
  • The "gemini" alias exists in the provider switch but is NOT in the supportedProviders list. Use "google" instead.
  • Custom host: set host in the config to point to a different Mem0 API endpoint (default: https://api.mem0.ai).

References

TopicFile
Provider API (createMem0, Mem0Provider, types)local / GitHub
Memory utilities (addMemories, retrieveMemories, etc.)local / GitHub
Usage patterns and exampleslocal / GitHub

Related Mem0 Skills

SkillWhen to useLink
mem0Python/TypeScript SDK, REST API, framework integrationslocal / GitHub
mem0-cliTerminal commands, scripting, CI/CD, agent tool loopslocal / GitHub

Frequently asked questions about Mem0 Vercel AI SDK Provider

Similar skills