Skip to main content
Sessions let you open a persistent payment channel to an MPP endpoint, make multiple requests, and stream data with per-voucher micropayments. Unlike fetch() which pays per-request, sessions pay incrementally through vouchers on an open channel.

When to Use Sessions

Lifecycle

Usage

Open a session

The SDK:
  1. Finds a configured Tempo wallet
  2. Computes the deposit: min(available budget, sessionMaxDeposit config, user maxDeposit)
  3. Reserves the deposit from the budget
  4. Opens a payment channel via mppx

Make requests

Use session.fetch() for individual requests within the session:

Stream data

Use session.stream() for SSE streaming with automatic voucher handling:
SessionEvent is a discriminated union:

Close the session

SessionReceipt:
Closing releases unused deposit back to the budget.

Budget Enforcement

Sessions enforce budget at two points:
  1. At open — The deposit is reserved atomically from available budget. If insufficient budget remains, openSession() throws.
  2. Per voucher — Each voucher’s cumulative amount is checked against the reserved deposit. If cumulative spend exceeds the deposit, the session is force-closed and a MppSessionBudgetError is thrown.
See Budget & Safety for the full reservation/release pattern.

Events

Sessions emit four event types:

Requirements

  • A Tempo wallet must be configured (sessions use Tempo payment channels)
  • Budget must have sufficient capacity for the deposit
  • The endpoint must support MPP session protocol

Next Steps