Suppose a data service charges a machine for one response without creating an account or opening a checkout page. x402 facilitates that x402 machine-to-machine micropayment by placing price and payment instructions inside the HTTP resource exchange. The client applies policy, produces payment evidence, and retries the same resource request.
This flow removes several human-oriented steps from a per-request purchase: account creation, manual checkout, invoice exchange, and card entry. It does not remove financial controls. It also does not prove that the service delivered the promised result.
The production design therefore has two linked state machines. x402 coordinates payment for resource access. Merchant infrastructure coordinates order creation, one-time execution, delivery, retries, refunds, and reconciliation.
Four Actors Complete the Payment Handshake
The resource server owns the paid API, file, MCP tool, model call, or digital service. It defines the resource and the acceptable payment requirements.
The machine client may be an AI agent, backend service, device, or automation. It interprets the requirement, checks policy, and asks a wallet to produce the payment evidence.
The wallet or signer controls funds and authorization. It should not sign solely because a server returned a price. It validates amount, asset, network, destination, resource, expiry, and budget.
A facilitator is an optional service that can verify and settle supported payments for the resource server. It reduces the need for each merchant to implement network-specific payment verification and settlement logic. A seller can also implement compatible verification directly.
The merchant system sits beside the protocol roles. It tracks the product, quote, purchase, payment, execution, delivery, refund, and accounting state. In a toy API, the resource server and merchant may be one process. Their state responsibilities should remain distinct.
The direct answer can be represented as:
request -> 402 requirement -> policy -> payment evidence -> retry -> verification -> resource
The commercial answer continues:
purchase -> execute once -> deliver -> record -> reconcile or refund
That second line is why x402 enables machine commerce without defining all of it.
Step 1: Return the Payment Requirement
An ordinary unpaid request reaches a protected route. The server does not redirect the client to a visual checkout. It returns HTTP status 402 and structured information describing how to pay for the resource.
In x402 v2, the PAYMENT-REQUIRED header carries the encoded requirement envelope. The exact payment option includes fields needed by its payment scheme and network. The client can inspect available choices and determine whether any fit policy.
A useful requirement binds:
the protected resource or route;
payment amount and asset;
network and payment scheme;
destination or payee;
validity or timeout;
a human-readable description where useful;
protocol and extension information.
The binding matters. A valid signature for the right amount should not be reusable against an unintended resource, destination, or network. The client should reject malformed, ambiguous, expired, or unsupported requirements.
The quote should also be stable enough for retries. If the price changes on every request, the client can enter a loop. Dynamic pricing needs a quote identifier and expiry. The server should either honor the accepted quote or return a clear new requirement without charging the old attempt twice.
HTTP makes the payment challenge transport-native. The same request path that describes a missing authentication token can now describe a missing payment, with machine-readable remediation.
Step 2: Authorize the Purchase
Automatic payment means software can complete an approved purchase without a person clicking a checkout button. It does not mean the agent can pay without limits.
The client should treat every 402 requirement as untrusted input. A compromised service can request a higher amount, different token, unknown network, or malicious destination. The model interpreting the service should not be the final authority.
Deterministic policy can check:
Policy dimension | Example rule |
|---|---|
Task budget | Total paid services stay below the workflow cap |
Per-payment limit | One call cannot exceed the configured amount |
Service identity | Endpoint and payee match an approved service |
Asset/network | Only supported stablecoin and network combinations |
Resource | Payment is bound to the intended API or tool |
Time | Quote has not expired |
Frequency | Calls per minute and cumulative spend are bounded |
Risk | New or low-reputation services require review |
The wallet should receive the normalized requirement and policy decision, not natural-language instructions alone. It signs the precise payload required by the selected payment scheme.
Balance management remains separate. An agent needs enough supported funds and, where relevant, transaction fees. Treasury automation may refill or rebalance within policy. A failed balance check should stop the purchase cleanly and preserve the quote for later retry if it remains valid.
This boundary is what makes machine payment operationally defensible: protocol automation below a deterministic spending ceiling.
Step 3: Verify Payment Evidence
After the client creates payment evidence, the server needs to establish that it satisfies the requirement. Verification checks the cryptographic and protocol conditions. Settlement completes the value movement under the selected payment method.
A facilitator can provide verify and settle capabilities for supported networks, schemes, and assets. The resource server sends the requirement and client evidence to the facilitator. The facilitator returns a result the server can use in its access decision.
This model simplifies seller integration. The facilitator can maintain network connectivity, payment-scheme logic, settlement handling, and consistent error responses. The tradeoff is provider dependency, supported-method scope, latency, fees, credentials, and service availability.
Direct verification gives the merchant more control. It also makes the merchant responsible for chain-specific logic, node access, confirmation policy, replay prevention, operational keys, and upgrades.
Neither path eliminates application verification. The server must confirm that the verified payment corresponds to its current resource, amount, purchase, and customer request. A generic “payment valid” response is insufficient if it can be attached to another order.
Verification and settlement may also be separate events. The merchant state should record which one authorizes delivery under its policy. For a low-value digital response, verified authorization may be enough. A high-value or reversible service may require stronger settlement evidence.
Step 4: Retry the Resource Request
The client retries the original request with payment evidence in the PAYMENT-SIGNATURE header under x402 v2. The server re-evaluates the protected route, extracts the evidence, and verifies it against the accepted requirement.
A successful response can include a PAYMENT-RESPONSE header describing the payment result. The client should store it with the resource response and purchase identifier.
The retry must preserve request identity. For a GET data resource, the route and query can identify the purchase target. For a state-changing POST, the server needs a stable idempotency or purchase key. Network retries, client timeouts, and model retries should converge on one commercial attempt.
The payment identifier extension can help correlate payment across components. It does not replace merchant idempotency. The merchant still needs a unique constraint that prevents two workers from delivering or charging the same purchase twice.
The server should reject:
evidence for another requirement;
an expired quote;
a replay outside allowed use;
an amount or asset mismatch;
an unsupported payment method;
a payment already consumed for a one-time resource;
evidence whose payee or resource binding differs.
On success, the protocol handshake is complete. The commercial transaction may still be executing.
Step 5: Fulfill Once and Reconcile
A production merchant should create a durable purchase before or when it issues a requirement. The purchase contains resource, price, quote version, expiry, customer or client reference where available, and idempotency key.
Payment verification moves the purchase to payment_verified. One worker obtains an execution lease and performs the service. The result is stored before the response is acknowledged. Delivery moves the purchase to delivered with a result hash or receipt.
This sequence prevents a common failure. The server verifies payment, starts expensive work, and loses the HTTP connection. Without durable state, the retry may execute again or ask for another payment. With purchase state, the client can retrieve the existing result.
A compact state model is:
Payment state | Delivery state | Meaning |
|---|---|---|
unpaid | not_started | 402 can be returned |
authorized | not_started | evidence exists but server has not accepted it |
verified | queued | purchase may execute once |
verified | running | execution lease is active |
verified | delivered | return stored result |
verified | failed_retryable | retry execution without repaying |
verified | failed_final | refund or manual resolution |
settled | refunded | value returned under merchant policy |
Webhooks can update payment or settlement state. They must be signed, deduplicated, and recoverable through polling or reconciliation because delivery can be delayed or lost.
x402 does not prescribe the product catalog, tax record, invoice, refund policy, service-level agreement, or proof of delivery. Merchant infrastructure owns those functions.
Micropayment Economics Depend on the Full Request Cost
A small payment is viable when revenue per successful request exceeds all variable costs and contributes enough to fixed operations.
Use this model:
contribution = price - service cost - payment cost - network cost - failure allowance - support allowance
Service cost may include model inference, data licensing, storage, bandwidth, or third-party tools. Payment cost includes facilitator or verification overhead. Network cost includes settlement and fee exposure. Failure allowance covers retries, refunds, and paid-but-undelivered cases.
A hypothetical data endpoint priced at $0.01 can work when the data response is cheap, payment overhead is low, and automated delivery succeeds reliably. It can fail economically if a $0.01 charge triggers expensive onchain action, manual support, or high refund frequency.
Granularity is a product decision. A merchant can charge per call, token, result, task, time window, or bundle. Very small calls may be batched into credits or session budgets. x402 enables per-request payment. It does not require the smallest possible unit.
Machine customers make price discovery important. The requirement should expose the price before authorization. Agents can compare providers and stop when a task budget no longer supports the next service.
For a multi-service workflow, the agent needs a total budget. A search call, scraping tool, model inference, and verification service may each be inexpensive. Their sum plus retries can exceed the task value. Policy should reserve budget for required later stages and define a stop condition.
Scenario: One Machine Buys Three Services
Assume a research agent has a $0.20 task budget. It needs a search result, a document extraction, and a verification score. Each provider exposes a paid HTTP resource with x402 requirements.
The search service returns a $0.02 requirement. The agent's policy recognizes the endpoint, asset, network, and payee. It reserves $0.02 plus a retry allowance, pays, and stores the response with purchase ID search-1.
The extraction service prices by document size and returns a $0.07 quote that expires in two minutes. The agent checks that the document hash in the requirement matches the file selected during planning. After payment, the service times out before returning a result.
The agent does not immediately pay again. It queries the existing purchase. The merchant reports payment_verified and failed_retryable. A worker resumes extraction under the same purchase ID and stores the result. The agent receives it without a second charge.
The verification service returns two payment options on different supported networks. Policy compares available balances, allowed assets, transaction overhead, and remaining budget. It selects a $0.03 option. Route selection is deterministic; the model cannot choose an unapproved network merely because it appears cheaper.
The complete task spends $0.12 and leaves $0.08 unspent. More importantly, it produces three independent commercial records. Each has its own requirement, payment evidence, merchant state, delivery receipt, and settlement status. The workflow trace links them under one task ID.
Now suppose the verification result is invalid JSON. Payment and delivery transport both succeeded, but product quality failed. The agent applies the service contract: retry parsing if the bytes are unchanged, ask the merchant to re-execute if the output violates its schema, or enter refund review. x402 does not decide which remedy applies.
This scenario shows how micropayments compose. The agent does not manage one unrestricted wallet action. It manages a task budget across several quotes, policy decisions, purchases, retries, and stop conditions. Each service remains independently replaceable because payment and delivery evidence are machine-readable.
Failures Must Preserve Payment and Delivery Evidence
Consider the same paid data request under seven faults.
Fault | Correct behavior |
|---|---|
Quote expires | Return a new requirement; do not accept stale evidence |
Insufficient funds | Stop before signing; keep task state recoverable |
Duplicate client retry | Resolve to the same purchase and result |
Payment replay | Reject mismatched or consumed evidence |
Facilitator timeout | Query status before issuing a new payment |
Verified payment, service error | Retry delivery or enter refund handling without repaying |
Lost webhook | Reconcile through durable payment identifiers and polling |
A timeout is ambiguous. The caller does not know whether the server failed before or after verification. The purchase endpoint or status method should answer that ambiguity.
Refunds are merchant and payment-method operations. Define eligibility, destination, timing, fees, and evidence before launch. Automatic refunds can handle deterministic failures. Disputed quality may need human review or a separate resolution service.
Proof of delivery should match the product. An API can hash the result and bind it to the purchase. A file service can record object hash and access grant. An MCP tool can store invocation parameters and output reference. Sensitive content should remain access-controlled.
The system should reconcile requirements issued, payments verified, services executed, results delivered, settlements completed, and refunds sent. A payment rail without reconciliation is not production commerce.
GOAT Extends x402 Into an Agent Commerce Stack
x402 is an open protocol and is not exclusive to GOAT Network. Developers can use reference SDKs, facilitators, edge platforms, merchant systems, wallets, and settlement networks in different combinations.
GOAT is relevant when developers need more than route-level middleware. Its public AgentKit and GOAT Flow materials cover payer-side actions, merchant operations, runtime policy, and broader onchain capabilities. GOAT's agent stack also connects x402 payments with ERC-8004-related identity functions and EVM execution in a Bitcoin-oriented infrastructure context.
That wider stack can help a machine discover a service, apply policy, pay, track merchant state, and perform a later onchain action. It does not permit unlimited agent spending. Developers should verify current supported operations, assets, networks, APIs, settlement behavior, and deployment status.
A narrow API can start with x402 middleware, one facilitator, a controlled wallet, and durable purchase state. A larger marketplace may need merchant onboarding, API credentials, webhooks, balances, order tracking, refunds, identity, reputation, and observability. The infrastructure choice follows the commercial workflow.
Deployment should pass four gates. Protocol evidence must bind to the right requirement. Wallet policy must deny unsafe requests. Merchant idempotency must produce one delivery. Reconciliation must explain every payment and exception.
x402 facilitates micropayments because machines can discover and satisfy payment requirements in the same HTTP interaction used to access a resource. Its strongest production use appears when that concise handshake is surrounded by explicit financial policy and merchant delivery controls.
Frequently Asked Questions
How does x402 enable machine-to-machine payments?
It lets a server return a machine-readable HTTP 402 payment requirement and lets a client retry with valid payment evidence after policy authorization.
Is a facilitator required?
No. A facilitator is optional. It can simplify verification and settlement for supported payment methods. A merchant may implement verification directly.
Can an AI agent pay automatically with x402?
Yes, within wallet and application policy. Budgets, allowlists, amount limits, supported assets, and approval thresholds should constrain automation.
Does x402 guarantee service delivery?
No. It coordinates payment for access. Merchant state, idempotent execution, delivery evidence, retries, and refunds remain separate.
Why is x402 suitable for micropayments?
It places price and payment instructions directly in the HTTP request flow, reducing account and checkout overhead for per-request services. Economic viability still depends on total costs.
Is x402 exclusive to GOAT Network?
No. x402 is an open protocol. GOAT provides tooling that integrates x402 with payer, merchant, identity, runtime, and onchain infrastructure.
Keep the Boundary Explicit
x402 automates the payment conversation that begins when a machine requests a priced HTTP resource. It standardizes how the server describes acceptable payment, how the client returns evidence, and how the server communicates the result.
The merchant still owns the commercial outcome. It must identify the purchase, execute once, preserve delivery evidence, recover from timeouts, refund eligible failures, and reconcile settlement. The client still owns authorization through bounded wallet policy. A reliable micropayment system is the combination of these responsibilities, not the 402 response alone.
Before launch, replay one paid request from both sides. The client should reproduce the requirement, policy decision, payment evidence, response, and task budget. The merchant should reproduce the quote, verification result, execution lease, delivery receipt, settlement record, and any webhook. Both records should resolve to the same purchase identifier.
Then disconnect the client after payment verification and before delivery. A second request must retrieve or resume the first purchase. It must not create another charge. This single test exercises the boundary that protocol demos often omit. It proves that HTTP payment automation and merchant commerce remain connected even when the network does not deliver a clean request-response cycle.



