On-ramps
Six ways to give a brain a wallet · MCP, TypeScript, Python, LangChain, OpenAI, raw HTTP.
An agent is a brain plus a wallet plus a connector. The brain stays whatever it is. AgentPay gives it hands to pay. Pick the one line that fits your stack.
MCP (Claude, Cursor, any MCP client)
Zero code. Add the server and your agent gets three tools: agentpay_pay_and_fetch, agentpay_wallet_balance, agentpay_identity.
{
"mcpServers": {
"agentpay": {
"command": "npx",
"args": ["agentpay-mcp"],
"env": { "AGENTPAY_API_KEY": "apk_live_..." }
}
}
}
TypeScript SDK
import { AgentPayClient } from "@agentpay/sdk";
const pay = await AgentPayClient.create({ apiKey: process.env.AGENTPAY_API_KEY });
// pay.fetch wraps fetch: on a 402 it pays within your caps and retries.
const res = await pay.fetch("https://api.example.com/search?q=otters");
Python SDK
from agentpay import AgentPayClient
import os
pay = AgentPayClient(api_key=os.environ["AGENTPAY_API_KEY"])
res = pay.fetch("https://api.example.com/search?q=otters")
LangChain
from agentpay.langchain import AgentPayTool
tools = [AgentPayTool(api_key=os.environ["AGENTPAY_API_KEY"])]
# Your agent can now pay for any 402 API as a normal tool call.
OpenAI tool use
tools = [{
"type": "function",
"function": {
"name": "pay_and_fetch",
"description": "Call a paid API; pays automatically if it returns 402.",
"parameters": { "type": "object", "properties": { "url": { "type": "string" } } }
}
}]
Raw HTTP
The protocol is x402-compatible, so you can speak it with curl. See the wire protocol for the exact messages.
curl -i $MERCHANT/api/echo # 402 Payment Required
curl -s $GATEWAY/pay -d @payment.json # { receipt_id, signature }
curl -s $MERCHANT/api/echo -H "X-Payment-Receipt: $RECEIPT_ID" # 200 OK