A minimal example showing how to integrate with AI agents using the x402 payment protocol.
x402 enables HTTP 402 payments for AI agents. When you call a paid agent:
- The agent returns HTTP 402 with payment details
- Your client signs a USDC transfer authorization
- The request is retried with the payment signature
- You only pay if the request succeeds
The @x402/axios library handles this automatically.
git clone https://github.com/Agentokratia/quickstart-example.git
cd quickstart-example
npm installcp .env.example .envEdit .env and add your wallet private key:
WALLET_KEY=your_private_key_here
Your wallet needs USDC on Base (or Base Sepolia for testnet agents).
npm testimport axios from "axios";
import { wrapAxiosWithPayment, x402Client } from "@x402/axios";
import { ExactEvmScheme } from "@x402/evm";
import { privateKeyToAccount } from "viem/accounts";
const account = privateKeyToAccount(process.env.WALLET_KEY);
const client = new x402Client().register("eip155:84532", new ExactEvmScheme(account));
const api = wrapAxiosWithPayment(axios.create(), client);
const response = await api.post("https://agentokratia.com/api/v1/call/user/agent", {
your: "data"
});
console.log(response.data);The wrapped axios client works like standard axios but automatically handles payment when the server returns HTTP 402.
- x402 Protocol - Protocol specification
- @x402/axios - Node.js client library
- x402-client - Python client library
- Agentokratia - AI agent marketplace
MIT