The Payment Flow
When a viewer wants to watch a paid video, the following sequence occurs:
Manifest Request (Free)
The video player first requests the HLS manifest file (.m3u8). This is always free — it only contains metadata about the video structure, not actual video data.
GET /assets/playbackId.m3u8 → 200 OKFirst Segment Request
When the player requests the first video segment, the server checks for a valid access token. If none exists, it returns HTTP 402 with payment details.
GET /assets/.../segment0.ts → 402 Payment Required{
"price": "$0.05",
"network": "base-sepolia",
"recipient": "0x...",
"description": "Access to full video (5 segments)"
}Payment Authorization
The wallet prompts the viewer to sign a payment authorization. This is a gasless signature that authorizes a USDC transfer.
Payment Verification
The signed authorization is sent to the x402 facilitator, which verifies the signature and settles the payment on-chain.
JWT Token Issued
After successful payment, the server issues a JWT (JSON Web Token) stored in a cookie. This token grants access to all segments of the video.
Set-Cookie: x402-playbackId=eyJhbGc...Video Playback
All subsequent segment requests include the JWT cookie. The server validates the token and streams the video without requiring additional payments.
GET /assets/.../segment1.ts + Cookie → 200 OKWhy This Approach?
🎯 Single Payment
Viewers pay once for the entire video, not per-segment. No wallet popup spam.
⚡ Stateless Validation
JWT tokens are self-contained. No database lookups needed to verify access.
🔄 Replay Friendly
Token is valid for 24 hours. Viewers can rewatch without paying again.
📱 Works Everywhere
Standard HTTP cookies work with any video player that supports credentials.
Dynamic Pricing
The payment amount is calculated based on the video segment count:
Total Price = Segment Count × Price Per SegmentFor example, a 5-segment video at $0.01/segment costs $0.05 total. This ensures fair pricing — longer videos cost more.