Operation Guide Template - Mem0

Operation Guide Template

Operation guides focus on a single action (add, search, update, delete). Show the minimal path to execute it, verify the result, and route readers to references or applied guides.

❌ DO NOT COPY: Guidance & Constraints

✅ COPY THIS: Content Skeleton

---
title: [Operation title]
description: [Outcome in one sentence]
icon: "bolt"
---

# [Operation headline: say what it does]

[State the problem this solves.] [Explain the outcome after running it.]

<Info>
  **Prerequisites**
  - [API key, project, runtime requirements]
  - [Identifiers the reader needs ready]
</Info>

<Warning>
  [Optional: describe the main risk, e.g., duplicates or destructive behavior.]
</Warning>

## When to pick this

- [Scenario 1]
- [Scenario 2]
- [Scenario 3]

## Configure access

```bash
export MEM0_API_KEY="sk-..."
```

<Tip>
  Already configured Mem0? Skip this and move to the next section.
</Tip>

## Prepare inputs

[Brief sentence describing payload requirements.]

<Tabs>
  <Tab title="Python">
<CodeGroup>
```python Python
payload = {
    "user_id": "alex",
    "memory": "I am training for a marathon."
}
```
</CodeGroup>
  </Tab>
  <Tab title="TypeScript">
<CodeGroup>
```typescript TypeScript
const payload = {
userId: "alex",
memory: "I am training for a marathon."
};
```
</CodeGroup>
  </Tab>
</Tabs>

## Call the operation

<Tabs>
  <Tab title="Python">
<CodeGroup>
```python Python
from mem0 import Memory

memory = Memory(api_key=os.environ["MEM0_API_KEY"])
response = memory.add(payload)
```
</CodeGroup>
  </Tab>
  <Tab title="TypeScript">
<CodeGroup>
```typescript TypeScript
import { Memory } from "mem0ai/oss";

const memory = new Memory({ apiKey: process.env.MEM0_API_KEY! });
const response = await memory.add(payload);
```
</CodeGroup>
  </Tab>
</Tabs>

<Info icon="check">
  Expect `{"memory_id": "mem_123"}` (or similar). Keep this ID for updates or deletes.
</Info>

<Warning>
  `401 Unauthorized` usually means the API key is missing or scoped incorrectly.
</Warning>

## Interpret the response

| Field       | Description                              |
| ----------- | ---------------------------------------- |
| `memory_id` | Use to update or delete later.          |
| `created_at` | ISO 8601 timestamp for auditing.        |

<Tip>
  Need to upsert instead? Switch to the update operation and supply the `memory_id`.
</Tip>

## Verify it worked

- Check the Mem0 dashboard for the new memory entry.
- Run the search operation with the same `user_id` and confirm it appears in results.

## Common follow-ups

- [Link to parameter reference]
- [Link to complementary operation]
- [Link to troubleshooting playbook section]

<CardGroup cols={2}>
  <Card
    title="[Concept guide]"
    description="[Deepen understanding of the operation’s model]"
    icon="layers"
    href="/[concept-link]"
  />
  <Card
    title="[Applied cookbook]"
    description="[How to apply this operation in a workflow]"
    icon="rocket"
    href="/[cookbook-link]"
  />
</CardGroup>

✅ Publish Checklist