Drop-in OpenAI Python client with transparent x402 payment support.
x402-openai-python is an established Python project in the AI payments / x402 ecosystem, focused on agent, ethereum, llm, openai. It currently has 260 GitHub stars and 28 forks, and sits alongside related tools like x402-openai-typescript, x402-deploy, claw-empire, x402-pay, AIephant-AI-Agent-Gateway, tdm-integration-kit.
A drop-in OpenAI Python client with transparent x402 payment support: you swap the import, and calls that hit a 402 "Payment Required" response are paid automatically from the agent’s wallet before the request completes. The transparency is the whole point — existing OpenAI-shaped code keeps working while gaining the ability to pay for metered endpoints.
This is exactly the integration pattern that makes x402 practical for AI builders: instead of rewriting your inference layer around a payment SDK, you keep the client you already use and let the payment ride inside the request. It supports Ethereum and Solana settlement per its topics.
Best for: Python teams that already call OpenAI-compatible APIs and want to add pay-per-request access with minimal code change. A x402 client in the Python SDK category.
Wrap the standard openai.OpenAI client with a crypto wallet.
When the server responds with HTTP 402, the library automatically signs and retries the request — zero code changes needed.
pip install x402-openai[evm] # Ethereum / Base / …
pip install x402-openai[svm] # Solana
pip install x402-openai[all] # all chains
from x402_openai import X402OpenAI
from x402_openai.wallets import EvmWallet
client = X402OpenAI(wallet=EvmWallet(private_key="0x…"))
res = client.chat.completions.create(
model="openai/gpt-4o-mini",
messages=[{"role": "user", "content": "Hello!"}],
)
print(res.choices[0].message.content)
Swap EvmWallet for SvmWallet to pay on Solana — the API is identical.
from x402_openai import AsyncX402OpenAI
client = AsyncX402OpenAI(wallet=EvmWallet(private_key="0x…"))
stream = await client.chat.completions.create(
model="openai/gpt-4o-mini",
messages=[{"role": "user", "content": "Explain x402"}],
stream=True,
)
async for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
from x402_openai.wallets import EvmWallet, SvmWallet
client = X402OpenAI(wallets=[
EvmWallet(private_key="0x…"),
SvmWallet(private_key="base58…"),
])
wallet = EvmWallet(mnemonic="word1 word2 … word12")
wallet = EvmWallet(mnemonic="…", account_index=2) # m/44'/60'/0'/0/2
wallet = EvmWallet(mnemonic="…", derivation_path="m/44'/60'/2'/0/0") # custom path
The protocol selects the right chain automatically based on the server's payment requirements.
Use policies to control which chain or scheme is preferred when multiple payment options are available:
from x402_openai import X402OpenAI, prefer_network, prefer_scheme, max_amount
from x402_openai.wallets import EvmWallet, SvmWallet
client = X402OpenAI(
wallets=[
EvmWallet(private_key="0x…"),
SvmWallet(private_key="base58…"),
],
policies=[
prefer_network("eip155:8453"), # Prefer Base mainnet
prefer_scheme("exact"), # Prefer exact payment scheme
max_amount(1_000_000), # Cap at 1 USDC (6 decimals)
],
)
X402OpenAI / AsyncX402OpenAIDrop-in replacement for openai.OpenAI / openai.AsyncOpenAI. Provide exactly one credential source:
| Parameter | Type | Description |
|---|---|---|
wallet |
Wallet |
Single wallet adapter |
wallets |
list[Wallet] |
Multiple adapters (multi-chain) |
policies |
list[Policy] |
Payment policies (chain/scheme preference, amount cap) |
x402_client |
x402HTTPClient* |
Pre-configured x402 client (bypasses policies) |
All standard OpenAI kwargs (base_url, timeout, max_retries, …) are forwarded.
Default base_url: https://llm.qntx.fun/v1
| Class | Chain | Extra |
|---|---|---|
EvmWallet(private_key=…) |
EVM | x402-openai[evm] |
EvmWallet(mnemonic=…) |
EVM (BIP-39) | x402-openai[evm] |
SvmWallet(private_key=…) |
Solana | x402-openai[svm] |
Implement the Wallet protocol to add a new chain.
X402Transport / AsyncX402Transport — httpx transports for manual wiring into any httpx.Client.
See the examples/ directory. Each script is self-contained:
EVM_PRIVATE_KEY="0x…" python examples/chat_evm.py
SOLANA_PRIVATE_KEY="base58…" python examples/chat_svm.py
EVM_PRIVATE_KEY="0x…" python examples/streaming_evm.py
MNEMONIC="word1 word2 …" python examples/chat_evm_mnemonic.py
EVM_PRIVATE_KEY="0x…" python examples/chat_evm_policy.py
EVM_PRIVATE_KEY="0x…" python examples/streaming_evm_policy.py
This project is licensed under the MIT License.
Drop-in OpenAI Typescript client with transparent x402 payment support.
Turn any API or MCP server into a paid service with x402
Manage AI agent teams locally using CLI, OAuth, and API tools to simulate a virtual company with autonomous workflows.
Open-source x402 payment processor for AI agents. Sub-400ms settlement on Solana + 7 EVM chains. Let LLMs pay for APIs programmatically with USDC. npm: nory-x402
Alephant is an open-source AI Agent Gateway for routing, tracking, and controlling LLM usage across AI agents, members, and workflows, and for publishing agent capabilities as paid endpoints with x402 and MPP payment rails.
Developer integration tools for adding TDM payments to AI agents, apps, and workflows. CLI, MCP server, and copy-paste examples
Open Source AI trading agent that operates autonomously across 1000+ markets - Polymarket, Kalshi, Binance, Hyperliquid, Solana DEXs, 5 EVM chains. Scans for edge, executes instantly, manages risk while you sleep. Agent commerce protocol for machine-to-machine payments. Self-hosted. Built on Claude.
TypeScript Interface for Machine Payments Protocol
Production-ready x402 facilitator server.
Rust SDK for the x402 payment protocol.
The financial operating system for AI agents. A single HTTP client that intercepts '402 Payment Required', routes across x402, L402, and MPP, persists credentials as recoverable assets, enforces per-envelope budgets, and emits a structured trace.
A wallet for agents. Make payments via x402, use stablecoins, swap assets, earn yield with defi and buy tokenized stocks across the most popular chains.