What is x402? How AI Agents Pay for APIs Without API Keys
x402 revives the long-ignored HTTP 402 status code to enable machine-native payments. An x402-enabled API returns a payment challenge; a compatible agent pays with USDC on Base and retries — zero signup, zero API keys, zero billing portals.
x402 is the HTTP payment protocol that lets AI agents pay for API calls automatically with USDC on Base. Instead of API keys and billing portals, an x402 API returns HTTP 402 with a price, the agent pays on-chain, and retries the request. Settlement takes ~2 seconds and costs under $0.01 in gas fees. Social Intel is the first Instagram data API to support x402.
Table of Contents
The API Key Problem
Every developer has fought with API keys. You find a service you want to use, spend 20 minutes creating an account, verify your email, add a credit card, navigate to "API Keys", generate a key, copy it somewhere safe, set an environment variable, and — finally — make your first request.
For human developers, this friction is annoying but manageable. For AI agents, it's a hard wall.
An autonomous AI agent running in a reasoning loop can't sign up for accounts, solve CAPTCHAs, or verify an email address. It can make HTTP requests. If an API requires a pre-registered key, the agent is blocked — it must hand off to a human to complete the setup before it can do its job.
x402 solves this. An x402-enabled API doesn't ask who you are. It asks can you pay?
What is x402?
x402 is an HTTP extension that uses the 402 Payment Required status code —
a code that has existed in the HTTP spec since 1991 but was reserved as "for future use"
for over three decades.
The core idea is simple:
- You make a request to an API.
- The API responds with
402 Payment Requiredand a payment header specifying the price, payment network, and payee address. - Your client pays on-chain (USDC on Base) and includes a payment proof in the retry request.
- The API verifies the payment and returns the actual response.
No accounts. No API keys. No billing portals. The payment is the credential.
The x402 open standard uses USDC on the Base network (Coinbase's L2), which settles in ~2 seconds with fees under $0.01.
How the Payment Flow Works
Initial Request
Agent sends a standard HTTP GET/POST to the API endpoint.
402 Payment Challenge
API responds with HTTP 402 and an X-Payment-Required header containing the price (e.g., 0.10 USDC), payee wallet address, and network (base).
On-Chain Payment
Agent's x402 client sends a USDC transfer on Base. The transaction hash becomes the payment proof.
Retry with Payment Proof
Agent retries the original request, including the signed payment receipt in the X-Payment header.
Verified Response
API verifies the on-chain payment and returns the actual data. Done.
The entire flow typically takes 3-5 seconds end-to-end, dominated by Base L2 confirmation time (~2s). The agent doesn't need to manage accounts, rotate keys, or handle expiring tokens.
x402 vs Traditional API Billing
- Must create account before first call
- Email verification required
- Credit card required upfront
- Keys expire, must be rotated
- Monthly billing, not per-request
- Blocked by rate limits and quotas
- No native agent support
- First call works immediately
- No account, no email
- Fund a wallet, start calling
- Payments are permanent on-chain
- True pay-per-request pricing
- Agent-native: no human required
- Wallet = identity
Using x402 in Python
The easiest way to use an x402 API in Python is with the httpx-x402 client,
which handles the 402 challenge-response automatically.
pip install httpx-x402 cdp-sdk
from httpx_x402 import X402Client from cdp import Wallet # Load your CDP wallet (Base network) wallet = Wallet.fetch("your-wallet-id") # x402 client handles 402 challenge-response automatically client = X402Client(wallet=wallet) response = client.get( "https://socialintel.dev/v1/search_leads", params={"niche": "fitness", "min_followers": 10000} ) leads = response.json() print(leads[0]) # { "username": ..., "followers": ..., "bio": ... }
The X402Client wraps a standard httpx.Client. When it receives a
402, it automatically signs and submits the USDC payment, then retries. No boilerplate.
Fund your wallet with a small amount of USDC on Base before your first call. $5 of USDC gets you ~50 Social Intel requests, with change left over for gas.
Manual implementation (raw httpx)
If you prefer to handle the x402 flow yourself:
import httpx, json API_URL = "https://socialintel.dev/v1/search_leads" PARAMS = {"niche": "fitness", "min_followers": 10000} # Step 1: Initial request r = httpx.get(API_URL, params=PARAMS) if r.status_code == 402: challenge = json.loads(r.headers["X-Payment-Required"]) # challenge = { "amount": "0.1", "token": "USDC", "network": "base", "payee": "0x..." } # Step 2: Pay on Base tx_hash = send_usdc(challenge["payee"], challenge["amount"]) # Step 3: Retry with proof r = httpx.get(API_URL, params=PARAMS, headers={"X-Payment": tx_hash}) data = r.json()
Why AI Agents Need x402
The AI agent ecosystem is growing rapidly. Claude, GPT-4o, and open-source models are being deployed as autonomous agents — writing code, browsing the web, and calling external APIs to complete tasks. These agents need data. And they hit the same wall: API keys.
Consider a typical agentic workflow:
- User asks agent: "Find 20 fitness influencers in Germany with over 50K followers"
- Agent decides it needs Instagram data
- Agent finds an Instagram search API
- Agent is blocked — the API requires account signup and key generation
- Agent must ask the human to create an account and provide a key
- Human interrupts their workflow, creates an account, pastes the key
- Agent completes the task — 20 minutes later than it could have
With x402, steps 4-6 don't exist. The agent has a funded wallet. It pays. It gets the data. The task completes without human intervention.
x402 is one piece of a broader shift toward agent-native infrastructure. MCP (Model Context Protocol) handles tool calling. x402 handles payments. Together they form the protocol stack that lets AI agents operate independently.
x402 and MCP: Better Together
MCP (Model Context Protocol) standardizes how AI assistants like Claude call external tools. An MCP server exposes API endpoints as tool definitions — Claude can discover and call them in its reasoning loop without any configuration beyond the server URL.
Social Intel runs an MCP server at https://socialintel.dev/mcp. When you add
it to Claude Desktop or Cursor, Claude can call Instagram search as a native tool. And because
the API is x402-enabled, Claude's agent wallet pays per call automatically — no key to provide,
no billing to manage.
Social Intel: First Instagram API with x402
Social Intel is the first Instagram data API to support both MCP and x402. You can:
- Call via REST — standard HTTPS, pays per request with x402
- Call via MCP — add to Claude Desktop or Cursor, no config beyond the server URL
- No account required — fund a Base wallet with USDC and start calling
Pricing is $0.10 per request. A search returns up to 12 profiles per call — usernames, follower counts, bios, contact info where available.
The interactive demo at socialintel.dev/#demo lets you run a search and see real results before touching your wallet.
Frequently Asked Questions
Is x402 an official HTTP standard?
HTTP 402 is a reserved status code in the official HTTP spec (RFC 7231). The x402 protocol is an open standard built on top of it, specifying the payment header format, supported networks, and verification flow. It is not yet an IETF RFC, but it is gaining traction in the API developer community.
What blockchain does x402 use?
The reference implementation uses USDC on Base — Coinbase's Ethereum L2. Base was chosen for its fast finality (~2 seconds), low transaction fees (under $0.01), and native USDC support. Other networks are possible but less common in practice.
How does the API verify payment without a centralized backend?
x402 uses a facilitator service that watches the Base blockchain for USDC
transfers to the payee address. When the client includes a transaction hash in the
X-Payment header, the API calls the facilitator to verify the transaction
exists, is confirmed, and matches the expected amount. The on-chain record is permanent.
What if I want to use a traditional API key instead?
Social Intel is x402-only for REST calls. If you add the MCP server to Claude or Cursor and let the assistant handle payments through its agent wallet, you never interact with payment details directly — from your perspective it behaves like any other Claude tool.
How is x402 different from Stripe or Paddle?
Stripe and Paddle are for humans — they require credit cards, billing addresses, and monthly invoices. x402 is for machines. There's no PCI compliance surface, no subscription management, and no chargebacks. The payment is a cryptographic proof on a public ledger, and it clears in seconds. For AI agent use cases, this is strictly better.
Related Articles
- Instagram Data APIs in 2026: Pricing & Features Compared — compare Social Intel, Apify, Bright Data, and every major provider
- Using Instagram Data in Claude and Cursor via MCP — step-by-step setup guide for the MCP server
Try Social Intel
The only Instagram data API with x402 + MCP support. No account required — add to Claude or call the REST endpoint directly.