Skip to main content

Memory API

The memory API is a small key value store for the things an agent should carry from one conversation to the next, such as a user's preferences, a project summary or the outcome of a previous run. Each entry has a key, a text value meant to be placed in a model's context, optional metadata, and a scope of a user id, a team id or both. The gateway stores it in the database and returns it to callers in the same scope, so an agent does not need its own database to remember things between sessions, and administrators can see and correct what agents remember.

Memory needs a database and no license feature. The Memory page in the Admin UI shows a banner saying the feature is on a draft deprecation list, with no removal date set.

Today only proxy admins can use the memory routes, and admin viewers can read them. A key with another role, such as an internal user key, a team key or an agent key, is refused with 401 by the gateway's route checks before the memory rules below are applied. So an agent that should read memory has to call with a proxy admin key, which can see and change every entry.

Scenario​

A support assistant answers questions about the platform team's monorepo. New engineers keep asking how releases are cut, and the assistant answers differently every time. A proxy admin stores one short summary under a shared key, the assistant's backend reads it with an admin key at the start of every conversation, and the admin fixes the text on the Memory page when the release day changes.

Steps​

  1. Write the entry with the key the agent will read, using a proxy admin key. Keys may contain slashes, so you can namespace them.

    curl -X PUT http://localhost:4000/v1/memory/project/platform/summary -H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json" \
    -d '{"value": "Platform is a monorepo. Releases cut from main every Tuesday.", "metadata": {"source": "onboarding"}, "team_id": "team-platform"}'
  2. In the agent, read it before the first model call with GET /v1/memory/project/platform/summary and put the value in the system prompt.

  3. To add or correct an entry by hand, open Memory under Agentic in the Admin UI, click New memory, fill Key and Value, optionally Metadata (optional JSON), and click Create. Use the row's Edit action to change the text and Delete, which asks you to type the key, to remove it.

  4. List what the team has stored with GET /v1/memory?key_prefix=project/platform/.

Expected result​

The PUT answers 200 with the stored row. team_id is the team the admin named in the body, and user_id and created_by are the calling key's user, here the master key's admin user (default_user_id). Without team_id in the body the row would take the calling key's team, which the master key does not have.

{
"memory_id": "3f6c2a9e-7b41-4d8a-9c55-1e2f3a4b5c6d",
"key": "project/platform/summary",
"value": "Platform is a monorepo. Releases cut from main every Tuesday.",
"metadata": {"source": "onboarding"},
"user_id": "default_user_id",
"team_id": "team-platform",
"created_by": "default_user_id",
"updated_at": "2026-10-16T10:14:00Z"
}

The Memory page lists the entry with its User ID and Team ID. Memory ids are UUIDs, and the Memory page search accepts a whole id or the start of a key.

Writing and reading​

Keys may contain slashes, so they can be namespaced. A key is unique across the whole gateway, not per user or team, so two entries can never share a key even in different scopes. Namespace keys by owner, for example user:123:notes or team:platform:summary.

PUT /v1/memory/{key} updates the provided fields of the entry with that key, or creates the entry for the caller's scope when no entry has the key. POST /v1/memory creates a new entry and answers 409 when any entry already holds the key, even one in a scope you cannot see. A PUT on a key held by an entry you cannot see answers 409 too, instead of creating a second entry. GET /v1/memory/{key} returns one entry, DELETE removes it, and GET /v1/memory lists entries with key, key_prefix and search filters, paged with page and page_size up to 500.

Scope and visibility​

On create, user_id and team_id default to the identity of the calling key. A proxy admin may set a different scope explicitly. The handlers also keep a non admin caller to entries whose user_id is their own or whose team_id is their own team, and only the owner, a team admin for a team entry, or a proxy admin may change or delete one. Those rules only take effect once non admin keys can reach the routes, which the route checks do not allow today, see the note at the top of this page.

Retention​

By default memory entries are kept until someone deletes them. Set maximum_memory_retention_period in the compliance settings, for example 90d, and the cleanup job deletes every entry that was not updated within that period. Turn it on when memories may hold personal facts you must not keep forever. After an entry is deleted, an agent that reads it gets 404, so write the agent to cope with a missing entry.

MethodPathSummary
GET/v1/memoryList memory entries
POST/v1/memoryCreate a memory entry
GET/v1/memory/{key}Read one memory entry
PUT/v1/memory/{key}Create or update a memory entry by key
DELETE/v1/memory/{key}Delete a memory entry

Admin UI​

The Memory page under Agentic lists entries with their scope and lets admins inspect, edit and delete them, see the Memory page.

Errors​

StatusMessageWhat it meansFix
400"Cannot create a memory entry without a user_id or team_id. Authenticate with a key that has a user_id or team_id, or call as a proxy admin."The calling key has no user or team, so the entry would be invisible to everyone.Use a key tied to a user or team, or set the scope as a proxy admin.
400"Request body must include at least one of: value, metadata."A PUT sent neither field.Send value, metadata or both.
400"Cannot create a new memory via PUT without a 'value'."A PUT for a key that does not exist yet sent no value.Send value.
401"Authentication Error, Only proxy admin can be used to generate, delete, update info for new keys/users/teams. ..."The key is not a proxy admin key, which the memory routes need today. Admin viewers may only read.Use a proxy admin key.
403"Only proxy admins may set user_id to a different user." or "... team_id to a different team."The body names a scope other than the caller's own.Leave user_id and team_id out.
403"You do not have permission to modify this memory entry."The caller may see the entry but does not own it.Ask the owner, a team admin or a proxy admin.
404"Memory with key '...' not found"No entry with that key is visible to the caller.Check the key on the Memory page, where admins see every scope.
409"Memory with key '...' already exists."Another entry, possibly one you cannot see, holds the key.Pick a namespaced key, or update the existing entry with PUT.
422{"detail": [...]}The body failed validation, for example key or value is missing on POST.Fix the field the loc names.
500"DB not connected ..." or "Internal error creating memory entry." (or listing, updating, deleting)The gateway has no database, or the database call failed. The cause is in the gateway log, never in the answer.Set DATABASE_URL, or check the log line below.

The error reference lists these next to the rest of the gateway's.

Audit​

Every memory change through the API or the Admin UI writes a row to the audit log on Spanway_MemoryTable, with the entry's memory_id as object_id and the action created, updated or deleted. The row keeps the key, metadata, user and team before and after the change, and leaves the stored text (value) out, because it can hold personal facts. Entries the retention job deletes write no row each, the Deleted <n> expired memory rows log line below records how many went.

Logs​

LevelLineWhat it meansAction
ERRORError creating memory: <error>, Error listing memory: <error>, Error upserting memory: <error>, Error deleting memory: <error>A database call failed and the caller got 500. The line carries the database error, which the answer leaves out.Check the database.
ERRORError loading team for write-auth check (team_id=<id>): <error>The gateway could not read the team to decide whether the caller is its admin, so the write was refused.Check the database.
INFODeleted <n> expired memory rowsThe retention job deleted entries older than maximum_memory_retention_period.None.
  • Memory page describes every control of the Admin UI page.
  • Custom agents do not read memory by themselves. An agent's tools or backend can call the memory API with a proxy admin key.
  • What Spanway stores lists where memory sits next to the other stores.