AiPayGent SDK

Copy-paste integration code for Python, JavaScript, curl, and MCP

No API keys, no accounts. POST to any endpoint → receive HTTP 402 with payment instructions → retry with signed USDC payment header. Use /preview to test free.

curl FREE — test first

# Free preview — no payment needed
curl https://api.aipaygent.xyz/preview?topic=bitcoin

# Paid endpoint — will return 402 first
curl -X POST https://api.aipaygent.xyz/research \
  -H "Content-Type: application/json" \
  -d '{"topic": "quantum computing breakthroughs 2025"}'

# With x402 payment header (Base Sepolia USDC)
curl -X POST https://api.aipaygent.xyz/research \
  -H "Content-Type: application/json" \
  -H "X-Payment: <signed-x402-tx>" \
  -d '{"topic": "quantum computing breakthroughs 2025"}'

Python

pip install x402-python anthropic

# --- research.py ---
from x402.client import X402Client
from eth_account import Account
import json

# Your EVM wallet (Base Sepolia for testnet)
account = Account.from_key("YOUR_PRIVATE_KEY")
client = X402Client(account)

# One call handles the 402 handshake automatically
response = client.post(
    "https://api.aipaygent.xyz/research",
    json={"topic": "quantum computing breakthroughs 2025"}
)
data = response.json()
print(data["summary"])
print(data["key_points"])

# --- batch.py (5 tasks, one payment at $0.10) ---
result = client.post(
    "https://api.aipaygent.xyz/batch",
    json={"operations": [
        {"endpoint": "research",  "input": {"topic": "AI agents 2025"}},
        {"endpoint": "summarize", "input": {"text": "...", "length": "short"}},
        {"endpoint": "sentiment", "input": {"text": "..."}},
    ]}
).json()

# --- pipeline.py (chain steps, pass output with {{prev}}) ---
result = client.post(
    "https://api.aipaygent.xyz/pipeline",
    json={"steps": [
        {"endpoint": "research",  "input": {"topic": "AI regulation EU 2025"}},
        {"endpoint": "summarize", "input": {"text": "{{prev}}", "length": "short"}},
        {"endpoint": "social",    "input": {"topic": "{{prev}}", "platforms": ["twitter"]}},
    ]}
).json()

JavaScript / Node.js

npm install x402-fetch viem

// research.mjs
import { wrapFetchWithPayment } from "x402-fetch";
import { privateKeyToAccount } from "viem/accounts";
import { baseSepolia } from "viem/chains";

const account = privateKeyToAccount("0xYOUR_PRIVATE_KEY");
const fetchWithPayment = wrapFetchWithPayment(fetch, account, baseSepolia);

const res = await fetchWithPayment("https://api.aipaygent.xyz/research", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ topic: "quantum computing 2025" }),
});
const data = await res.json();
console.log(data.summary);

// Generate social posts + translate in one pipeline call
const pipeline = await fetchWithPayment("https://api.aipaygent.xyz/pipeline", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ steps: [
    { endpoint: "write",      input: { spec: "blog post about x402", type: "article" } },
    { endpoint: "headline",   input: { content: "{{prev}}", count: 5 } },
    { endpoint: "translate",  input: { text: "{{prev}}", language: "Spanish" } },
  ]}),
});
const result = await pipeline.json();

MCP (Claude Desktop / Cursor / any MCP client)

# Option 1 — Remote (no install, no API key needed by client)
# Add to your MCP client config:
{
  "mcpServers": {
    "aipaygent": {
      "type": "streamable-http",
      "url": "https://mcp.aipaygent.xyz/mcp"
    }
  }
}

# Option 2 — Local via stdio (requires your own ANTHROPIC_API_KEY)
pip install aipaygent-mcp

{
  "mcpServers": {
    "aipaygent": {
      "command": "aipaygent-mcp",
      "env": { "ANTHROPIC_API_KEY": "sk-ant-..." }
    }
  }
}

Claude Agent (Anthropic SDK)

pip install anthropic x402-python

# Give Claude the ability to call AiPayGent tools
import anthropic, requests
from x402.client import X402Client
from eth_account import Account

x402 = X402Client(Account.from_key("YOUR_PRIVATE_KEY"))

def call_aipaygent(endpoint: str, payload: dict) -> dict:
    return x402.post(f"https://api.aipaygent.xyz/{endpoint}", json=payload).json()

client = anthropic.Anthropic()
tools = [{
    "name": "research",
    "description": "Research any topic. Returns summary, key points, and sources.",
    "input_schema": {"type": "object", "properties": {"topic": {"type": "string"}}, "required": ["topic"]},
}]

# Claude will autonomously call /research and use the result
response = client.messages.create(
    model="claude-sonnet-4-6", max_tokens=1024, tools=tools,
    messages=[{"role": "user", "content": "Research the latest in fusion energy"}]
)

Endpoints & Pricing

/research $0.01
/write $0.02
/code $0.02
/analyze $0.02
/translate $0.01
/summarize $0.01
/social $0.02
/extract $0.01
/qa $0.01
/classify $0.01
/sentiment $0.01
/keywords $0.01
/compare $0.01
/transform $0.01
/chat $0.02
/plan $0.02
/decide $0.01
/proofread $0.01
/explain $0.01
/questions $0.01
/outline $0.01
/email $0.01
/sql $0.01
/regex $0.01
/mock $0.01
/score $0.01
/timeline $0.01
/action $0.01
/pitch $0.02
/debate $0.02
/headline $0.01
/fact $0.01
/rewrite $0.01
/tag $0.01
/batch $0.10
/pipeline $0.15
/preview FREE