@dexterai/x402 v1.7.0
Stripe
Machine Payments
Add AI agent payments to your API in 3 lines of code. Payments land in your Stripe Dashboard. No crypto knowledge required.
Agent RequestGET /api/data
+Stripe PIDeposit Address
+USDC on Base$0.01 payment
+DashboardSettled in USD
The Difference
Stripe's Docs~45 lines · 6 imports
import Stripe from "stripe";
import { paymentMiddleware } from "@x402/hono";
import { x402ResourceServer,
HTTPFacilitatorClient } from "@x402/core/server";
import { ExactEvmScheme }
from "@x402/evm/exact/server";
import { Hono } from "hono";
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
const facilitator = new HTTPFacilitatorClient({
url: process.env.FACILITATOR_URL
});
// 40+ lines for createPayToAddress...
async function createPayToAddress(ctx) {
if (ctx.paymentHeader) {
const decoded = JSON.parse(
Buffer.from(ctx.paymentHeader, "base64")
.toString()
);
return decoded.payload.authorization.to;
}
const pi = await stripe.paymentIntents.create({
amount, currency: "usd",
payment_method_types: ["crypto"],
payment_method_data: { type: "crypto" },
payment_method_options: {
crypto: { mode: "custom" }
}, confirm: true
});
return pi.next_action
.crypto_collect_deposit_details
.deposit_addresses["base"].address;
}
// Configure middleware + scheme registration...
app.use(paymentMiddleware({
"GET /paid": { accepts: [{ scheme: "exact",
price: "$0.01", network: "eip155:84532",
payTo: createPayToAddress }] }
}, new x402ResourceServer(facilitator)
.register("eip155:84532",
new ExactEvmScheme())));With @dexterai/x4023 lines · 1 import
import { x402Middleware, stripePayTo }
from '@dexterai/x402/server';
app.use('/api/data', x402Middleware({
amount: '0.01',
payTo: stripePayTo(process.env.STRIPE_SECRET_KEY),
}));
// That's it. Payments land in your Stripe Dashboard.
// Network auto-set to Base. Facilitator auto-configured.
// Sales tax, refunds, and reporting just work.How It Works
Payment Flow Simulation
1
Agent sends request
GET /api/data → Server
2
Server returns 402 Payment Required
x402Middleware creates Stripe PaymentIntent
3
Agent signs USDC transfer on Base
TransferWithAuthorization → deposit address
4
Facilitator verifies and settles on-chain
x402.dexter.cash → Base network
5
Stripe auto-captures the PaymentIntent
USDC arrives → Stripe captures → USD in balance
6
Content returned to agent
HTTP 200 OK with paid content
Integration Examples
import express from 'express';
import { x402Middleware, stripePayTo } from '@dexterai/x402/server';
const app = express();
// Protect any endpoint with Stripe machine payments
app.get('/api/data',
x402Middleware({
amount: '0.01', // $0.01 per request
payTo: stripePayTo(process.env.STRIPE_SECRET_KEY),
}),
(req, res) => {
// Only runs after successful payment
res.json({ data: 'premium content', payer: req.x402?.payer });
}
);
app.listen(3000);What This Replaces
Monetizing APIs Today
- ✗Issue API keys, manage accounts
- ✗Monthly subscriptions ($29-199/mo)
- ✗Rate limiting, usage tracking, billing
- ✗Agents can't use credit cards
- ✗No microtransaction support
- ✗Complex Stripe integration (100+ lines)
APIs + Stripe + x402
- ✓No accounts, no API keys needed
- ✓Pay per request — as low as $0.01
- ✓Usage tracking built into the protocol
- ✓Agents pay with USDC from any wallet
- ✓Microtransactions down to $0.01
- ✓3 lines of code with @dexterai/x402
$npm install @dexterai/x402 stripe