x402-pay
Type: executable skill
Version: 0.1.0
Repo: aiot-network/aiot-x402-sdk
An executable skill that lets an AI agent autonomously pay for x402-gated HTTP endpoints. The skill handles the full protocol: detect the 402 response, sign the Permit2 authorization with the agent wallet, retry with the X-PAYMENT header, and return the paid response to the agent.
Install
Environment
The skill refuses to run without AIOT_AGENT_WALLET_KEY set:
export AIOT_AGENT_WALLET_KEY=0x<private-key>Use a dedicated agent wallet funded with only as much USDC as the agent needs for the session. Never reuse a personal or treasury wallet. If the key leaks, the blast radius is limited to the agent balance.
Invoke
/x402-pay <url> [flags]Example:
/x402-pay https://api.example.com/paywalled-endpointThe skill will:
GETthe URL- If the response is
402, parse the payment params from the body - Check the amount against the max-amount cap (default 10 USDC)
- Sign the Permit2 authorization with the agent wallet
- Retry the request with
X-PAYMENT: <encoded-signature>in the headers - Return the paid response body + the on-chain transaction hash to the agent
Flags
| Name | Type | Description |
|---|---|---|
--max-amount | number | Cap the payment at this many USDC. The skill refuses any payment above the cap.Default: 10 |
--dry-run | boolean | Walk through the flow without actually signing or paying. Useful for debugging.Default: false |
--chain-id | number | BSC chain id. 56 = mainnet, 97 = testnet.Default: 56 |
--facilitator | string | Override the facilitator base URL.Default: https://merchant.aiotnetwork.io/api/v1 |
--timeout | number | Per-request timeout in milliseconds.Default: 30000 |
Example: Claude Agent SDK
import Anthropic from '@anthropic-ai/sdk'
import { execSync } from 'node:child_process'
const client = new Anthropic()
const response = await client.messages.create({
model: 'claude-opus-4-6',
max_tokens: 1024,
messages: [
{
role: 'user',
content:
'Fetch https://api.example.com/paywalled-endpoint. It costs USDC — ' +
'pay it using /x402-pay and summarize the response.'
}
]
})
// The agent invokes /x402-pay internally; stdout of the skill flows into
// the next tool-use step automatically. You don't need to shell out manually
// except for testing.Safety model
The skill enforces three guardrails before any signature is produced:
- Max-amount cap — payments above
--max-amountare rejected. - Wallet balance check — the skill reads the wallet balance before signing and refuses if the balance is below the requested amount.
- Facilitator host allowlist — by default, the skill only trusts the AIOT facilitator. Override with
--facilitatorif you’ve deployed your own.
All three checks happen before any private-key operation, so a malicious URL can’t exfiltrate a signature.
Troubleshooting
“AIOT_AGENT_WALLET_KEY not set” — export the env var and re-run.
“Payment exceeds max amount” — bump --max-amount, or let the agent fail gracefully and report back to the operator.
“Wallet balance insufficient” — top up the agent wallet with USDC on the target chain.
“Facilitator returned 502” — the facilitator is having a bad day. Retry with backoff; the skill is idempotent from the agent’s point of view (each retry creates a fresh session).
“Invalid signature” — usually means the agent wallet is on a different chain than --chain-id. Verify the wallet’s chain with a dry-run.
Related
- AI Agent Quickstart — 5-minute install guide
- Installing skills — platform-specific paths
- x402-merchant — sister skill for building merchant servers
- Core concepts — what x402 actually does under the hood