POST
/
v1
/
memories
# To use the Python SDK, install the package:
# pip install mem0ai

from mem0 import MemoryClient

client = MemoryClient(api_key="your_api_key", org_id="your_org_id", project_id="your_project_id")

messages = [
    {"role": "user", "content": "<user-message>"},
    {"role": "assistant", "content": "<assistant-response>"}
]

client.add(messages, user_id="<user-id>", version="v2")
[
  {
    "id": "<string>",
    "data": {
      "memory": "<string>"
    },
    "event": "ADD"
  }
]

Authorizations

Authorization
string
header
required

API key authentication. Prefix your Mem0 API key with 'Token '. Example: 'Token your_api_key'

Body

application/json
messages
object[]

An array of message objects representing the content of the memory. Each message object typically contains 'role' and 'content' fields, where 'role' indicates the sender (e.g., 'user', 'assistant', 'system') and 'content' contains the actual message text. This structure allows for the representation of conversations or multi-part memories.

agent_id
string | null

The unique identifier of the agent associated with this memory.

user_id
string | null

The unique identifier of the user associated with this memory.

app_id
string | null

The unique identifier of the application associated with this memory.

run_id
string | null

The unique identifier of the run associated with this memory.

metadata
object | null

Additional metadata associated with the memory, which can be used to store any additional information or context about the memory. Best practice for incorporating additional information is through metadata (e.g. location, time, ids, etc.). During retrieval, you can either use these metadata alongside the query to fetch relevant memories or retrieve memories based on the query first and then refine the results using metadata during post-processing.

includes
string | null

String to include the specific preferences in the memory.

Minimum length: 1
excludes
string | null

String to exclude the specific preferences in the memory.

Minimum length: 1
infer
boolean
default:true

Wether to infer the memories or directly store the messages.

output_format
string | null

It two output formats: v1.0 (default) and v1.1. To enable the latest format, which provides enhanced detail for each memory operation, set the output_format parameter to v1.1. Note that v1.0 will be deprecated in version 0.1.35.

custom_categories
object | null

A list of categories with category name and it's description.

custom_instructions
string | null

Defines project-specific guidelines for handling and organizing memories. When set at the project level, they apply to all new memories in that project.

immutable
boolean
default:false

Whether the memory is immutable.

expiration_date
string | null

The date and time when the memory will expire. Format: YYYY-MM-DD

org_id
string | null

The unique identifier of the organization associated with this memory.

project_id
string | null

The unique identifier of the project associated with this memory.

version
string | null

The version of the memory to use. The default version is v1, which is deprecated. We recommend using v2 for new applications.

Response

200
application/json
Successful memory creation
id
string
required
data
object
required
event
enum<string>
required
Available options:
ADD,
UPDATE,
DELETE