createAgentClient from @meterlane/x402/client inside a tool() definition, your agent can reach any Meterlane x402-gated route without you writing any payment-retry logic — the client handles the 402 → sign → retry cycle transparently inside the tool’s execute function.
All examples on this page target Base Sepolia (
eip155:84532) and the public sandbox demo route. Do not use mainnet keys or mainnet facilitators in development or CI.1
Install dependencies
You need Import the MIT-licensed client — not the server middleware:The client is MIT-licensed; audit what it signs before running it with a funded wallet.
@openai/agents for the agent runtime, zod for parameter schemas, and @meterlane/x402 for the x402 payment client.2
Set your environment variable
3
Create the payment tool
The tool calls
paidFetch — a fetch wrapper that handles x402 automatically — instead of calling fetch directly.4
Attach the tool to an agent and run it
Pass the tool to an Run the file:Without
Agent instance, then call run() with a prompt:OPENAI_API_KEY the script invokes the tool directly, which is useful for verifying that your wallet is funded and the payment flow works before you spend model tokens.How it works
When the agent callsmeterlanePaidGet, the execute function fires paidFetch(url). The x402 cycle runs inside that call:
- The client sends a plain
GETto the gateway. - The gateway returns 402 with an
X-Payment-Requirementsheader describing the USDC price and receiver address. ExactEvmSchemeuses your private key to sign an ERC-3009 authorization for that amount on Base Sepolia.- The client retries the request with the authorization attached as a payment header.
- The gateway settles on-chain and returns 200 with the upstream response body.
- The tool returns
{ ok: true, status: 200, bodyPreview }to the agent.
"eip155:84532" (Base Sepolia) with the default public x402.org facilitator for all development work. Production deployments that need Base mainnet require a private mainnet-capable facilitator configured in your Meterlane dashboard under Settings → Developer.