## Prerequisites

- Mem0 Platform account ( [Sign up here](https://app.mem0.ai/?utm_source=oss&utm_medium=platform-quickstart))
- API key ( [Get one from dashboard](https://app.mem0.ai/dashboard/settings?tab=api-keys&subtab=configuration))
- Python 3.10+, Node.js 18+, or cURL

## Installation

1. Install SDK

```
   pip install mem0ai
   ```

```
   npm install mem0ai
   ```

2. Set your API key

```python
   from mem0 import MemoryClient
   
   client = MemoryClient(api_key="your-api-key")
   ```

```javascript
   import MemoryClient from 'mem0ai';
   const client = new MemoryClient({ apiKey: 'your-api-key' });
   ```

```bash
   export MEM0_API_KEY="your-api-key"
   ```

```bash
   mem0 init --api-key "your-api-key"
   ```

3. Add a memory

```python
   messages = [\
       {"role": "user", "content": "I'm a vegetarian and allergic to nuts."},\
       {"role": "assistant", "content": "Got it! I'll remember your dietary preferences."}\
   ]
   client.add(messages, user_id="user123")
   ```

```javascript
   const messages = [\
       {"role": "user", "content": "I'm a vegetarian and allergic to nuts."},\
       {"role": "assistant", "content": "Got it! I'll remember your dietary preferences."}\
   ];
   await client.add(messages, { userId: "user123" });
   ```

```bash
   curl -X POST https://api.mem0.ai/v3/memories/add/ \
     -H "Authorization: Token $MEM0_API_KEY" \
     -H "Content-Type: application/json" \
     -d '{\
       "messages": [\
         {"role": "user", "content": "Im a vegetarian and allergic to nuts."},\
         {"role": "assistant", "content": "Got it! Ill remember your dietary preferences."}\
       ],\
       "user_id": "user123"\
     }'
   ```

```bash
   mem0 add "I'm a vegetarian and allergic to nuts." --user-id user123
   ```

4. Search memories

```python
   results = client.search("What are my dietary restrictions?", filters={"user_id": "user123"})
   print(results)
   ```

```javascript
   const results = await client.search("What are my dietary restrictions?", { filters: { user_id: "user123" } });
   console.log(results);
   ```

```bash
   curl -X POST https://api.mem0.ai/v3/memories/search/ \
     -H "Authorization: Token $MEM0_API_KEY" \
     -H "Content-Type: application/json" \
     -d '{\
       "query": "What are my dietary restrictions?",\
       "filters": {"user_id": "user123"}\
     }'
   ```

```bash
   mem0 search "What are my dietary restrictions?" --user-id user123
   ```

**Output:**

```
{
  "results": [\
    {\
      "id": "14e1b28a-2014-40ad-ac42-69c9ef42193d",\
      "memory": "Allergic to nuts",\
      "user_id": "user123",\
      "categories": ["health"],\
      "created_at": "2025-10-22T04:40:22.864647-07:00",\
      "score": 0.30\
    }\
  ]
}
```

**Pro Tip**: Want AI agents to manage their own memory automatically? Use [Mem0 MCP](https://docs.mem0.ai/platform/mem0-mcp) to let LLMs decide when to save, search, and update memories.

## What’s next?

You stored and searched your first memory. Keep going:

[**How it works** 
See how Mem0 extracts, stores, and retrieves memories under the hood.](https://docs.mem0.ai/core-concepts/how-it-works)

[**Memory operations** 
Go beyond add and search: update, delete, and the full memory lifecycle.](https://docs.mem0.ai/core-concepts/memory-operations/add)

[**Build an AI companion** 
Put it to work in a real app, end to end, in about 10 minutes.](https://docs.mem0.ai/cookbooks/essentials/building-ai-companion)

Stuck on setup? See the [FAQs and troubleshooting](https://docs.mem0.ai/platform/faqs).
