Drop-in OpenAI Typescript client with transparent x402 payment support.
x402-openai-typescript is an established TypeScript project in the AI payments / x402 ecosystem, focused on ethereum, openai, solana, typescript. It currently has 152 GitHub stars and 25 forks, and sits alongside related tools like x402-openai-python, tdm-integration-kit, tdm-sdk, TDM-Agent-Integration-Kit, Sentinel, CloddsBot.
The TypeScript sibling of qntx’s x402 OpenAI client: a drop-in wrapper around the OpenAI client that transparently handles x402 payments, so agent code paying for metered inference or tool endpoints needs no separate payment plumbing.
For the large share of the agent ecosystem building in TypeScript, this lowers the barrier to consuming paid x402 services to almost nothing — keep your OpenAI-compatible calls, gain automatic USDC settlement on a 402. It targets Ethereum and Solana.
Best for: TypeScript/Node agents calling OpenAI-compatible APIs that want automatic pay-per-request. See the TypeScript SDK category for alternatives.
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.
bun add x402-openai @x402/evm viem # EVM (Ethereum / Base / …)
bun add x402-openai @x402/svm @solana/kit @scure/base # Solana
bun add x402-openai @x402/evm @x402/svm viem @solana/kit @scure/base # all chains
import { X402OpenAI } from "x402-openai";
import { EvmWallet } from "x402-openai/wallets";
const client = new X402OpenAI({
wallet: new EvmWallet({ privateKey: "0x…" }),
});
const res = await client.chat.completions.create({
model: "openai/gpt-4o-mini",
messages: [{ role: "user", content: "Hello!" }],
});
console.log(res.choices[0]?.message.content);
Swap EvmWallet for SvmWallet to pay on Solana — the API is identical.
const stream = await client.chat.completions.create({
model: "openai/gpt-4o-mini",
messages: [{ role: "user", content: "Explain x402" }],
stream: true,
});
for await (const chunk of stream) {
const content = chunk.choices[0]?.delta?.content;
if (content) process.stdout.write(content);
}
import { EvmWallet, SvmWallet } from "x402-openai/wallets";
const client = new X402OpenAI({
wallets: [
new EvmWallet({ privateKey: "0x…" }),
new SvmWallet({ privateKey: "base58…" }),
],
});
const wallet = new EvmWallet({ mnemonic: "word1 word2 … word12" });
const wallet2 = new EvmWallet({ mnemonic: "…", accountIndex: 2 }); // m/44'/60'/0'/0/2
const wallet3 = new EvmWallet({ mnemonic: "…", derivationPath: "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:
import { X402OpenAI, preferNetwork, preferScheme, maxAmount } from "x402-openai";
import { EvmWallet, SvmWallet } from "x402-openai/wallets";
const client = new X402OpenAI({
wallets: [
new EvmWallet({ privateKey: "0x…" }),
new SvmWallet({ privateKey: "base58…" }),
],
policies: [
preferNetwork("eip155:8453"), // Prefer Base mainnet
preferScheme("exact"), // Prefer exact payment scheme
maxAmount(1_000_000n), // Cap at 1 USDC (6 decimals)
],
});
X402OpenAIDrop-in replacement for openai.OpenAI. Provide exactly one credential source:
| Parameter | Type | Description |
|---|---|---|
wallet |
Wallet |
Single wallet adapter |
wallets |
Wallet[] |
Multiple adapters (multi-chain) |
policies |
PaymentPolicy[] |
Payment policies (chain/scheme preference, amount cap) |
x402Client |
x402Client |
Pre-configured x402 client (bypasses policies) |
All standard OpenAI options (baseURL, timeout, maxRetries, …) are forwarded.
Default baseURL: https://llm.qntx.fun/v1
| Class | Chain | Install extras |
|---|---|---|
EvmWallet({ privateKey: … }) |
EVM | @x402/evm viem |
EvmWallet({ mnemonic: … }) |
EVM (BIP-39) | @x402/evm viem |
SvmWallet({ privateKey: … }) |
Solana | @x402/svm @solana/kit @scure/base |
Implement the Wallet interface to add a new chain.
See the examples/ directory. Each script is self-contained:
EVM_PRIVATE_KEY="0x…" bun examples/chat-evm.ts
SOLANA_PRIVATE_KEY="base58…" bun examples/chat-svm.ts
EVM_PRIVATE_KEY="0x…" bun examples/streaming-evm.ts
MNEMONIC="word1 word2 …" bun examples/chat-evm-mnemonic.ts
EVM_PRIVATE_KEY="0x…" bun examples/chat-evm-policy.ts
EVM_PRIVATE_KEY="0x…" SOLANA_PRIVATE_KEY="base58…" bun examples/chat-multichain-policy.ts
This project is licensed under the MIT License.
Drop-in OpenAI Python client with transparent x402 payment support.
Developer integration tools for adding TDM payments to AI agents, apps, and workflows. CLI, MCP server, and copy-paste examples
Open contract-facing SDK for payable routes and gateway-backed integrations. Thin public surface for authorize, checkout, and session flows.
Developer integration tools for adding TDM payments to AI agents, apps, and workflows. CLI, MCP server, and copy-paste examples
Enterprise audit, compliance & budget enforcement layer for the x402 payment protocol
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.
Turn any API or MCP server into a paid service with x402
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.