Delx

x402 vs Stripe for Agent APIs: When to Use Each

If you are building an API that AI agents will consume, you face a billing decision that did not exist two years ago: should you use x402 (on-chain per-call payments) or Stripe (traditional subscription/usage billing)? The answer depends on who your consumers are, how frequently they call your API, and whether autonomous agents need to pay without human intervention.

This article provides a detailed comparison — feature by feature, cost by cost — and explains when to use each approach, including the increasingly popular hybrid model. If you are not yet familiar with x402, read What Is x402? first.

The Comparison Table

Here is a side-by-side comparison of x402 and Stripe across the dimensions that matter most for agent APIs:

Dimensionx402Stripe
Account requiredNo — just a funded walletYes — email, card, customer object
API keys neededNo — payment receipt is the credentialYes — must provision and rotate
Per-call cost< $0.001 gas fee2.9% + $0.30 per charge
Min viable payment$0.01 (gas is negligible)~$1.00 (fees eat small amounts)
Settlement speed< 2 seconds (Base L2)2-7 business days
Agent autonomyFull — no human neededLimited — human must set up account
Billing modelPer-call, pay-as-you-goSubscription, usage-based, or per-charge
ChargebacksImpossible — on-chain is finalPossible — dispute process
CurrencyUSDC (stablecoin, $1 peg)Fiat (USD, EUR, etc.)
ComplianceEmerging — varies by jurisdictionMature — PCI, SOC 2, global coverage
InvoicingOn-chain receipts (not traditional)Full invoicing, tax, receipts
Integration effortParse 402 headers, verify on-chain txStripe SDK, webhooks, customer portal

Per-Call Cost Analysis

The cost difference is dramatic at small payment amounts. Let us compare the effective cost for different API call prices:

API Call Pricex402 Total Costx402 Fee %Stripe Total CostStripe Fee %
$0.01$0.01090.9%$0.31033003%
$0.05$0.05090.18%$0.3515603%
$0.10$0.10090.09%$0.4029303%
$1.00$1.00090.01%$1.32933%
$10.00$10.0009<0.01%$10.595.9%

The takeaway: for API calls priced below $1.00, Stripe's $0.30 fixed fee makes per-call billing impractical. x402's sub-cent gas fees make payments as low as $0.01 viable. At higher price points ($10+), Stripe becomes competitive because the fixed fee is a small percentage.

Latency Comparison

Payment latency matters for agent workflows. An agent waiting for payment confirmation is an agent not doing useful work. Here is how the two approaches compare:

Phasex402Stripe
Initial request~50ms (returns 402)~50ms (returns 401 if no API key)
Payment processing~1-2s (Base L2 confirmation)~2-5s (Stripe API + card network)
Retry with proof~100ms (verify on-chain)N/A (API key already stored)
Total first-call~1.5-2.5sMinutes to hours (account setup)

For x402, the first call takes 1-2 seconds extra (the 402 + pay + retry loop). Subsequent calls within the same session can be pre-authorized, reducing latency to near-zero. For Stripe, the first call requires account creation — a human-driven process that can take minutes to hours — but subsequent calls are fast because the API key is cached.

Agent Compatibility

The core question is: can your consumer pay without a human?

x402: Built for Autonomous Agents

x402 was designed from the ground up for autonomous agents. The payment flow is entirely programmatic: detect 402, read headers, send USDC, retry with receipt. No human ever needs to touch a form, approve a charge, or enter credentials. An agent with a funded wallet can access any x402 service immediately.

Stripe: Built for Human Developers

Stripe excels at human-facing billing: checkout pages, subscription management, invoices, tax compliance, dispute resolution. But agents cannot navigate these flows. An agent cannot:

Stripe's API-based billing (Stripe Billing) works for usage-based models, but it still requires a human to create the customer account and store a payment method upfront.

Use Cases: When to Choose Which

Neither x402 nor Stripe is universally better. The right choice depends on your use case:

Choose x402 When:

Choose Stripe When:

The Hybrid Approach

Many APIs — including Delx — use both. The hybrid model serves both audiences without compromise:

                    ┌─────────────────────┐
                    │   Your API Server   │
                    └──────────┬──────────┘
                               │
              ┌────────────────┼────────────────┐
              │                │                │
    ┌─────────▼──────┐   ┌────▼────┐   ┌───────▼────────┐
    │  Has API Key?  │   │  Has    │   │  No auth       │
    │  (Stripe user) │   │  x402   │   │  provided      │
    │                │   │  receipt│   │                │
    └───────┬────────┘   └────┬────┘   └───────┬────────┘
            │                 │                │
       ┌────▼────┐       ┌───▼────┐       ┌───▼────┐
       │ Serve   │       │ Verify │       │ Return │
       │ response│       │ on-    │       │  402   │
       │ + bill  │       │ chain  │       │ Payment│
       │ to      │       │ then   │       │ Required│
       │ Stripe  │       │ serve  │       │        │
       └─────────┘       └────────┘       └────────┘

Here is how the hybrid auth middleware works in practice:

# Python — hybrid auth middleware
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.responses import JSONResponse

class HybridAuthMiddleware(BaseHTTPMiddleware):
    async def dispatch(self, request, call_next):
        # Path 1: Stripe API key
        api_key = request.headers.get("Authorization", "").replace("Bearer ", "")
        if api_key and await self.verify_stripe_key(api_key):
            # Record usage for Stripe billing
            await self.record_stripe_usage(api_key)
            return await call_next(request)

        # Path 2: x402 payment receipt
        receipt = request.headers.get("X-Payment-Receipt")
        if receipt and await self.verify_x402_receipt(receipt):
            return await call_next(request)

        # Path 3: No auth — return 402
        return JSONResponse(
            status_code=402,
            content={
                "error": "Payment required",
                "amount": "0.01",
                "currency": "USDC",
            },
            headers={
                "X-Payment-Amount": "10000",     # 0.01 USDC
                "X-Payment-Token": "USDC",
                "X-Payment-Chain": "base",
                "X-Payment-Address": "0xabc...def",
                "X-Payment-Schema": "x402-v1",
            },
        )

    async def verify_stripe_key(self, key: str) -> bool:
        """Check if the API key is valid in Stripe."""
        # Look up the key in your database
        ...

    async def verify_x402_receipt(self, tx_hash: str) -> bool:
        """Verify the USDC transfer on Base."""
        # Read the on-chain transaction
        # Confirm amount, recipient, and that it hasn't been used before
        ...

    async def record_stripe_usage(self, key: str):
        """Record usage for metered billing in Stripe."""
        # stripe.SubscriptionItem.create_usage_record(...)
        ...

Code Comparison: Client Side

Here is what the client code looks like for each approach:

x402 Client (Agent)

# Python — x402 client
import httpx

async def call_api(url: str, payload: dict) -> dict:
    async with httpx.AsyncClient() as client:
        resp = await client.post(url, json=payload)

        if resp.status_code == 402:
            # Pay on-chain (see what-is-x402 for full implementation)
            tx_hash = await pay_usdc(
                to=resp.headers["X-Payment-Address"],
                amount=int(resp.headers["X-Payment-Amount"]),
            )
            # Retry with receipt
            resp = await client.post(
                url,
                json=payload,
                headers={"X-Payment-Receipt": tx_hash},
            )

        return resp.json()

# Usage — no account, no API key
result = await call_api(
    "https://api.delx.ai/api/v1/tools/checkin",
    {"agent_id": "agent-01", "mood": "working"},
)

Stripe Client (Human Developer)

# Python — Stripe-authenticated client
import httpx

# Prerequisites:
# 1. Sign up at delx.ai/signup (email + credit card)
# 2. Create API key in the dashboard
# 3. Store key securely

API_KEY = "sk_live_..."  # From dashboard

async def call_api(url: str, payload: dict) -> dict:
    async with httpx.AsyncClient() as client:
        resp = await client.post(
            url,
            json=payload,
            headers={"Authorization": f"Bearer {API_KEY}"},
        )
        return resp.json()

# Usage — requires account + API key
result = await call_api(
    "https://api.delx.ai/api/v1/tools/checkin",
    {"agent_id": "agent-01", "mood": "working"},
)

Notice the difference: the x402 client has zero setup — no account, no key. The Stripe client requires a human to sign up, create an API key, and store it securely. For autonomous agents, the x402 path is the only viable one.

Agent-to-Agent Commerce

One area where x402 has no Stripe equivalent is agent-to-agent commerce. When Agent A needs to call Agent B's API, neither agent can create a Stripe account for the other. But both agents can have wallets, and x402 lets them transact directly.

This creates a composable agent economy where services can be chained without any central billing platform. Agent A calls Agent B, which calls Agent C — each paying the next via x402. The entire chain settles on-chain in seconds.

For more on this pattern, see Agent-to-Agent Payments.

Decision Framework

Use this flowchart to decide which approach fits your API:

Q: Are your consumers primarily AI agents?
├── YES → Use x402 (+ optional Stripe for human fallback)
└── NO
    Q: Are your consumers human developers?
    ├── YES
    │   Q: Is your per-call price < $1.00?
    │   ├── YES → Use x402 (Stripe fees too high)
    │   └── NO → Use Stripe (or hybrid)
    └── BOTH
        → Use hybrid (x402 for agents, Stripe for humans)

Most APIs serving the AI agent ecosystem will end up with the hybrid approach. It is not significantly more engineering effort — you add one middleware that checks for either an API key or an x402 receipt — and it serves both audiences optimally.

For pricing details on Delx's hybrid model, see Pricing.

Frequently Asked Questions

Should I use x402 or Stripe for my agent API?

Use x402 when your consumers are autonomous AI agents that need per-call payments without accounts. Use Stripe when your consumers are human developers or organizations that prefer traditional billing with invoices and credit cards. Many APIs use both — x402 for agents, Stripe for human teams.

What is the per-call cost difference between x402 and Stripe?

x402 on Base costs less than $0.001 in gas per call, making payments as low as $0.01 viable. Stripe charges 2.9% + $0.30 per transaction, which means the minimum practical charge is around $1.00 to keep fees reasonable. For high-frequency, low-value agent calls, x402 is significantly cheaper.

Can an AI agent use Stripe to pay for API calls?

Not easily. Stripe requires account creation, credit card entry, and often 3D Secure verification — all designed for humans. An agent cannot fill out a checkout form. While Stripe offers API-based billing, it still requires a pre-created customer account with stored payment methods.

What is the hybrid approach?

The hybrid approach offers both payment methods on the same API. Human teams sign up via Stripe and get API keys with monthly billing. AI agents use x402 for per-call payments with no account required. The API server checks for either an API key or an x402 receipt on each request.

Is x402 secure?

Yes. x402 uses on-chain settlement — payments are verified by reading the blockchain, not by trusting the client. Transaction receipts are unique and cannot be replayed. There are no stored credentials to leak. The security model is arguably stronger than API keys because there is nothing to steal.

Add x402 to Your Agent API

Enable per-call payments for AI agents in under 30 minutes. Start with x402 alone or go hybrid with Stripe from day one.