9d6b79a14e
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
84 lines
2.8 KiB
Plaintext
84 lines
2.8 KiB
Plaintext
---
|
||
title: 'Add Memories'
|
||
description: "Add facts, messages, or metadata to a user memory store with support for async processing and event tracking."
|
||
openapi: post /v1/memories/
|
||
---
|
||
|
||
Add new facts, messages, or metadata to a user’s memory store. The Add Memories endpoint accepts either raw text or conversational turns and commits them asynchronously so the memory is ready for later search, retrieval, and graph queries.
|
||
|
||
## Endpoint
|
||
|
||
- **Method**: `POST`
|
||
- **URL**: `/v1/memories/`
|
||
- **Content-Type**: `application/json`
|
||
|
||
Memories are processed asynchronously by default. The response contains queued events you can track while the platform finalizes enrichment.
|
||
|
||
## Required headers
|
||
|
||
| Header | Required | Description |
|
||
| --- | --- | --- |
|
||
| `Authorization: Token <MEM0_API_KEY>` | Yes | API key scoped to your workspace. |
|
||
| `Accept: application/json` | Yes | Ensures a JSON response. |
|
||
|
||
## Request body
|
||
|
||
Provide at least one message or direct memory string. Most callers supply `messages` so Mem0 can infer structured memories as part of ingestion.
|
||
|
||
<CodeGroup>
|
||
```json Basic request
|
||
{
|
||
"user_id": "alice",
|
||
"messages": [
|
||
{ "role": "user", "content": "I moved to Austin last month." }
|
||
],
|
||
"metadata": {
|
||
"source": "onboarding_form"
|
||
}
|
||
}
|
||
```
|
||
</CodeGroup>
|
||
|
||
### Common fields
|
||
|
||
| Field | Type | Required | Description |
|
||
| --- | --- | --- | --- |
|
||
| `user_id` | string | No* | Associates the memory with a user. Provide when you want the memory scoped to a specific identity. |
|
||
| `messages` | array | No* | Conversation turns for Mem0 to infer memories from. Each object should include `role` and `content`. |
|
||
| `metadata` | object | Optional | Custom key/value metadata (e.g., `{"topic": "preferences"}`). |
|
||
| `infer` | boolean (default `true`) | Optional | Set to `false` to skip inference and store the provided text as-is. |
|
||
|
||
> \* Provide at least one `messages` entry to describe what you are storing. For scoped memories, include `user_id`. You can also attach `agent_id`, `app_id`, `run_id`, `project_id`, or `org_id` to refine ownership.
|
||
|
||
<Tip>
|
||
Need more details? See [all request parameters](#body-messages) below for complete field descriptions, types, and constraints.
|
||
</Tip>
|
||
|
||
## Response
|
||
|
||
Successful requests return an array of events queued for processing. Each event includes the generated memory text and an identifier you can persist for auditing.
|
||
|
||
<CodeGroup>
|
||
```json 200 response
|
||
[
|
||
{
|
||
"id": "mem_01JF8ZS4Y0R0SPM13R5R6H32CJ",
|
||
"event": "ADD",
|
||
"data": {
|
||
"memory": "The user moved to Austin in 2025."
|
||
}
|
||
}
|
||
]
|
||
```
|
||
|
||
```json 400 response
|
||
{
|
||
"error": "400 Bad Request",
|
||
"details": {
|
||
"message": "Invalid input data. Please refer to the memory creation documentation at https://docs.mem0.ai/platform/quickstart#4-1-create-memories for correct formatting and required fields."
|
||
}
|
||
}
|
||
```
|
||
</CodeGroup>
|
||
|