⚡ Protocol

x402: The HTTP Protocol That Lets AI Agents Pay for APIs Autonomously

July 2026 · 5 min read · run.pay engineering

When an AI agent needs to call a paid API service, something has to go wrong. Either a human has to set up an account and API key in advance (breaking autonomy), or the agent has no way to pay at all. The x402 protocol solves this at the HTTP level.

What is x402?

x402 is an emerging HTTP payment standard based on the 402 Payment Required status code that's been in the HTTP spec since 1991 but never officially used. The x402 draft (currently being discussed at IETF) proposes a standard way for servers to request payment inline within an HTTP request/response cycle.

The flow is elegantly simple:

1. Client requests a resource GET /api/service HTTP/1.1 2. Server responds with 402 + payment details HTTP/1.1 402 Payment Required X-Payment-Required: {"amount": "0.01", "currency": "USD", ...} 3. Client pays and retries POST /api/service HTTP/1.1 X-Payment: <payment_proof> 4. Server verifies and responds HTTP/1.1 200 OK X-Payment-Receipt: {"txId": "tx_...", "amount": "0.01"}
Key insight:

The payment happens inside the HTTP request — no redirect, no OAuth, no account creation. The agent stays in control the entire time.

Why x402 matters for AI agents

Existing API payment models were designed for humans. A developer signs up, enters billing, gets an API key, and manages it. This works when a human is in the loop — but AI agents operating autonomously can't do any of that.

x402 changes the fundamental model: instead of requiring pre-authorization, the server says "this costs $0.01" and the agent pays inline. No pre-signup, no API key management, no human intervention.

How run.pay implements x402 with Stripe

Most x402 implementations use cryptocurrency (XRPL, Solana, Base) for the payment layer. run.pay takes a different approach: we implement the x402 protocol with Stripe as the payment engine. No crypto required.

When an agent calls any service on run.pay without a payment header, they get:

HTTP/1.1 402 Payment Required X-Payment-Required: { "version": "1", "scheme": "runpay-stripe", "network": "stripe", "maxAmountRequired": "0.01", "currency": "USD", "paymentMethods": ["stripe-wallet"], "agentWalletEndpoint": "https://getrunpay.com/signup" }

The agent then adds their wallet ID to the next request:

POST /x402/hallucination-detector HTTP/1.1 X-Payment: agt_your_agent_id Content-Type: application/json {"response": "text to check for hallucinations"}

run.pay verifies the wallet, deducts from Stripe, calls the service, and returns the result with a payment receipt header. The entire cycle takes under 500ms.

Using x402 with any framework

cURL

curl -X POST https://runpay-backend-visibility-production.up.railway.app/x402/hallucination-detector \ -H "X-Payment: agt_your_agent_id" \ -H "Content-Type: application/json" \ -d '{"response": "your text here"}'

Python

import httpx response = httpx.post( "https://runpay-backend-visibility-production.up.railway.app/x402/hallucination-detector", headers={"X-Payment": "agt_your_agent_id"}, json={"response": "your text here"} ) if response.status_code == 402: payment_details = response.headers.get("X-Payment-Required") # Fund your wallet at https://getrunpay.com/signup result = response.json()

What this means for the ecosystem

As x402 gains adoption across AI frameworks, any agent with a run.pay wallet will automatically be able to access hundreds of services without integration work. The wallet becomes a universal payment primitive for the agent economy.

LangChain, CrewAI, and AutoGen are all moving toward native x402 support. When they do, every service on run.pay will be automatically accessible to millions of developers.

Try x402 on run.pay today

First 3 calls free. No crypto. Stripe-native. x402-compatible.

Create agent wallet →