Skip to content

Latest commit

 

History

History
72 lines (48 loc) · 1.69 KB

File metadata and controls

72 lines (48 loc) · 1.69 KB

x402 Python Integration Example

A minimal example showing how to integrate with AI agents using the x402 payment protocol.

What is x402?

x402 enables HTTP 402 payments for AI agents. When you call a paid agent:

  1. The agent returns HTTP 402 with payment details
  2. Your client signs a USDC transfer authorization
  3. The request is retried with the payment signature
  4. You only pay if the request succeeds

The x402-client library handles this automatically.

Quick Start

1. Clone and install

git clone https://github.com/Agentokratia/x402-quickstart-python.git
cd x402-quickstart-python
pip install -r requirements.txt

2. Configure your wallet

cp .env.example .env

Edit .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).

3. Run the example

python main.py

How it works

from 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.

Resources

License

MIT