cURL
curl --request POST \
--url https://api.nano-gpt.com/api/v1/memory \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{
"content": "<string>"
}
],
"expiration_days": 30,
"model_context_limit": 128000
}
'import requests
url = "https://api.nano-gpt.com/api/v1/memory"
payload = {
"messages": [{ "content": "<string>" }],
"expiration_days": 30,
"model_context_limit": 128000
}
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({
messages: [{content: '<string>'}],
expiration_days: 30,
model_context_limit: 128000
})
};
fetch('https://api.nano-gpt.com/api/v1/memory', 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.nano-gpt.com/api/v1/memory",
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' => [
[
'content' => '<string>'
]
],
'expiration_days' => 30,
'model_context_limit' => 128000
]),
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.nano-gpt.com/api/v1/memory"
payload := strings.NewReader("{\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"expiration_days\": 30,\n \"model_context_limit\": 128000\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.nano-gpt.com/api/v1/memory")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"expiration_days\": 30,\n \"model_context_limit\": 128000\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.nano-gpt.com/api/v1/memory")
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 \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"expiration_days\": 30,\n \"model_context_limit\": 128000\n}"
response = http.request(request)
puts response.read_body{
"messages": [
{
"role": "<string>",
"content": "<string>"
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123,
"prompt_tokens_details": {
"cached_tokens": 123
}
}
}{
"error": 123,
"message": "<string>"
}{
"error": 123,
"message": "<string>"
}{
"error": 123,
"message": "<string>"
}Endpoint Examples
Context Memory (Standalone)
Compress a conversation with Context Memory and return compressed messages and usage (no model inference)
POST
/
v1
/
memory
cURL
curl --request POST \
--url https://api.nano-gpt.com/api/v1/memory \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{
"content": "<string>"
}
],
"expiration_days": 30,
"model_context_limit": 128000
}
'import requests
url = "https://api.nano-gpt.com/api/v1/memory"
payload = {
"messages": [{ "content": "<string>" }],
"expiration_days": 30,
"model_context_limit": 128000
}
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({
messages: [{content: '<string>'}],
expiration_days: 30,
model_context_limit: 128000
})
};
fetch('https://api.nano-gpt.com/api/v1/memory', 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.nano-gpt.com/api/v1/memory",
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' => [
[
'content' => '<string>'
]
],
'expiration_days' => 30,
'model_context_limit' => 128000
]),
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.nano-gpt.com/api/v1/memory"
payload := strings.NewReader("{\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"expiration_days\": 30,\n \"model_context_limit\": 128000\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.nano-gpt.com/api/v1/memory")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"expiration_days\": 30,\n \"model_context_limit\": 128000\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.nano-gpt.com/api/v1/memory")
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 \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"expiration_days\": 30,\n \"model_context_limit\": 128000\n}"
response = http.request(request)
puts response.read_body{
"messages": [
{
"role": "<string>",
"content": "<string>"
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123,
"prompt_tokens_details": {
"cached_tokens": 123
}
}
}{
"error": 123,
"message": "<string>"
}{
"error": 123,
"message": "<string>"
}{
"error": 123,
"message": "<string>"
}Overview
The standalone Context Memory endpoint compresses an entire conversation into a single memory message. This endpoint does not run a model. It returns the compressed memory message and usage so you can pipe it into your own chat completion request or store it.- No model inference is performed
- Pass your
messagesarray and optional settings
Authentication
Authorization: Bearer YOUR_API_KEYorx-api-key: YOUR_API_KEY
Request
Headers
Content-Type: application/jsonAuthorization: Bearer YOUR_API_KEYorx-api-key: YOUR_API_KEYmemory_expiration_days: <1..365>(optional) — overrides body; defaults to 30
Body
{
"messages": [
{ "role": "system", "content": "You are a helpful assistant." },
{ "role": "user", "content": "Summarize our previous discussion and continue." }
],
"expiration_days": 45,
"model_context_limit": 128000
}
messages(required): OpenAI-style messages.user,assistant,system,tool, andfunctionroles are accepted. Assistanttool_callsare ignored during compression.expiration_days(optional): 1..365; default 30. If both header and body are provided, the header takes precedence.model_context_limit(optional): Context target for compression. Default 128k; values below 10k are clamped internally.
Response
Success (200)
{
"messages": [
{ "role": "system", "content": "<compressed-context>..." }
],
"usage": {
"prompt_tokens": 51234,
"completion_tokens": 1234,
"total_tokens": 52468,
"prompt_tokens_details": {
"cached_tokens": 4096
}
}
}
messages: The single memory-compressed message array to use as your full context in a chat completion requestusage: Token usage. When available,prompt_tokens_details.cached_tokensindicates discounted cached input tokens
Error Examples
400 Bad Request
{ "error": "messages must be a non-empty array" }
401 Unauthorized
{ "error": "Invalid session" }
402 Payment Required
{ "error": "Insufficient balance" }
429 Too Many Requests
{ "error": "Rate limit exceeded. Please wait before sending another request." }
Pricing & Billing
- Non-cached input tokens: $5.00 / 1M
- Cached input tokens: $2.50 / 1M (when applicable)
- Output tokens: $10.00 / 1M
/v1/chat/completions, model costs are billed separately.
Retention
- Default retention: 30 days
- Configure via body
expiration_daysor headermemory_expiration_days - Header value takes precedence over body when both are supplied
Examples
const res = await fetch('https://api.nano-gpt.com/api/v1/memory', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
'memory_expiration_days': '45'
},
body: JSON.stringify({
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Optimize our previous plan and continue.' }
]
})
});
const { messages, usage } = await res.json();
// Use `messages` as the full context for a subsequent /v1/chat/completions call
import requests
url = 'https://api.nano-gpt.com/api/v1/memory'
headers = {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
}
data = {
'messages': [
{ 'role': 'system', 'content': 'You are a helpful assistant.' },
{ 'role': 'user', 'content': 'Summarize and continue.' }
],
'expiration_days': 30,
'model_context_limit': 128000
}
r = requests.post(url, headers=headers, json=data)
result = r.json()
print(result['messages'][0]['content'][:200])
print(result['usage'])
curl -X POST https://api.nano-gpt.com/api/v1/memory \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "memory_expiration_days: 90" \
-d '{
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Compress our conversation and continue."}
]
}'
Authorizations
bearerAuthapiKeyAuth
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
application/json
Parameters for memory compression
OpenAI-style messages array to compress
Show child attributes
Show child attributes
Retention in days (1..365). Defaults to 30 if not provided.
Required range:
1 <= x <= 365Target context size for compression (minimum enforced 10,000)