fetch() which pays per-request, sessions pay incrementally through vouchers on an open channel.
When to Use Sessions
| Use case | Method |
|---|---|
| Single request, get data, done | agent.fetch(url) |
| Multiple requests to same endpoint | agent.openSession(url) |
| SSE streaming with micropayments | session.stream(url) |
| MCP tool calls with payment | agent.wrapMcpClient(client) |
Lifecycle
Usage
Open a session
- Finds a configured Tempo wallet
- Computes the deposit:
min(available budget, sessionMaxDeposit config, user maxDeposit) - Reserves the deposit from the budget
- Opens a payment channel via mppx
Make requests
Usesession.fetch() for individual requests within the session:
Stream data
Usesession.stream() for SSE streaming with automatic voucher handling:
SessionEvent is a discriminated union:
Close the session
SessionReceipt:
Budget Enforcement
Sessions enforce budget at two points:-
At open — The deposit is reserved atomically from available budget. If insufficient budget remains,
openSession()throws. -
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
MppSessionBudgetErroris thrown.
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
- Budget & Safety — reservation/release pattern, orphan detection
- How It Works — session flow sequence diagram
- Configuration —
sessionMaxDepositconfig