Batch Delete Memories - Mem0

Documentation Index

Fetch the complete documentation index at: /llms.txt

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

Python

# To use the Python SDK, install the package:
# pip install mem0ai

from mem0 import MemoryClient
client = MemoryClient(api_key="your_api_key")

delete_memories = [
    {"memory_id": "285ed74b-6e05-4043-b16b-3abd5b533496"},
    {"memory_id": "2c9bd859-d1b7-4d33-a6b8-94e0147c4f07"}
]

response = client.batch_delete(delete_memories)
print(response)

JavaScript

// To use the JavaScript SDK, install the package:
// npm i mem0ai

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

const deleteMemories = [
    { memory_id: "285ed74b-6e05-4043-b16b-3abd5b533496" },
    { memory_id: "2c9bd859-d1b7-4d33-a6b8-94e0147c4f07" }
];

client.batchDelete(deleteMemories)
    .then(response => console.log('Batch delete response:', response))
    .catch(error => console.error(error));

cURL

curl -X DELETE "https://api.mem0.ai/v1/batch/" \
     -H "Authorization: Token your-api-key" \
     -H "Content-Type: application/json" \
     -d '{
         "memories": [
             {
                 "memory_id": "285ed74b-6e05-4043-b16b-3abd5b533496"
             },
             {
                 "memory_id": "2c9bd859-d1b7-4d33-a6b8-94e0147c4f07"
             }
         ]
     }'

PHP

<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.mem0.ai/v1/batch/",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "DELETE",
  CURLOPT_POSTFIELDS => json_encode([
    'memories' => [
        [
                'memory_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a'
        ]
    ]
  ]),
  CURLOPT_HTTPHEADER => [
    "Authorization: <api-key>",
    "Content-Type: application/json"
  ],
]);

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

curl_close($curl);

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

Go

package main

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

func main() {

url := "https://api.mem0.ai/v1/batch/"

payload := strings.NewReader("{\n  \"memories\": [\n    {\n      \"memory_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n    }\n  ]\n}")

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

req.Header.Add("Authorization", "<api-key>")
    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))
}

Java

HttpResponse<String> response = Unirest.delete("https://api.mem0.ai/v1/batch/")
  .header("Authorization", "<api-key>")
  .header("Content-Type", "application/json")
  .body("{\n  \"memories\": [\n    {\n      \"memory_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n    }\n  ]\n}")
  .asString();

Ruby

require 'uri'
require 'net/http'

url = URI("https://api.mem0.ai/v1/batch/")

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

request = Net::HTTP::Delete.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"memories\": [\n    {\n      \"memory_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n    }\n  ]\n}"

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

Response

200

400

{
  "message": "Successfully deleted 2 memories"
}
{
  "error": "Maximum of 1000 memories can be deleted in a single request"
}

Authorizations

Authorization
string
header
required
API key authentication. Prefix your Mem0 API key with 'Token '. Example: 'Token your_api_key'

Body

memories
object[]
required
Array of memory objects to delete.
Maximum array length: 1000

Response

message
string
Example:
"Successfully deleted 2 memories"