Home / Guides / Use Agent402 from Claude Code, Cursor, VS Code, Windsurf, Cline, Roo Code, Codex CLI, Gemini CLI, Continue, ElizaOS, AgentCore and any OpenAI SDK

Use Agent402 from Claude Code, Cursor, VS Code, Windsurf, Cline, Roo Code, Codex CLI, Gemini CLI, Continue, ElizaOS, AgentCore and any OpenAI SDK

Agent402 opens two doors to an agent host:

  • Models: an OpenAI-compatible gateway. Run the local wallet proxy (agent402-openclaw proxy, below) and point any client that accepts a base URL at http://127.0.0.1:8412/v1: it pays each call from your wallet over x402. With a credits key you already hold, a client can instead use https://agent402.tools/v1/metered directly with the key as its API key. Each request is quoted from its own body (input plus your max_tokens), from $0.001 a call. GET https://agent402.tools/v1/models lists every id with its price and input cap; auto (routed per prompt, flat $0.01) lives at https://agent402.tools/v1/auto.
  • Tools: the hosted MCP connector at https://agent402.tools/mcp (discovery and the free tier need no key at all), or the agent402-mcp stdio server, which pays wallet-only tools from a wallet when AGENT_KEY is set (an EVM key holding USDC; SOLANA_AGENT_KEY pays on Solana).

Already hold a credits key (a402_…) from before? It keeps working: put it in AGENT402_CREDITS_KEY in place of AGENT_KEY in any stdio block below. GET /api/credits/balance (Bearer) reports what a credits key has left. Use a low-value wallet funded only with what you mean to spend. Every route also answers a stock x402 402 (USDC on Base, Solana, Polygon, Arbitrum, Monad, Celo, Avalanche, Sei, Optimism, Stellar, or Algorand - or USDG on Robinhood Chain) and an MPP challenge, so any x402 client pays per call with no key.

Pay from a wallet (local proxy)

The proxy runs on your machine, signs an x402 payment for each call from a wallet you hold (the key never leaves the machine), and forwards to the gateway. Any OpenAI-compatible client then uses it as its base URL:

npm i agent402-openclaw @x402/fetch @x402/evm viem   # in one folder
export AGENT402_WALLET_KEY=0x...      # an EVM key holding USDC on Base
export AGENT402_MAX_PER_CALL_USD=2    # per-call ceiling checked before signing
npx agent402-openclaw proxy           # run from that folder; serves http://127.0.0.1:8412/v1

Install the four packages together and run the proxy from the same folder: the wallet packages are optional peers, so a proxy started without them runs unpaid and logs that x402 payment is unavailable.

Use model auto or any id from GET /v1/models. Run npx agent402-openclaw permit2-approve once to settle metered calls at actual usage instead of the quote. The proxy also answers the Anthropic wire (POST /v1/messages), so Claude Code pays from the same wallet (next section).

Claude Code

Claude Code as an LLM client, billed per request under a quoted ceiling. With the local proxy running (above), point Claude Code at it and it pays each turn from your wallet:

export ANTHROPIC_BASE_URL=http://127.0.0.1:8412
export ANTHROPIC_AUTH_TOKEN=unused    # the proxy pays; this value is ignored
claude --model anthropic/claude-sonnet-5.5

With a credits key you already hold, you can instead point it at the metered tier with the credits key as the auth token (Bearer), keep your usual model names - dated ids like claude-haiku-4-5-20251001 resolve to the live model:

export ANTHROPIC_BASE_URL=https://agent402.tools/v1/metered
export ANTHROPIC_AUTH_TOKEN=a402_...
claude --model anthropic/claude-sonnet-5.5

Verified 2026-08-27 with claude-cli 2.1.250: a full turn (110 KB system prompt + 22 tool schemas, adaptive thinking, streaming) and a tool-use round trip both complete; each turn is quoted from its own body (/v1/metered accepts bodies to 1 MB / 200k input chars) and settles at actual usage, so an idle turn costs cents, never the ceiling. Not carried on this wire: output_config, context_management (dropped, the model default applies) and server-side tools (web search, computer use) - Claude Code's own tools are client tools and work as usual.

Tools over the hosted connector (free tier and discovery, no key):

claude mcp add --transport http agent402 https://agent402.tools/mcp

Paid tools from a wallet, through the stdio server:

claude mcp add agent402 -e AGENT_KEY=0x... -- npx -y agent402-mcp

Or in .mcp.json at the project root:

{
  "mcpServers": {
    "agent402": {
      "command": "npx",
      "args": ["-y", "agent402-mcp"],
      "env": { "AGENT_KEY": "${AGENT_KEY}" }
    }
  }
}

Cursor

.cursor/mcp.json in the project (or ~/.cursor/mcp.json for every project). Remote, no key:

{ "mcpServers": { "agent402": { "url": "https://agent402.tools/mcp" } } }

Paid tools from a wallet:

{
  "mcpServers": {
    "agent402": {
      "command": "npx",
      "args": ["-y", "agent402-mcp"],
      "env": { "AGENT_KEY": "0x..." }
    }
  }
}

Continue

config.yaml. A model entry for chat, plus the connector for agent mode:

models:
  - name: Agent402 (metered)
    provider: openai
    apiBase: http://127.0.0.1:8412/v1   # the local wallet proxy (above)
    apiKey: unused                      # the proxy pays from your wallet
    model: openai/gpt-4o-mini
    roles:
      - chat
mcpServers:
  - name: Agent402
    type: streamable-http
    url: https://agent402.tools/mcp

Any id from /v1/models works as model. With a credits key you already hold, use apiBase: https://agent402.tools/v1/metered and the key as apiKey instead. The metered route takes up to 200,000 characters of input per request.

ElizaOS

Tools: the elizaos-plugin-agent402 plugin adds AGENT402_FIND / AGENT402_CALL / AGENT402_ABOUT actions ("plugins": ["elizaos-plugin-agent402"], setting AGENT402_WALLET_KEY to an EVM key holding USDC, or AGENT402_CREDITS_KEY for a credits key you already hold). Models: the OpenAI plugin reads its base URL from the environment, so no code changes. With the local wallet proxy running (above):

OPENAI_BASE_URL=http://127.0.0.1:8412/v1
OPENAI_API_KEY=unused
OPENAI_LARGE_MODEL=anthropic/claude-sonnet-5.5
OPENAI_MEDIUM_MODEL=openai/gpt-4o-mini

The proxy serves chat. Embeddings live at /v1/embeddings ($0.002 a call), which the proxy does not forward: with a credits key you already hold, set OPENAI_EMBEDDING_URL=https://agent402.tools/v1 and OPENAI_EMBEDDING_MODEL=text-embedding-3-small, with the key as the API key.

Any OpenAI SDK

With the local wallet proxy running (above), point the SDK at it; the proxy pays each call from your wallet:

from openai import OpenAI
client = OpenAI(base_url="http://127.0.0.1:8412/v1", api_key="unused")
r = client.chat.completions.create(model="openai/gpt-4o-mini",
    messages=[{"role": "user", "content": "One sentence on x402."}], max_tokens=60)
print(r.choices[0].message.content)

With a credits key you already hold, exported as AGENT402_CREDITS_KEY, call the metered route directly:

import os
from openai import OpenAI
client = OpenAI(base_url="https://agent402.tools/v1/metered", api_key=os.environ["AGENT402_CREDITS_KEY"])
r = client.chat.completions.create(model="openai/gpt-4o-mini",
    messages=[{"role": "user", "content": "One sentence on x402."}], max_tokens=60)
print(r.choices[0].message.content)
import OpenAI from "openai";
const apiKey = process.env.AGENT402_CREDITS_KEY;
// Stop here when it is unset: the SDK would otherwise fall back to OPENAI_API_KEY
// and send that key to this base URL.
if (!apiKey) throw new Error("export AGENT402_CREDITS_KEY first");
const client = new OpenAI({ baseURL: "https://agent402.tools/v1/metered", apiKey });
const r = await client.chat.completions.create({ model: "openai/gpt-4o-mini",
  messages: [{ role: "user", content: "One sentence on x402." }], max_tokens: 60 });
console.log(r.choices[0].message.content);

Send an Idempotency-Key header on retries and a retried call replays the paid answer instead of paying again.

The same metered pricing is on the Responses wire too, for the OpenAI Agents SDK and responses.create(): base URL https://agent402.tools/v1/metered (route /v1/metered/responses), function tools only, store always false.

Any Anthropic SDK (Messages wire)

The same metered pricing on the Anthropic Messages wire. From a wallet, point the SDK's base URL at the local proxy (http://127.0.0.1:8412, which answers POST /v1/messages) with any placeholder key. With a credits key you already hold, use https://agent402.tools/v1/metered (route /v1/metered/messages) and pass the key as the SDK's auth_token (sent as Authorization: Bearer, which the credits gate reads), not api_key (sent as x-api-key):

import os
from anthropic import Anthropic
client = Anthropic(base_url="https://agent402.tools/v1/metered", auth_token=os.environ["AGENT402_CREDITS_KEY"])
m = client.messages.create(model="anthropic/claude-haiku-4.5", max_tokens=60,
    messages=[{"role": "user", "content": "One sentence on x402."}])
print(m.content[0].text)
import Anthropic from "@anthropic-ai/sdk";
const authToken = process.env.AGENT402_CREDITS_KEY;
if (!authToken) throw new Error("export AGENT402_CREDITS_KEY first");
// apiKey: null keeps the SDK from reading ANTHROPIC_API_KEY from the
// environment and sending it here as x-api-key.
const client = new Anthropic({ baseURL: "https://agent402.tools/v1/metered", apiKey: null, authToken });
const m = await client.messages.create({ model: "anthropic/claude-haiku-4.5", max_tokens: 60,
  messages: [{ role: "user", content: "One sentence on x402." }] });
console.log(m.content[0].text);

Amazon Bedrock AgentCore

An AgentCore Gateway turns https://agent402.tools/openapi.json into MCP tools with an OpenAPI target (agentcore add gateway-target --type open-api-schema --schema <path to openapi.json>), or aggregates the hosted connector as an MCP server target. Paid calls ride AgentCore Payments: the agent forwards our 402 payload, AgentCore signs it from its managed wallet, and the retry carries the signed payment header; every Agent402 route answers a stock x402 v2 challenge, so nothing on our side needs configuring.

VS Code

GitHub Copilot's agent mode reads .vscode/mcp.json in the workspace (or the user profile via the MCP: Open User Configuration command; MCP: Add Server in the palette writes either). Remote, free tier, no key:

{ "servers": { "agent402": { "type": "http", "url": "https://agent402.tools/mcp" } } }

Paid tools from a wallet, through the stdio server with the key held in a prompted input (VS Code stores it, the file never carries it):

{
  "inputs": [{ "type": "promptString", "id": "agent402-key", "description": "EVM private key holding USDC (0x...)", "password": true }],
  "servers": {
    "agent402": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "agent402-mcp"],
      "env": { "AGENT_KEY": "${input:agent402-key}" }
    }
  }
}

Windsurf

Cascade reads ~/.codeium/windsurf/mcp_config.json (Streamable HTTP, SSE and stdio are all supported; note Cascade caps the tools it can see at 100 in total across servers, and this connector lists a small fixed set, not the whole catalog). Remote, free tier:

{ "mcpServers": { "agent402": { "serverUrl": "https://agent402.tools/mcp" } } }

Paid tools from a wallet, with the key read from the environment (${env:VAR} interpolation is Windsurf's own):

{
  "mcpServers": {
    "agent402": {
      "command": "npx",
      "args": ["-y", "agent402-mcp"],
      "env": { "AGENT_KEY": "${env:AGENT_KEY}" }
    }
  }
}

Cline

MCP Servers icon in the top toolbar, Configure tab, then Configure MCP Servers (the CLI reads ~/.cline/mcp.json). Remote, free tier:

{
  "mcpServers": {
    "agent402": { "type": "streamableHttp", "url": "https://agent402.tools/mcp", "disabled": false, "autoApprove": [] }
  }
}

Paid tools from a wallet:

{
  "mcpServers": {
    "agent402": {
      "command": "npx",
      "args": ["-y", "agent402-mcp"],
      "env": { "AGENT_KEY": "0x..." },
      "disabled": false,
      "autoApprove": []
    }
  }
}

Cline's own "OpenAI Compatible" provider also accepts a base URL, so the models door works too: base URL http://127.0.0.1:8412/v1 (the local wallet proxy, above) with any placeholder API key, and a model id from /v1/models. A credits key you already hold works with base URL https://agent402.tools/v1/metered and the key as the API key.

Roo Code

Settings icon in the Roo pane, then Edit Global MCP (mcp_settings.json) or Edit Project MCP (.roo/mcp.json, which wins on a name clash). Remote, free tier:

{
  "mcpServers": {
    "agent402": { "type": "streamable-http", "url": "https://agent402.tools/mcp", "alwaysAllow": [], "disabled": false }
  }
}

Paid tools from a wallet:

{
  "mcpServers": {
    "agent402": {
      "command": "npx",
      "args": ["-y", "agent402-mcp"],
      "env": { "AGENT_KEY": "0x..." },
      "alwaysAllow": [],
      "disabled": false
    }
  }
}

OpenAI Codex CLI

One command for the free tier:

codex mcp add agent402 --url https://agent402.tools/mcp

Or in ~/.codex/config.toml, paid tools from a wallet through the stdio server:

[mcp_servers.agent402]
command = "npx"
args = ["-y", "agent402-mcp"]
env = { AGENT_KEY = "0x..." }

Codex as a model host, with a credits key you already hold (the local proxy does not serve the Responses wire): its model_providers speak the Responses wire, and the metered tier serves it at /v1/metered/responses (quoted per request from the body, settled at actual usage for a credits key). In ~/.codex/config.toml:

model_provider = "agent402"
model = "anthropic/claude-haiku-4.5"

[model_providers.agent402]
name = "Agent402 (metered)"
base_url = "https://agent402.tools/v1/metered"
env_key = "AGENT402_CREDITS_KEY"
wire_api = "responses"

Then export AGENT402_CREDITS_KEY=a402_... and run codex. The route is proven daily by the paid canary; a full Codex session against it has not yet been run end to end, so if a turn is refused, the 400 body says exactly which field (server tools and previous_response_id are not served).

Gemini CLI

One command for the free tier:

gemini mcp add --transport http agent402 https://agent402.tools/mcp

Or in ~/.gemini/settings.json (httpUrl is the Streamable HTTP key; url means SSE), paid tools from a wallet through the stdio server:

{
  "mcpServers": {
    "agent402": {
      "command": "npx",
      "args": ["-y", "agent402-mcp"],
      "env": { "AGENT_KEY": "0x..." }
    }
  }
}

What the same wallet buys

The wallet (or credits key) that pays for chat pays for the rest: four wires on every tier (OpenAI chat, OpenAI Responses, Anthropic Messages, Gemini generateContent), embeddings, rerank, images, speech and transcription, 500+ tools, finished reports and monitors, and a router that buys from other sellers and resells the result, proven sellers first. Why pay here, with the proof links: agent402.tools/#why.

Packages for this guide

Back to guides