/ai-toolkit:x402-paymentsfrom ai-toolkit
Builds HTTP endpoints and clients using the x402 protocol for per-request stablecoin payments (USDC on Base/Solana). Covers Express, Hono, Next.js middleware, paying AI agents with spending limits, and testnet-to-mainnet migration.
Ships in ai-toolkit. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
x402 puts payment into HTTP itself. A server answers an unpaid request with 402 Payment Required and a description of what it accepts; the client signs a stablecoin payment authorization and retries; the server has a facilitator verify and settle it, then returns the resource. Your job with this skill is to help the user build either side of that exchange so it works, and so that nobody loses money or keys along the way.
This code moves real money once it points at mainnet, and a leaked private key empties a wallet. Keep these defaults unless the user deliberately chooses otherwise:
eip155:84532) or Solana Devnet with the free https://x402.org/facilitator. Before writing a mainnet network ID, CDP credentials, or running a client that pays a mainnet resource, tell the user what will change and get a yes..env file that is gitignored and chmod 600. Refer to them as ${EVM_PRIVATE_KEY} and never echo, log, or print one. If you generate a throwaway testnet key, write it straight into .env and show only the address (the user needs it for the faucet).setSpendControls) and, for loops, in total; see references/client-patterns.md. A paying agent loop also needs an iteration limit.402 with a PAYMENT-REQUIRED header: base64 JSON listing what it accepts (scheme, network, asset, amount in atomic units, payTo).PAYMENT-SIGNATURE header.200 with a PAYMENT-RESPONSE header: base64 JSON with success, transaction, network, and payer.Facilitators verify and settle without holding funds. Schemes: exact (fixed price), upto (metered, settles up to a cap), batch-settlement, and auth-capture. EVM payments use EIP-3009 where the token supports it, with Permit2 as a fallback for other ERC-20s. Network IDs are CAIP-2 strings. Details: references/protocol-spec.md.
npm install @x402/express @x402/core @x402/evm express dotenv
import "dotenv/config";
import express from "express";
import { paymentMiddleware, x402ResourceServer } from "@x402/express";
import { HTTPFacilitatorClient } from "@x402/core/server";
import { ExactEvmScheme } from "@x402/evm/exact/server";
const payTo = process.env.PAY_TO;
if (!payTo) throw new Error("Set PAY_TO in .env to the wallet address that receives payments");
const facilitator = new HTTPFacilitatorClient({ url: "https://x402.org/facilitator" });
const server = new x402ResourceServer(facilitator).register("eip155:84532", new ExactEvmScheme());
const app = express();
app.use(
paymentMiddleware(
{
"GET /weather": {
accepts: [{ scheme: "exact", price: "$0.001", network: "eip155:84532", payTo }],
description: "Current weather",
mimeType: "application/json",
},
},
server,
),
);
app.get("/weather", (_req, res) => res.json({ weather: "sunny", temperature: 70 }));
app.listen(4021, () => console.log("Listening on http://localhost:4021"));
Routes not listed in the config stay free. Prices are dollar strings; the SDK converts them to atomic units (USDC has 6 decimals). Buyers on the default client settings refuse payments above $1, and payments in assets outside the SDK's default list (mainly USD stablecoins), so price above that only if your buyers raise their limits.
npm install @x402/fetch @x402/evm viem dotenv
import "dotenv/config";
import { x402Client, wrapFetchWithPayment, x402HTTPClient } from "@x402/fetch";
import { ExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
const key = process.env.EVM_PRIVATE_KEY as `0x${string}` | undefined;
if (!key) throw new Error("Set EVM_PRIVATE_KEY in .env (a funded testnet key)");
const client = new x402Client()
.register("eip155:*", new ExactEvmScheme(privateKeyToAccount(key)))
.setSpendControls({ maxAmountPerPayment: "$0.01" });
const fetchWithPayment = wrapFetchWithPayment(fetch, client);
const response = await fetchWithPayment("http://localhost:4021/weather");
const result = await new x402HTTPClient(client).processResponse(response);
console.log(result.paymentStatus, result.body); // "settled" | "settle_failed" | "payment_required" | "none"
Register schemes on the client before wrapping fetch or axios. Both snippets use top-level await and ES modules, so the project needs "type": "module" and a runner such as tsx.
| Need | Use | Packages |
|---|---|---|
| Express / Hono server | paymentMiddleware + x402ResourceServer | @x402/express or @x402/hono, @x402/evm |
| Next.js | paymentProxy in proxy.ts (Next.js 16), or withX402 around one route handler | @x402/next, @x402/core, @x402/evm |
| fetch / axios client | wrapFetchWithPayment / wrapAxiosWithPayment | @x402/fetch or @x402/axios, @x402/evm, viem |
| Solana | ExactSvmScheme (server or client) | @x402/svm, @solana/kit, @scure/base |
| Paid MCP tools, or an MCP client that pays | createPaymentWrapper / createx402MCPClient | @x402/mcp |
| Mainnet settlement | createCdpFacilitatorClient() | @coinbase/cdp-sdk |
| Python or Go | Both SDKs support V2 | PyPI x402, Go module github.com/x402-foundation/x402/go/v2 |
| Task | Read |
|---|---|
| Headers, payload types, schemes, networks and token addresses, facilitator API | references/protocol-spec.md |
| Middleware for each framework, multi-route config, custom verify/settle, discovery listing | references/server-patterns.md |
| Clients, Solana signers, spend controls and hooks, reading the result, errors | references/client-patterns.md |
| AI agents and MCP tools that pay or charge | references/agentic-patterns.md |
| Testnet to mainnet, CDP credentials, faucets, key handling, security checklist | references/deployment.md |
These notes match x402 2.28.0 (October 2026). The SDK changes quickly. Before relying on a method name, check the version the project has installed (npm ls @x402/core) and compare with the official examples in examples/typescript/ of https://github.com/x402-foundation/x402 (the repo moved there from coinbase/x402). The protocol docs are at https://docs.x402.org and the CDP facilitator docs at https://docs.cdp.coinbase.com/x402/welcome. If what's installed disagrees with these notes, trust the installed package and the official example.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
x402, http-402, stablecoin-payments, paywalled-apis, agent-payments
6 skills in this plugin
/cpp-reinforcement-learningReinforcement learning in C++ with LibTorch (the PyTorch C++ frontend) and C++20. Use when the user is implementing DQN, PPO or SAC in C++, building a replay buffer or rollout buffer in C++, fixing libtorch memory growth or GPU issues in a C++ agent, running environments in parallel threads, or loading a policy trained in Python into a C++ program (games, robotics, simulators). Not for Python RL with Gymnasium or Stable-Baselines3, including exporting a Python policy to ONNX (use reinforcement-learning), or for general deep learning (use deep-learning)./deep-learningBuild and train neural networks with Keras 3 on any backend (JAX, TensorFlow or PyTorch). Use when the user is writing Keras code or asks for a Keras model, wants to migrate tf.keras / Keras 2 code to Keras 3, or is working on image classification, segmentation, text classification, sequence-to-sequence, time-series forecasting, or generative models (VAE, GAN) in Keras, including custom training loops, callbacks, transfer learning, mixed precision and multi-GPU training. Not for plain PyTorch or JAX training loops without Keras, Hugging Face / LLM fine-tuning, or reinforcement learning (use reinforcement-learning).npx claudepluginhub aznatkoiny/zai-skills --plugin ai-toolkitOther plugins' skills for the same job