Python
# To use the Python SDK, install the package:
# pip install mem0ai
from mem0 import MemoryClient
client = MemoryClient(api_key="your_api_key")
json_schema = {pydantic_json_schema}
filters = {
"AND": [
{"user_id": "alex"}
]
}
response = client.create_memory_export(
schema=json_schema,
filters=filters
)
print(response)// To use the JavaScript SDK, install the package:
// npm i mem0ai
import MemoryClient from 'mem0ai';
const client = new MemoryClient({ apiKey: "your-api-key" });
const jsonSchema = {pydantic_json_schema};
const filters = {
AND: [
{user_id: 'alex'}
]
};
client.createMemoryExport({
schema: jsonSchema,
filters: filters
})
.then(result => console.log(result))
.catch(error => console.error(error));curl --request POST \
--url 'https://api.mem0.ai/v1/exports/' \
--header 'Authorization: Token <api-key>' \
--header 'Content-Type: application/json' \
--data '{
"schema": {pydantic_json_schema},
"filters": {
"AND": [
{"user_id": "alex"}
]
}
}'package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.mem0.ai/v1/exports/"
filters := map[string]interface{}{
"AND": []map[string]interface{}{
{"user_id": "alex"},
},
}
data := map[string]interface{}{
"schema": map[string]interface{}{}, // Your schema here
"filters": filters,
}
jsonData, _ := json.Marshal(data)
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
req.Header.Add("Authorization", "Token <api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(string(body))
}<?php
$curl = curl_init();
$filters = [
'AND' => [
['user_id' => 'alex']
]
];
$data = array(
"schema" => array(), // Your schema here
"filters" => $filters
);
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.mem0.ai/v1/exports/",
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($data),
CURLOPT_HTTPHEADER => [
"Authorization: Token <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;
}import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import org.json.JSONObject;
import org.json.JSONArray;
JSONObject filters = new JSONObject()
.put("AND", new JSONArray()
.put(new JSONObject().put("user_id", "alex")));
JSONObject data = new JSONObject()
.put("schema", new JSONObject()) // Your schema here
.put("filters", filters);
HttpResponse<JsonNode> response = Unirest.post("https://api.mem0.ai/v1/exports/")
.header("Authorization", "Token <api-key>")
.header("Content-Type", "application/json")
.body(data.toString())
.asJson();require 'uri'
require 'net/http'
url = URI("https://api.mem0.ai/v1/exports/")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"schema\": {},\n \"filters\": {\n \"user_id\": \"<string>\",\n \"agent_id\": \"<string>\",\n \"app_id\": \"<string>\",\n \"run_id\": \"<string>\"\n },\n \"org_id\": \"<string>\",\n \"project_id\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"message": "Memory export request received. The export will be ready in a few seconds.",
"id": "550e8400-e29b-41d4-a716-446655440000"
}{
"message": "Schema is required and must be a valid object"
}Memory Management
Create Memory Export
Submit an export job to create a structured memory export using a customizable Pydantic schema and filters.
POST
/
v1
/
exports
/
Python
# To use the Python SDK, install the package:
# pip install mem0ai
from mem0 import MemoryClient
client = MemoryClient(api_key="your_api_key")
json_schema = {pydantic_json_schema}
filters = {
"AND": [
{"user_id": "alex"}
]
}
response = client.create_memory_export(
schema=json_schema,
filters=filters
)
print(response)// To use the JavaScript SDK, install the package:
// npm i mem0ai
import MemoryClient from 'mem0ai';
const client = new MemoryClient({ apiKey: "your-api-key" });
const jsonSchema = {pydantic_json_schema};
const filters = {
AND: [
{user_id: 'alex'}
]
};
client.createMemoryExport({
schema: jsonSchema,
filters: filters
})
.then(result => console.log(result))
.catch(error => console.error(error));curl --request POST \
--url 'https://api.mem0.ai/v1/exports/' \
--header 'Authorization: Token <api-key>' \
--header 'Content-Type: application/json' \
--data '{
"schema": {pydantic_json_schema},
"filters": {
"AND": [
{"user_id": "alex"}
]
}
}'package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.mem0.ai/v1/exports/"
filters := map[string]interface{}{
"AND": []map[string]interface{}{
{"user_id": "alex"},
},
}
data := map[string]interface{}{
"schema": map[string]interface{}{}, // Your schema here
"filters": filters,
}
jsonData, _ := json.Marshal(data)
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
req.Header.Add("Authorization", "Token <api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(string(body))
}<?php
$curl = curl_init();
$filters = [
'AND' => [
['user_id' => 'alex']
]
];
$data = array(
"schema" => array(), // Your schema here
"filters" => $filters
);
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.mem0.ai/v1/exports/",
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($data),
CURLOPT_HTTPHEADER => [
"Authorization: Token <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;
}import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import org.json.JSONObject;
import org.json.JSONArray;
JSONObject filters = new JSONObject()
.put("AND", new JSONArray()
.put(new JSONObject().put("user_id", "alex")));
JSONObject data = new JSONObject()
.put("schema", new JSONObject()) // Your schema here
.put("filters", filters);
HttpResponse<JsonNode> response = Unirest.post("https://api.mem0.ai/v1/exports/")
.header("Authorization", "Token <api-key>")
.header("Content-Type", "application/json")
.body(data.toString())
.asJson();require 'uri'
require 'net/http'
url = URI("https://api.mem0.ai/v1/exports/")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"schema\": {},\n \"filters\": {\n \"user_id\": \"<string>\",\n \"agent_id\": \"<string>\",\n \"app_id\": \"<string>\",\n \"run_id\": \"<string>\"\n },\n \"org_id\": \"<string>\",\n \"project_id\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"message": "Memory export request received. The export will be ready in a few seconds.",
"id": "550e8400-e29b-41d4-a716-446655440000"
}{
"message": "Schema is required and must be a valid object"
}Submit a job to create a structured export of memories using a customizable Pydantic schema. This process may take some time to complete, especially if you’re exporting a large number of memories. You can tailor the export by applying various filters (e.g.,
user_id, agent_id, app_id, or run_id) and by modifying the Pydantic schema to ensure the final data matches your exact needs.Authorizations
API key authentication. Prefix your Mem0 API key with 'Token '. Example: 'Token your_api_key'
Body
application/json
Was this page helpful?
⌘I