Add Memories - Mem0

Documentation Index

Fetch the complete documentation index at: /llms.txt

Use this file to discover all available pages before exploring further.

cURL

curl -X POST https://api.mem0.ai/v3/memories/add/ \
  -H "Authorization: Token <api-key>" \
  -H "Content-Type: application/json" \
  -d '{\
    "messages": [ \
      {"role": "user", "content": "I just moved to San Francisco from New York."}, \
      {"role": "assistant", "content": "Got it, I\\u0027ll update your location."} \
    ], \
    "user_id": "alice"\
  }'
from mem0 import MemoryClient

client = MemoryClient(api_key="your-api-key")

result = client.add(
    messages=[ \
        {"role": "user", "content": "I just moved to San Francisco from New York."}, \
        {"role": "assistant", "content": "Got it, I'll update your location."} \
    ],
    user_id="alice",
)
print(result)
import MemoryClient from "mem0ai";

const client = new MemoryClient({ apiKey: "your-api-key" });

const result = await client.add(
  [ \
    { role: "user", content: "I just moved to San Francisco from New York." }, \
    { role: "assistant", content: "Got it, I'll update your location." }, \
  ],
  { userId: "alice" }
);
console.log(result);
<?php

$curl = curl_init();

curl_setopt_array($curl, [ \
  CURLOPT_URL => "https://api.mem0.ai/v3/memories/add/", \
  CURLOPT_RETURNTRANSFER => true, \
  CURLOPT_ENCODING => "", \
  CURLOPT_MAXREDIRS => 10, \
  CURLOPT_TIMEOUT => 30, \
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, \
  CURLOPT_CUSTOMREQUEST => "POST", \
  CURLOPT_POSTFIELDS => json_encode([ \
    'messages' => [ \
        [ \
                'role' => 'user', \
                'content' => 'I just moved to San Francisco from New York.' \
        ], \
        [ \
                'role' => 'assistant', \
                'content' => 'Got it, I\\'ll update your location.' \
        ] \
    ], \
    'user_id' => 'alice' \
  ]), \
  CURLOPT_HTTPHEADER => [ \
    "Content-Type: application/json" \
  ], \
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
package main

import (
    "fmt"
    "strings"
    "net/http"
    "io"
)

func main() {

url := "https://api.mem0.ai/v3/memories/add/"

payload := strings.NewReader("{\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"I just moved to San Francisco from New York.\"\n    },\n    {\n      \"role\": \"assistant\",\n      \"content\": \"Got it, I'll update your location.\"\n    }\n  ],\n  \"user_id\": \"alice\"}\")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
    body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))
}
HttpResponse<String> response = Unirest.post("https://api.mem0.ai/v3/memories/add/")
  .header("Content-Type", "application/json")
  .body("{\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"I just moved to San Francisco from New York.\"\n    },\n    {\n      \"role\": \"assistant\",\n      \"content\": \"Got it, I'll update your location.\"\n    }\n  ],\n  \"user_id\": \"alice\"}")
  .asString();
require 'uri'
require 'net/http'

url = URI("https://api.mem0.ai/v3/memories/add/")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"I just moved to San Francisco from New York.\"\n    },\n    {\n      \"role\": \"assistant\",\n      \"content\": \"Got it, I'll update your location.\"\n    }\n  ],\n  \"user_id\": \"alice\"}\"

response = http.request(request)
puts response.read_body

Response

The request is queued for background processing. The response contains an event_id for tracking status.

Example 200 response

{
  "message": "Memory processing has been queued for background execution",
  "status": "PENDING",
  "event_id": "2c4d1f44-4f7b-4b2f-9f6e-7b5b4f5a1234"
}

Basic request

{
  "user_id": "alice",
  "messages": [
    { "role": "user", "content": "I moved to Austin last month." }
  ],
  "metadata": {
    "source": "onboarding_form"
  }
}

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.

Common Fields

Field Type Required Description
messages array Yes Conversation turns for Mem0 to extract memories from. Each object should include role and content.
user_id string No* Associates the memory with a user.
agent_id string No* Associates the memory with an agent.
run_id string No* Associates the memory with a run.
app_id string No* Associates the memory with an app.
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.
expiration_date string Optional Date in YYYY-MM-DD format. The memory is visible through this date and hidden by default after it passes.

More Details

See all request parameters below for complete field descriptions, types, and constraints.