Make an API Call with the Agent Memory API
- how-to
How to make an API call with the Agent Memory API on a self-managed Agent Memory server.
This page is for self-managed Agent Memory.
Use the Agent Memory API to store and retrieve memory for your AI agents on your Agent Memory server.
Prerequisites
To make an API call with the Agent Memory API, you need:
-
An access token, if your Agent Memory server uses authentication.
Make an API Call
You can use a client such as curl to make an API call with the Agent Memory API.
To make an API call with the Agent Memory API:
-
Use the hostname and port of your Agent Memory server as the base URL:
http://<HOST>:<PORT> -
If your Agent Memory server uses authentication, pass the access token as a Bearer token using the HTTP
Authorizationheader. -
If the endpoint requires a request body, pass it in JSON format.
Alternatively, you can use a client such as Insomnia or Postman to explore the details of the REST API. The Agent Memory API uses an OpenAPI v3 specification. To download the Agent Memory API specification, go to the Agent Memory API Reference and click Download.
Examples
The following examples show how to store memory with the Agent Memory API. Run them in order, because each example uses the user or session created in the previous one:
If your Agent Memory server does not use authentication, remove the Authorization header from each example.
Create a User
The following POST request creates a user.
You choose the user_id, which must be unique.
-
$BASE_URLis the base URL. This is the hostname and port of your Agent Memory server. -
$TOKENis your access token, used as the Bearer token.
curl "$BASE_URL/users" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"user_id": "user_123",
"name": "John Doe"
}'
The response is a JSON object similar to the following.
{
"id": "user_123",
"name": "John Doe",
"sessions": [],
"metadata": {}
}
The response includes the user ID.
You can use the user ID for any further API calls in which {USER_ID} is a path parameter.
Create a Session
The following POST request creates a session for the user.
You choose the session_id, which must be unique for the user.
-
$BASE_URLis the base URL. This is the hostname and port of your Agent Memory server. -
$TOKENis your access token, used as the Bearer token.
curl "$BASE_URL/users/user_123/sessions" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"session_id": "session_456"
}'
The response is a JSON object similar to the following.
{
"user_id": "user_123",
"session_id": "session_456",
"start_time": "2026-09-24 14:30:00.123456",
"end_time": null,
"annotations": {},
"metadata": {},
"blocks_ttl": null
}
The response includes the session ID.
You can use the session ID for any further API calls in which {SESSION_ID} is a path parameter.
Add Memory Blocks
The following POST request adds 2 facts to the session as memory blocks.
The request sets async_processing to false, so Agent Memory processes the memory blocks before it returns a response.
You can then search the memory blocks immediately.
-
$BASE_URLis the base URL. This is the hostname and port of your Agent Memory server. -
$TOKENis your access token, used as the Bearer token.
curl "$BASE_URL/users/user_123/sessions/session_456/memory" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"facts": [
"User prefers email notifications",
"User is allergic to peanuts"
],
"async_processing": false
}'
The response is a JSON object similar to the following.
{
"message": "Successfully added 2 memory block(s).",
"accepted_count": 2,
"block_ids": [
"<BLOCK_ID_1>",
"<BLOCK_ID_2>"
],
"rejected_count": 0,
"rejected_details": null
}
The response includes the ID of each memory block that Agent Memory added.
Next Steps
-
For more information about the Agent Memory API, see Agent Memory API for Self-Managed Deployments.
-
For a full reference guide, see Agent Memory API Reference.
-
For an error reference, see The Agent Memory API Errors.