Memory API
Programmatically manage conversation sessions and memory from your applications.
Overview
The Memory API allows you to manage conversation sessions programmatically. Create, list, update, and delete sessions directly from your application using the same superAgentKey authentication.
Authentication
superAgentKey header for authentication. The same key you use for chat completions works here.Base URL
https://www.superagentstack.com/api/v1/memoryAuthentication
Include your Super Agent Stack API key in the request headers:
curl -X GET https://www.superagentstack.com/api/v1/memory/sessions \
-H "superAgentKey: YOUR_SUPER_AGENT_KEY"List Sessions
/api/v1/memory/sessionsRetrieve all conversation sessions for your account.
Query Parameters
| Parameter | Type | Description |
|---|---|---|
limit | number | Max sessions to return (1-100, default: 50) |
const response = await fetch('https://www.superagentstack.com/api/v1/memory/sessions?limit=20', {
headers: {
'superAgentKey': process.env.SUPER_AGENT_KEY
}
});
const { data } = await response.json();
console.log(data);
// [{ id: "uuid", title: "Chat about AI", createdAt: "...", messageCount: 5 }, ...]Create Session
/api/v1/memory/sessionsCreate a new conversation session. You can optionally provide a custom session ID.
Request Body
| Field | Type | Description |
|---|---|---|
title | string (optional) | Session title (max 255 chars) |
sessionId | string (optional) | Custom UUID for the session |
const response = await fetch('https://www.superagentstack.com/api/v1/memory/sessions', {
method: 'POST',
headers: {
'superAgentKey': process.env.SUPER_AGENT_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({
title: 'Customer Support Chat'
})
});
const { data } = await response.json();
console.log(data.id); // Use this sessionId in chat completionsGet Session
/api/v1/memory/sessions/:sessionIdRetrieve details of a specific session.
const sessionId = 'your-session-uuid';
const response = await fetch(`https://www.superagentstack.com/api/v1/memory/sessions/${sessionId}`, {
headers: {
'superAgentKey': process.env.SUPER_AGENT_KEY
}
});
const { data } = await response.json();
console.log(data);
// { id: "uuid", title: "...", createdAt: "...", messageCount: 10, isArchived: false }Delete Session
/api/v1/memory/sessions/:sessionIdPermanently delete a session and all its messages. This action cannot be undone.
Destructive Action
const sessionId = 'your-session-uuid';
const response = await fetch(`https://www.superagentstack.com/api/v1/memory/sessions/${sessionId}`, {
method: 'DELETE',
headers: {
'superAgentKey': process.env.SUPER_AGENT_KEY
}
});
const result = await response.json();
console.log(result);
// { success: true, message: "Session deleted successfully" }Python Example
import requests
import os
session_id = "your-session-uuid"
response = requests.delete(
f"https://www.superagentstack.com/api/v1/memory/sessions/{session_id}",
headers={
"superAgentKey": os.environ.get("SUPER_AGENT_KEY")
}
)
result = response.json()
print(result) # {"success": True, "message": "Session deleted successfully"}cURL Example
curl -X DELETE https://www.superagentstack.com/api/v1/memory/sessions/YOUR_SESSION_ID \
-H "superAgentKey: YOUR_SUPER_AGENT_KEY"Archive Session
/api/v1/memory/sessions/:sessionId/archiveArchive a session instead of deleting it. Archived sessions are hidden from the default list but can be restored later.
const sessionId = 'your-session-uuid';
const response = await fetch(`https://www.superagentstack.com/api/v1/memory/sessions/${sessionId}/archive`, {
method: 'POST',
headers: {
'superAgentKey': process.env.SUPER_AGENT_KEY
}
});
const result = await response.json();
// { success: true, message: "Session archived successfully" }Get Session Messages
/api/v1/memory/sessions/:sessionId/messagesRetrieve all messages from a specific session.
const sessionId = 'your-session-uuid';
const response = await fetch(`https://www.superagentstack.com/api/v1/memory/sessions/${sessionId}/messages?limit=50`, {
headers: {
'superAgentKey': process.env.SUPER_AGENT_KEY
}
});
const { data } = await response.json();
console.log(data);
// [{ role: "user", content: "Hello", createdAt: "..." }, { role: "assistant", content: "Hi!", createdAt: "..." }]Complete Example: Session Lifecycle
Here's a complete example showing how to manage sessions in a chat application:
import OpenAI from 'openai';
const SUPER_AGENT_KEY = process.env.SUPER_AGENT_KEY;
const BASE_URL = 'https://www.superagentstack.com';
// 1. Create a new session
async function createSession(title) {
const response = await fetch(`${BASE_URL}/api/v1/memory/sessions`, {
method: 'POST',
headers: {
'superAgentKey': SUPER_AGENT_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({ title })
});
const { data } = await response.json();
return data.id;
}
// 2. Use the session for chat
async function chat(sessionId, message) {
const client = new OpenAI({
baseURL: `${BASE_URL}/api/v1`,
apiKey: process.env.OPENROUTER_API_KEY,
defaultHeaders: {
'superAgentKey': SUPER_AGENT_KEY,
'sessionId': sessionId
}
});
const response = await client.chat.completions.create({
model: 'google/gemini-2.0-flash-exp:free',
messages: [{ role: 'user', content: message }]
});
return response.choices[0].message.content;
}
// 3. Delete session when done
async function deleteSession(sessionId) {
const response = await fetch(`${BASE_URL}/api/v1/memory/sessions/${sessionId}`, {
method: 'DELETE',
headers: { 'superAgentKey': SUPER_AGENT_KEY }
});
return response.json();
}
// Usage
async function main() {
// Create session
const sessionId = await createSession('Customer Support');
console.log('Created session:', sessionId);
// Chat with memory
const reply1 = await chat(sessionId, 'My name is Alice');
console.log('AI:', reply1);
const reply2 = await chat(sessionId, 'What is my name?');
console.log('AI:', reply2); // Will remember "Alice"
// Clean up when done
await deleteSession(sessionId);
console.log('Session deleted');
}
main();Error Responses
| Status | Error | Description |
|---|---|---|
| 401 | Unauthorized | Missing or invalid superAgentKey |
| 404 | Not Found | Session does not exist or belongs to another user |
| 500 | Server Error | Internal error - contact support if persistent |