Session Server
The session server SDK handles voucher verification, challenge generation, and session context tracking. Sellers integrate it into their API server to accept session-based payments.
Quick Start
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
recipient | string | required | Solana wallet address to receive session settlements |
pricePerUnit | string | required | Minimum payment per request in atomic USDC units |
apiUrl | string | https://x402.dexter.cash | Settlement API base URL |
network | string | mainnet-beta | Solana cluster |
meter | function | none | Custom metering function for variable pricing |
suggestedDeposit | string | none | Suggested deposit amount returned in challenges |
Methods
getChallenge()
Returns a 402 challenge object for clients that don't have a voucher. The challenge includes the recipient, price, network, and suggested deposit so the client knows how to open a session.
verifyVoucher(voucher)
Verifies a signed voucher. Returns { valid: true } or { valid: false, error: string }.
Verification checks:
- Ed25519 signature is valid
- Cumulative amount is monotonically increasing
- Sequence number is strictly increasing
- Amount meets or exceeds pricePerUnit
- Signer pubkey is consistent across all vouchers in the channel
getSessionContext(channelId)
Returns the current session state for a channel, including cumulative amount and voucher count. Returns undefined if no vouchers have been verified for the channel.
removeSession(channelId)
Removes a session from the server's tracking state. Call this when notified that a session has closed.
Custom Metering
For variable pricing (per-token, per-byte, per-record), provide a meter function:
Express Integration
Full Express example with error handling:
What Happens at Session Close
When the buyer closes a session, Dexter executes a single TransferChecked instruction from the buyer's Swig wallet to your recipient address for the cumulative amount consumed. You do not need to do anything. The settlement is final once confirmed on-chain.
Read Next
- Session Client for the buyer-side integration
- Sessions Overview for the non-custodial model and architecture
- API Reference for endpoint schemas