How it works
Gateway and retries
What reaches a provider API, and what happens when it fails after payment.
What reaches your API
The request path is appended to your upstream’s base path: /weather/paris becomes
https://api.acme.example/v1/weather/paris.
| Forwarded | Never forwarded |
|---|---|
| Path, query and body | The agent’s IP address and forwarding headers |
content-type, accept, user-agent, and other non-reserved x- headers | Authorization and cookies |
X-Px402-Proxy-Secret | PAYMENT-SIGNATURE |
X-Px402-Payment-Id, X-Px402-Route-Id, X-Px402-Attempt | The payer’s wallet address |
On the way back, Location and Set-Cookie never reach the agent.
Your side of the contract
- Refuse any request without the right
X-Px402-Proxy-Secret. Otherwise anyone who finds your API can call it for free. - Dedupe on
X-Px402-Payment-Id. Delivery is at least once. The earning is counted exactly once. - Send the first byte within 10 s and finish within 30 s, in at most 5 MiB.
- Do not redirect. A redirect is a failed attempt.
The gateway only forwards to your admin-approved upstream: HTTPS on port 443, on your verified domain, resolving to a public address.
When your API fails after payment
The money has already moved, so the payment stays bound to its nonce and the agent retries with the same payment.
- 01Agent → px402 gatewayThe first verified claim binds the payment and opens a 300 s retry window.
- 02px402 gateway → Provider APIThe gateway takes a 45 s lease and forwards the call.
- 03Provider API → px402 gatewayA 5xx, a redirect, 401, 407, 408, 425, 429, a timeout or a network error.
- 04px402 gateway → AgentThe answer carries retry.until, the attempt number and the maximum of 5.
- 05Agent → px402 gatewayThe SDK resends the same PAYMENT-SIGNATURE. It does not pay again.
- 06px402 gateway → Provider APIA new attempt under a new lease.
- 07Provider API → px402 gatewayThe provider answers.
- 08px402 gateway → AgentServed, and the earning is counted once, for the attempt that held the live lease.
| Situation | Answer |
|---|---|
| Another attempt is running | 409 CLAIM_IN_PROGRESS; retry |
| The upstream failed | 503 UPSTREAM_FAILED; retry until retry.until |
| 5 attempts failed, or the window closed | 409 CLAIM_LAPSED. This is a refund case |
Providers list refund cases with px402 provider refunds --provider <providerId>. Refunds are manual today.