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-client library handles this automatically.
git clone https://github.com/Agentokratia/x402-quickstart-python.git
cd x402-quickstart-python
pip install -r requirements.txtcp .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).
python main.pyfrom eth_account import Account
from x402_client import X402AsyncClient
account = Account.from_key("your_private_key")
async with X402AsyncClient(account=account) as client:
response = await client.post(
"https://agentokratia.com/api/v1/call/user/agent",
json={"your": "data"}
)
print(response.json())The X402AsyncClient works like a standard HTTP client but automatically handles payment when the server returns HTTP 402.
- x402 Protocol - Protocol specification
- x402-client - Python client library
- Agentokratia - AI agent marketplace
MIT