Skip to content

AgentaOS/quickstart-example-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages