What is 402 Retry Logic?
402 retry logic is the client-side pattern of re-requesting a resource after receiving an HTTP 402 Payment Required response — attaching a signed payment payload in the PAYMENT-SIGNATURE header on the retry attempt.
WHY IT MATTERS
The x402 protocol's core flow is a two-step interaction: the client first requests a resource and receives 402 with payment requirements, then retries with a payment signature attached. This retry is fundamental to how x402 works — it's not an error recovery mechanism but the normal payment flow.
The standard retry flow:
- Client sends
GET /resource - Server responds
402 Payment Requiredwith PAYMENT-REQUIRED header - Client constructs payment payload matching the requirements
- Client re-sends
GET /resourcewith PAYMENT-SIGNATURE header - Server verifies, settles, and returns 200 with resource
The x402 spec notes that steps 1-2 are optional if the client already knows the payment requirements — allowing a single-request flow for repeat purchases from known endpoints.
However, retry logic becomes dangerous when combined with autonomous agents and error states. If the server returns an error after payment (500, timeout, malformed response), a naïve retry loop pays again and again. PolicyLayer's analysis identified this as the infinite payment loop threat — a production system called GetOnStack once entered a recursive loop for 11 days, costing $47,000 in API costs. With x402, each retry costs real money.
Safe 402 retry logic requires: maximum retry counts, duplicate payment detection, exponential backoff, and per-endpoint circuit breakers.
HOW POLICYLAYER USES THIS
PolicyLayer's duplicate detection prevents the most dangerous retry failure mode — paying twice for the same resource. If an agent retries a request to the same endpoint within a configurable time window, the second payment is blocked. The circuit breaker pauses all payments after consecutive failures.