Optimize User Memories
curl --request POST \
--url https://api.example.com/optimize-memories \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"user_id": "<string>",
"model": "<string>",
"apply": true
}
'import requests
url = "https://api.example.com/optimize-memories"
payload = {
"user_id": "<string>",
"model": "<string>",
"apply": True
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({user_id: '<string>', model: '<string>', apply: true})
};
fetch('https://api.example.com/optimize-memories', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/optimize-memories",
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([
'user_id' => '<string>',
'model' => '<string>',
'apply' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"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.example.com/optimize-memories"
payload := strings.NewReader("{\n \"user_id\": \"<string>\",\n \"model\": \"<string>\",\n \"apply\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.example.com/optimize-memories")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"user_id\": \"<string>\",\n \"model\": \"<string>\",\n \"apply\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/optimize-memories")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"user_id\": \"<string>\",\n \"model\": \"<string>\",\n \"apply\": true\n}"
response = http.request(request)
puts response.read_body{
"memories": [
{
"memory_id": "f9361a69-2997-40c7-ae4e-a5861d434047",
"memory": "User has a 3-year-old golden retriever named Max who loves fetch and walks. Lives in San Francisco's Mission district, works as a product manager in tech. Enjoys hiking Bay Area trails, trying new restaurants (especially Japanese, Thai, Mexican), and learning piano for 1.5 years.",
"topics": [
"pets",
"location",
"work",
"hobbies",
"food_preferences"
],
"user_id": "user2",
"updated_at": "2025-11-18T10:30:00Z"
}
],
"memories_before": 4,
"memories_after": 1,
"tokens_before": 450,
"tokens_after": 180,
"tokens_saved": 270,
"reduction_percentage": 60
}{
"detail": "Bad request"
}{
"detail": "Unauthenticated access"
}{
"detail": "Not found"
}{
"detail": [
{
"loc": [
"body",
"endpoint"
],
"msg": "Value error, Endpoint must be a path, not a full URL",
"type": "value_error"
}
]
}{
"detail": "Internal server error"
}Memory
Optimize User Memories
Optimize all memories for a given user using the default summarize strategy. This operation combines all memories into a single comprehensive summary, achieving maximum token reduction while preserving all key information. To use a custom model, specify the model parameter in ‘provider:model_id’ format (e.g., ‘openai:gpt-4o-mini’, ‘anthropic:claude-3-5-sonnet-20241022’). If not specified, uses MemoryManager’s default model (gpt-4o). Set apply=false to preview optimization results without saving to database.
POST
/
optimize-memories
Optimize User Memories
curl --request POST \
--url https://api.example.com/optimize-memories \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"user_id": "<string>",
"model": "<string>",
"apply": true
}
'import requests
url = "https://api.example.com/optimize-memories"
payload = {
"user_id": "<string>",
"model": "<string>",
"apply": True
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({user_id: '<string>', model: '<string>', apply: true})
};
fetch('https://api.example.com/optimize-memories', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/optimize-memories",
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([
'user_id' => '<string>',
'model' => '<string>',
'apply' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"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.example.com/optimize-memories"
payload := strings.NewReader("{\n \"user_id\": \"<string>\",\n \"model\": \"<string>\",\n \"apply\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.example.com/optimize-memories")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"user_id\": \"<string>\",\n \"model\": \"<string>\",\n \"apply\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/optimize-memories")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"user_id\": \"<string>\",\n \"model\": \"<string>\",\n \"apply\": true\n}"
response = http.request(request)
puts response.read_body{
"memories": [
{
"memory_id": "f9361a69-2997-40c7-ae4e-a5861d434047",
"memory": "User has a 3-year-old golden retriever named Max who loves fetch and walks. Lives in San Francisco's Mission district, works as a product manager in tech. Enjoys hiking Bay Area trails, trying new restaurants (especially Japanese, Thai, Mexican), and learning piano for 1.5 years.",
"topics": [
"pets",
"location",
"work",
"hobbies",
"food_preferences"
],
"user_id": "user2",
"updated_at": "2025-11-18T10:30:00Z"
}
],
"memories_before": 4,
"memories_after": 1,
"tokens_before": 450,
"tokens_after": 180,
"tokens_saved": 270,
"reduction_percentage": 60
}{
"detail": "Bad request"
}{
"detail": "Unauthenticated access"
}{
"detail": "Not found"
}{
"detail": [
{
"loc": [
"body",
"endpoint"
],
"msg": "Value error, Endpoint must be a path, not a full URL",
"type": "value_error"
}
]
}{
"detail": "Internal server error"
}Authorizations
Query Parameters
Body
application/json
Schema for memory optimization request
Response
Memories optimized successfully
Schema for memory optimization response
Was this page helpful?