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",
"error_code": "BAD_REQUEST"
}{
"detail": "Unauthenticated access",
"error_code": "UNAUTHENTICATED"
}{
"detail": "Insufficient permissions"
}{
"detail": "Not found",
"error_code": "NOT_FOUND"
}{
"detail": "Validation error",
"error_code": "VALIDATION_ERROR"
}{
"detail": "Internal server error",
"error_code": "INTERNAL_SERVER_ERROR"
}Optimize User Memories
Optimize all memories for a user with the summarize strategy. The operation combines the user’s memories into one summary. Set apply=false to preview the result without saving it. Specify a custom model as provider:model_id, for example openai:gpt-5.4-mini, anthropic:claude-sonnet-4-6, or google:gemini-3.5-flash. If omitted, Agno v2.7.4 uses MemoryManager’s default model, gpt-4o.
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",
"error_code": "BAD_REQUEST"
}{
"detail": "Unauthenticated access",
"error_code": "UNAUTHENTICATED"
}{
"detail": "Insufficient permissions"
}{
"detail": "Not found",
"error_code": "NOT_FOUND"
}{
"detail": "Validation error",
"error_code": "VALIDATION_ERROR"
}{
"detail": "Internal server error",
"error_code": "INTERNAL_SERVER_ERROR"
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Query Parameters
Database ID to use for optimization
Table to use for optimization
Body
Schema for memory optimization request
User ID to optimize memories for
Model in provider:model_id format. Current examples include openai:gpt-5.4-mini, anthropic:claude-sonnet-4-6, and google:gemini-3.5-flash. If omitted, Agno v2.7.4 uses MemoryManager's default model, gpt-4o.
If True, apply optimization changes to database. If False, return preview only without saving.
Response
Memories optimized successfully
Schema for memory optimization response
List of optimized memory objects
Show child attributes
Show child attributes
Number of memories before optimization
x >= 0Number of memories after optimization
x >= 0Token count before optimization
x >= 0Token count after optimization
x >= 0Number of tokens saved through optimization
x >= 0Percentage of token reduction achieved
0 <= x <= 100Was this page helpful?