Pay for APIs with x402-protected on Solana, from the command line.
x402tool is like curl for x402 APIs. Hit any x402-protected endpoint, and the CLI handles the payment and retries automatically.
# See what it costs
x402tool GET https://jupiter.api.corbits.dev/tokens/v2/recent --dry-run
# Pay and get the response
x402tool GET https://jupiter.api.corbits.dev/tokens/v2/recent --keypair auth.jsonnpm install -g x402toolNode.js v18+.
1. Preview what you'll pay — always start here:
x402tool GET https://api.example.com/data --dry-run2. Make the request — add your Solana keypair:
x402tool GET https://api.example.com/data --keypair ~/.config/solana/auth.jsonThat's it. The CLI detects the 402 response, submits a Solana payment, and retries with proof.
x402tool POST https://triton.api.corbits.dev \
--keypair auth.json \
--body '{"jsonrpc":"2.0","id":1,"method":"getBalance","params":["corzHctjX9Wtcrkfxz3Se8zdXqJYCaamWcQA7vwKF7Q"]}'x402tool GET "https://jupiter.api.corbits.dev/ultra/v1/order" \
--query inputMint=So11111111111111111111111111111111111111112 \
--query outputMint=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v \
--query amount=20000000 \
--query taker=YOUR_WALLET_ADDRESSUse repeatable headers with either Key: Value or key=value:
x402tool GET https://api.example.com/data \
--header "x-api-key: abc123" \
--header x-client-id=my-agentx402tool GET https://api.example.com/data -o response.jsonPath must be under the current directory.
--json gives machine-readable output. --quiet suppresses wallet and timing logs.
x402tool GET https://api.example.com/data --dry-run --json --quiet
x402tool POST https://api.example.com/action --keypair auth.json --quiet -o result.jsonDefault is 30s. Override in milliseconds:
x402tool GET https://api.example.com/slow --timeout 60000These use Corbits x402-protected APIs.
x402tool GET "https://jupiter.api.corbits.dev/ultra/v1/order" \
--dry-run \
--query inputMint=So11111111111111111111111111111111111111112 \
--query outputMint=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v \
--query amount=20000000 \
--query taker=YOUR_WALLET_ADDRESSx402tool GET https://jupiter.api.corbits.dev/tokens/v2/recent \
--keypair ~/.config/solana/auth.jsonx402tool POST https://triton.api.corbits.dev \
--dry-run \
--body '{"jsonrpc":"2.0","id":1,"method":"getBalance","params":["corzHctjX9Wtcrkfxz3Se8zdXqJYCaamWcQA7vwKF7Q"]}'x402tool POST https://triton.api.corbits.dev \
--keypair ~/.config/solana/auth.json \
--body '{"jsonrpc":"2.0","id":1,"method":"getBalance","params":["corzHctjX9Wtcrkfxz3Se8zdXqJYCaamWcQA7vwKF7Q"]}'x402tool GET https://agent.metengine.xyz/api/v1/markets/trending \
--keypair ~/.config/solana/auth.json \
-o result.jsonx402tool GET "https://pro-api.coingecko.com/api/v3/x402/simple/price" \
--keypair ~/.config/solana/auth.json \
--query vs_currencies=usd --query symbols=btc,eth,sol --query include_market_cap=trueStandard Solana keypair format — a JSON array of numbers. Must be under cwd or home.
solana-keygen new -o my-keypair.json- You make a request (GET or POST).
- If the API returns 402, the CLI parses payment requirements via
@x402/core. - It signs and submits a Solana transaction with
@x402/svm. - It retries the original request with the payment proof attached.
With --dry-run, it stops at step 2 and shows you the requirements.
The network (mainnet/devnet) is determined by the API's payment response, not by a CLI flag.
| Flag | What it does |
|---|---|
--keypair <path> |
Solana keypair for payment |
--dry-run |
Preview costs, don't pay |
--body <json> |
JSON body (POST only) |
--query <k=v> |
Query param (repeatable) |
--header <header> |
HTTP header (repeatable) |
--rpc-url <url> |
Solana RPC (or SOLANA_RPC_URL env) |
--json |
Machine-readable output |
--quiet |
Suppress extra logs |
--timeout <ms> |
Request timeout (default: 30000) |
-o, --output <path> |
Write response to file |
- Automatic Solana payment on 402 responses
- Dry-run mode to preview costs
- GET and POST with optional JSON body
- Agent-friendly JSON and quiet modes
- Configurable timeout, query params, output path
- URL scheme and keypair path validation
git clone https://github.com/pratikbuilds/x402-cli.git
cd x402-cli
npm install
npm run build
node dist/index.js GET <url>Fork, branch, commit, push, open a PR.
MIT — see LICENSE.
