You’ll use this when…
- Your app already relies on OpenAI chat completions and you want Mem0 to feel familiar.
- You need to reuse existing middleware that expects OpenAI-compatible responses.
- You plan to switch between Mem0 Platform and the self-hosted client without rewriting code.
Feature
- Drop-in client:
client.chat.completions.create(...)works the same as OpenAI’s method signatures. - Shared parameters: Mem0 accepts
messages,model, and optional memory-scoping fields (user_id,agent_id,run_id). - Memory-aware responses: Each call saves relevant facts so future prompts automatically reflect past conversations.
- OSS parity: Use the same API surface whether you call the hosted proxy or the OSS configuration.
Run one request with
user_id set. If the next call references that ID and its reply uses the stored memory, compatibility is confirmed.Configure it
Call the managed Mem0 proxy
Reuse the same identifiers your OpenAI client already sends so you can switch between providers without branching logic.
Use the OpenAI-compatible OSS client
See it in action
Memory-aware restaurant recommendation
The second response should call out Indian restaurants and avoid cheese, proving Mem0 recalled the stored preference.
Verify the feature is working
- Compare responses from Mem0 vs. OpenAI for identical prompts—both should return the same structure (
choices,usage, etc.). - Inspect stored memories after each request to confirm the fact extraction captured the right details.
- Test switching between hosted (
Mem0(api_key=...)) and OSS configurations to ensure both respect the same request body.
Best practices
- Scope context intentionally: Pass identifiers only when you want conversations to persist; skip them for one-off calls.
- Log memory usage: Inspect
response.metadata.memories(if enabled) to see which facts the model recalled. - Reuse middleware: Point your existing OpenAI client wrappers to the Mem0 proxy URL to avoid code drift.
- Handle fallbacks: Keep a code path for plain OpenAI calls in case Mem0 is unavailable, then resync memory later.
Parameter reference
| Parameter | Type | Purpose |
|---|---|---|
user_id | str | Associates the conversation with a user so memories persist. |
agent_id | str | Optional agent or bot identifier for multi-agent scenarios. |
run_id | str | Optional session/run identifier for short-lived flows. |
metadata | dict | Store extra fields alongside each memory entry. |
filters | dict | Restrict retrieval to specific memories while responding. |
limit | int | Cap how many memories Mem0 pulls into the context (default 10). |