All articles
solanax402paymentsaiagentsusdc

x402 and pay.sh: why pay-per-call beats API keys for agents and builders

API keys are the wrong primitive for an agent economy. x402 replaces the account-creation/billing-portal/key-rotation cycle with a single HTTP round trip. pay.sh is the CLI and gateway that makes this practical — 76 providers, no accounts, USDC on Solana.

Share

The average developer manages dozens of API keys. Each one came with an account registration, an email verification, a billing portal setup, a plan decision, and a key-rotation policy. When an AI agent needs to call a paid API, it inherits all of that friction — except it can't click the signup buttons.

x402 is a payment protocol that eliminates the account layer entirely. pay.sh is the CLI that makes x402 practical: a single binary that sits in front of any HTTP call and handles payment challenges transparently. No accounts. No keys. No subscriptions. Just a wallet, USDC, and a command.

The problem with API keys

API keys are a workaround for a missing primitive: a way to pay for HTTP access without a credit card form. They were never designed for machine-to-machine use. The friction they create is tolerable for a human setting up a project once — it's untenable for an autonomous agent that might need to call a new API mid-task.

  • Account registration. An agent can't fill out a signup form, verify an email, or agree to ToS. Every account-gated API is effectively blocked from autonomous use.
  • Prepaid plans and minimums. Most APIs require a credit card before they let you make a single call. You pay $20/month whether you use it or not.
  • Key management overhead. Keys expire, rotate, leak, and need to be injected into every environment. For a portfolio of 10+ APIs, this becomes a maintenance job.
  • Opaque pricing. You find out what a call costs by reading a pricing page, not from the API response. Agents can't negotiate or compare costs at runtime.

How x402 changes the model

x402 uses the HTTP 402 Payment Required status code — in the spec since 1997, unused until now — to embed payment negotiation directly into the HTTP request/response cycle:

text
1. Client → Server    GET /api/endpoint
2. Server → Client    402 Payment Required
                      X-Payment-Required: {
                        "amount": "0.001",
                        "asset": "USDC",
                        "network": "solana-mainnet",
                        "payTo": "<address>",
                        "nonce": "<server-issued>"
                      }
3. Client pays on Solana, includes tx proof in retry
4. Client → Server    GET /api/endpoint
                      X-Payment: { "txid": "<sig>", "nonce": "..." }
5. Server → Client    200 OK  ←  the actual response

No account. No key. No billing portal. The price is in the response. The payment is on-chain and verifiable. One round trip of overhead.

What pay.sh is

pay.sh is a CLI and gateway that handles the x402 flow for you. Install the binary, fund a wallet, and it wraps any HTTP call:

sh
# Install (macOS / Linux)
brew install anthropics/tap/pay

# Or npm
npx @anthropic-ai/pay setup

# Fund your wallet (PayPal, Venmo, Apple Pay, Solana mobile)
pay topup

# Now use it in front of any x402-aware API
pay curl https://api.venice.ai/api/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model": "llama-3.3-70b", "messages": [{"role": "user", "content": "hello"}]}'

The pay curl wrapper catches a 402response, authorises payment from your local wallet (via OS keychain), and retries — all transparently. The calling code sees a 200 with the response body it wanted.

For agents specifically, pay.sh plugs into Claude Code and OpenAI Codex via MCP, so an agent running inside Claude can make paid API calls without human intervention — spending from a pre-funded wallet with your approval.

The catalog: 76 providers, no accounts required

pay.sh maintains a registry of providers that speak x402. As of June 2026, 76 providers across 13 categories — none requiring an account:

  • AI/ML (34 services). Venice.ai private inference (43 endpoints — LLMs, image gen, audio, video), Perplexity Sonar with citations, Alibaba Cloud vision/speech/ OCR/video (dozens of endpoints), Google Cloud NLP, Vision, Speech-to-Text, Text-to-Speech, Video Intelligence.
  • Finance (5 services). Birdeye DeFi market data (47 endpoints across Solana + 15 chains), Nansen smart money analytics (56 endpoints), StableCrypto via CoinGecko + DefiLlama + Alchemy (105 endpoints), CoinGecko onchain DEX, Clustly (tip any X handle in USDC).
  • Compute (1 service, 137 endpoints). QuickNode pay-per-request RPC for 140+ blockchain networks — Solana, Ethereum, and everything in between.
  • Data (6 services). StableEnrich (Apollo, Exa, Firecrawl, Hunter, Serper and more in one gateway), Wolfram Alpha, RentCast US property data, Social Intel influencer search, BigQuery (255 public datasets).
  • Messaging (4 services). AgentMail (51-endpoint programmatic email for agents), StableEmail, StablePhone (AI outbound calls), Textbelt SMS.
  • Shopping (3 services). Purch — buy products from Amazon and Shopify with USDC. StableMerch — custom printed merchandise from AI-generated images. Crush Rewards retail pricing across major US/Canadian retailers.
  • Media, Maps, Search, Storage, Security, Translation. fal.ai image/video generation, Google Places, Tripadvisor, StableUpload (file hosting + static sites), Google Vision, Alibaba moderation, Google + Alibaba translation.

Every one of these is callable with pay curl — no account, no API key, no plan to choose.

Why Solana specifically

x402 is network-agnostic at the protocol level — the X-Payment-Required header specifies which chain and asset to use. In practice, most of the pay.sh catalog settles in USDC on Solana because:

  • Fees are negligible. A $0.001 API call is economical only if the settlement cost is a fraction of a cent. Solana's base fees (~0.000005 SOL) make micropayment settlement viable at any call volume.
  • Settlement is fast. With Alpenglow consensus approaching and current ~400ms slots, finality is fast enough not to add meaningful latency to an API call.
  • USDC is widely held. Stablecoin balances don't require managing token price risk. An agent can hold $10 of USDC and make thousands of small API calls before needing a top-up.
  • Solana Foundation is in the catalog. The Foundation sponsors access to Alibaba Cloud and Google Cloud APIs directly through the pay.sh registry — dozens of endpoints for AI, translation, vision, speech, and maps, available via the same pay curl interface.

Advantages for builders

For a developer building a tool or agent:

  • Try before you commit. Sandbox mode lets you make calls with ephemeral test wallets at no cost. When you're ready to go live, pay setup generates a real keypair in your OS keychain and you fund it once.
  • One wallet, 76 APIs. You don't manage 76 sets of credentials — you manage one balance. The catalog handles routing to the right provider.
  • Transparent cost signals. Because pricing is in the 402 response, you can log exactly what each call cost — per call, per provider — without scraping a billing dashboard.
  • Drop-in for existing tooling. Wrap your existing curl calls with pay curl, or use pay wget. No SDK change required.

Advantages for agents

For an autonomous agent running inside Claude Code or a custom agent loop:

  • Capable of calling new APIs mid-task. An agent that needs a Perplexity citation, a Nansen wallet profile, or a Google Places lookup can make those calls without a human pre-provisioning credentials. The wallet handles it.
  • Bounded spend. Fund the wallet with a fixed amount. When it's empty, spending stops. No runaway billing events.
  • Auditable. Every payment is an on-chain transaction. You can inspect exactly what the agent spent, when, and on what — with no reliance on a provider's billing records.
  • MCP-native. The pay.sh MCP server exposes the catalog as tools directly in the Claude Code tool loop. An agent can search the catalog, pick a provider, and call it without leaving the session.

Become a provider

If you run an API, x402 lets you monetise it without building a billing portal. Add a 402 response to any endpoint, point it at a Solana address, and payments flow directly to your wallet per call. The pay.sh pay server command deploys a payment gateway in front of an existing API with no code changes on the API side.

sh
# Wrap your API with a payment gateway
pay server --upstream http://localhost:3000 \
           --price 0.001 \
           --asset USDC \
           --network solana-mainnet \
           --pay-to <your-solana-address>

The Solana Foundation and Anza use the same mechanism to sponsor access to cloud provider APIs — they absorb the cost on the upstream side and expose the endpoints free or discounted through the pay.sh catalog.

Getting started

sh
# 1. Install
brew install anthropics/tap/pay
# or: npx @anthropic-ai/pay setup

# 2. Fund (sandbox is free; mainnet needs USDC)
pay topup

# 3. Try a call
pay curl https://api.venice.ai/api/v1/models

# 4. Browse the catalog
pay list

Further reading

Keep reading

x402 and pay.sh: why pay-per-call beats API keys for agents and builders | devrels.xyz