Overview
SessionPlugin provides per-payer key-value storage for aixyz agents. Each x402 signer gets an isolated session — two different payers never see each other’s data. Sessions are accessed via getSession() using AsyncLocalStorage, so tools don’t need to thread payer identity through function parameters.
SessionPlugin is always registered by the build pipeline. To use a custom storage backend, create an app/session.ts file.
Setup
SessionPlugin is auto-registered whenaixyz build or aixyz dev generates the server entrypoint. No manual setup is needed for the default in-memory store.
To use a custom store (Redis, database, etc.), create app/session.ts:
app/session.ts
app/session.ts and passes it to SessionPlugin({ store: sessionStore }). If no app/session.ts exists, the default InMemorySessionStore is used.
API
getSession()
Returns the current payer-scoped Session, or undefined if no x402 payment was made for this request.
getPayer()
Shorthand for getSession()?.payer. Returns the x402 signer address or undefined.
Session Interface
All operations are scoped to the current x402 payer automatically.SetOptions
ListOptions
ListResult
InMemorySessionStore
The default store. Uses LRU eviction and optional sliding-window TTL.- LRU eviction — when
maxEntriesis reached, the least-recently-used entry is evicted - Sliding-window TTL —
get()refreshes the expiry timer. Expired entries are lazily removed on read. - OOM-safe —
maxEntriesis a hard cap across all payers
Custom Storage Backend
Implement theSessionStore interface for Redis, a database, or any KV store:
app/session.ts
SessionStore Interface
Required methods:
Optional methods:
MCP Integration
Sessions work automatically inside MCP tool handlers. The MCP plugin detects the session plugin and wraps tool execution with the payer context from x402 payment verification. No additional configuration is needed.Constructor Options
x402 Payments
Payment protocol that provides payer identity for sessions.
x402 Sessions Template
Working example with session-backed content storage.