Skip to main content

How sessions work

A payment session is created when a paying request arrives with acceptSessions: true configured and the MPP challenge intent was session. The session is atomic — the PaymentSession and its linked Vault are created together, with a UNIQUE constraint on sessionId in the Vault table guaranteeing exactly one vault per session.

Session creation flow

The response includes the X-PRUDRA-SESSION-ID header. The agent stores this value and includes it in all subsequent requests.

Session reuse flow

No payment verification on session requests — the session ID is the authorization.

Session scoping

Sessions are scoped to the organisation. A session ID cannot be used across organisations. Two organisations can never accidentally share a session, even if they use the same session ID value (which is a UUID — collision is cryptographically unlikely).

The PaymentSession model

Session ID in your handler

After the middleware processes a session request, your handler has access to:
req.sessionId is set on both the first request (where it’s created) and subsequent requests (where it’s reused).

When a session expires

Session expiry is checked on every incoming session request. If expiresAt < now():
  1. The session lookup returns null
  2. payMiddleware falls through to normal payment flow
  3. A fresh 402 is returned with new challenges
  4. The agent must pay again to create a new session
The expired session’s vault is still accessible for reading — expiry only prevents new requests from attaching to the session.