Skip to main content
Add memory capabilities to the official OpenAI SDKs using Supermemory. Two approaches available:
  1. withSupermemory wrapper - Automatic memory injection into each user turn (zero-config)
  2. Function calling tools - Explicit tool calls for search/add memory operations
On @supermemory/tools 2.x? Run npx supermemory@latest migrate, or read the 3.0 upgrade guide.
New to Supermemory? Start with withSupermemory for the simplest integration. It automatically injects relevant memories into your prompts.

Supermemory tools on npm

Check out the NPM page for more details

Supermemory AI SDK

Check out the PyPI page for more details

withSupermemory wrapper

The simplest way to add memory to your OpenAI client. Wraps your client to automatically add relevant memories to each user turn, leaving your system prompt untouched so provider prompt caching keeps working.

Installation

Quick start

Configuration options

Prompt caching

Memories are fetched once per user turn (tool-call steps reuse them) and appended to that turn’s user message. Earlier turns are re-sent with exactly the block they got the first time, so every request starts with the same bytes as the one before. The profile is fetched once per conversation, on its first turn, and never refreshed; newer facts reach the model through each turn’s search. A failed profile fetch is retried on the next user turn. Keep one wrapper per conversation to get this: a new wrapper starts with no memory of earlier turns’ blocks. Recall has a 3 second budget with no retries. If it fails or runs out, the model call goes ahead without memories for that turn. When addMemory is "always", the finished turn is saved once after the model’s final answer, in the background, and system and developer messages are never saved.

Modes explained

Works with Responses API too

Environment variables


Function calling tools

For explicit control over memory operations, use function calling tools. The model decides when to search or add memories.

Installation

Quick start

Configuration

Memory tools configuration

Available tools

Search memories

Search through user memories using semantic search:

Add memory

Store new information in memory:

Individual tools

Use tools separately for more granular control:

Complete chat example

Here’s a complete example showing a multi-turn conversation with memory:

Error handling

Handle errors gracefully in your applications:

API reference

Python SDK

SupermemoryTools

Constructor
Methods
  • get_tool_definitions() - Get OpenAI function definitions
  • search_memories(information_to_get, limit=10) - Search user memories. Pass limit by keyword: the second positional parameter is the deprecated, ignored include_full_docs
  • add_memory(memory) - Add new memory
  • execute_tool_call(tool_call) - Execute individual tool call

execute_memory_tool_calls

with_supermemory

Wraps a sync or async OpenAI client’s chat.completions.create. The Python wrapper places memories so the provider’s prompt cache keeps working. The user’s profile is fetched once per conversation and appended to the first system or developer message as a separate block, byte-identical on every later call. Each new user message gets its own search results appended to it, and earlier messages are re-sent with exactly the block they got the first time. Tool-call steps reuse their turn’s memories and never search again. Recall has a 3 second budget with no retries. If it fails or runs out, the model call goes ahead without memories, and a failed profile is fetched again on the next user message. When add_memory is "always", each turn is saved once in the background after the model’s final reply, and system and developer messages are never saved.

JavaScript SDK

supermemoryTools

createToolCallExecutor

Environment variables

Set these environment variables:

Development

Python setup

JavaScript setup

Next steps

AI SDK integration

Use with Vercel AI SDK for streamlined development

Add memories

Direct API access for advanced memory management