Agent SDK integrations & snippets.
Copy-paste in 5s: Claude Code MCP, Cloudflare Agents SDK, OpenAI Python Guardrail, or 10% Referral Earner.
{
"mcpServers": {
"x402-screen": {
"type": "http",
"url": "https://aso-x402-screen.asostudio.workers.dev/mcp",
"headers": {
"X-Referral-Agent": "claude-code"
}
}
}
}
import { privateKeyToAccount, signTypedData } from "viem/accounts";
import { toHex } from "viem";
const API = "https://aso-x402-screen.asostudio.workers.dev";
const NETWORK = "eip155:8453";
const USDC = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
const account = privateKeyToAccount(process.env.PAYER_PRIVATE_KEY as `0x${string}`);
const TYPES = { TransferWithAuthorization: [["from", "address"], ["to", "address"], ["value", "uint256"], ["validAfter", "uint256"], ["validBefore", "uint256"], ["nonce", "bytes32"]].map(([name, type]) => ({ name, type })) };
export async function screenUrl(url: string) {
const demo = await fetch(`${API}/v1/demo?url=${encodeURIComponent(url)}`, {
headers: { "X-Referral-Agent": process.env.AGENT_ID ?? "cf-agent" },
});
if (demo.status !== 402) return demo.json();
const terms = JSON.parse(atob(demo.headers.get("PAYMENT-REQUIRED")!));
const accept = terms.accepts.find((a: any) => a.network === NETWORK && a.asset.toLowerCase() === USDC.toLowerCase());
if (!accept) throw new Error("402 offer has no exact USDC acceptance on Base");
const authorization = {
from: account.address,
to: accept.payTo as `0x${string}`,
value: BigInt(accept.maxAmountRequired),
validAfter: 0n,
validBefore: BigInt(Math.floor(Date.now() / 1000) + Number(accept.maxTimeoutSeconds)),
nonce: toHex(crypto.getRandomValues(new Uint8Array(32))),
};
const signature = await signTypedData({
account,
domain: { name: "USD Coin", version: "2", chainId: 8453, verifyingContract: USDC },
types: TYPES,
primaryType: "TransferWithAuthorization",
message: authorization,
});
const payment = btoa(JSON.stringify({
x402Version: 2, scheme: "exact", network: NETWORK, payload: { signature, authorization },
}));
const res = await fetch(`${API}/v1/screen/url`, {
method: "POST",
headers: { "content-type": "application/json", "PAYMENT-SIGNATURE": payment, "X-Referral-Agent": process.env.AGENT_ID ?? "cf-agent" },
body: JSON.stringify({ url }),
});
// 200 body = report; PAYMENT-RESPONSE header carries the settlement ref
return res.json();
}
import json
import os
import urllib.parse
import urllib.request
from agents import GuardrailFunctionOutput, RunContextWrapper, input_guardrail
API = "https://aso-x402-screen.asostudio.workers.dev"
REFERRAL = os.environ.get("X_REFERRAL_AGENT", "openai-guardrail")
RISKY = {"block", "malicious", "high_risk", "phishing"}
def _first_url(text: str) -> str | None:
for token in text.split():
if token.startswith(("http://", "https://")):
return token.rstrip(").,;")
return None
def _screen(url: str) -> dict:
req = urllib.request.Request(
f"{API}/v1/demo?url={urllib.parse.quote(url, safe='')}",
headers={"X-Referral-Agent": REFERRAL},
)
with urllib.request.urlopen(req, timeout=15) as res:
return json.load(res)
@input_guardrail(name="screen_inbound_url")
async def screen_inbound_url(
ctx: RunContextWrapper, agent, payload: str
) -> GuardrailFunctionOutput:
url = _first_url(payload)
if url is None:
return GuardrailFunctionOutput({"screened": False}, tripwire_triggered=False)
try:
verdict = _screen(url)
except Exception as exc:
return GuardrailFunctionOutput({"url": url, "error": str(exc)}, False)
return GuardrailFunctionOutput(
verdict, tripwire_triggered=verdict.get("verdict") in RISKY
)
// Autonomous directory router: screens candidates, pays $0.002 USDC on Base,
// and books 10% of every fee to its own address via X-Referral-Agent.
import { privateKeyToAccount, signTypedData } from "viem/accounts";
import { toHex } from "viem";
const API = "https://aso-x402-screen.asostudio.workers.dev";
const NETWORK = "eip155:8453";
const USDC = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
const earner = privateKeyToAccount(process.env.EARNER_PRIVATE_KEY);
const referral = earner.address; // 10% commission accrues to this address
const TYPES = { TransferWithAuthorization: [["from", "address"], ["to", "address"], ["value", "uint256"], ["validAfter", "uint256"], ["validBefore", "uint256"], ["nonce", "bytes32"]].map(([name, type]) => ({ name, type })) };
async function quote(url) {
const res = await fetch(`${API}/v1/demo?url=${encodeURIComponent(url)}`, { headers: { "X-Referral-Agent": referral } });
if (res.status !== 402) return { res };
const terms = JSON.parse(Buffer.from(res.headers.get("PAYMENT-REQUIRED"), "base64"));
return { res, terms };
}
async function pay(terms) {
const accept = terms.accepts.find((a) => a.network === NETWORK);
const authorization = { from: earner.address, to: accept.payTo, value: BigInt(accept.maxAmountRequired), validAfter: 0n, validBefore: BigInt(Math.floor(Date.now() / 1000) + Number(accept.maxTimeoutSeconds)), nonce: toHex(crypto.getRandomValues(new Uint8Array(32))) };
const signature = await signTypedData({ account: earner, primaryType: "TransferWithAuthorization", domain: { name: "USD Coin", version: "2", chainId: 8453, verifyingContract: USDC }, types: TYPES, message: authorization });
return Buffer.from(JSON.stringify({ x402Version: 2, scheme: "exact", network: NETWORK, payload: { signature, authorization } })).toString("base64");
}
const candidates = [
"https://aso-x402-screen.asostudio.workers.dev/v1/demo",
"https://developers.cloudflare.com/agents/",
];
for (const url of candidates) {
const { res, terms } = await quote(url);
if (!terms) { console.log(url, "listed-free", await res.text()); continue; }
const paid = await fetch(`${API}/v1/screen/url`, { method: "POST", headers: { "content-type": "application/json", "PAYMENT-SIGNATURE": await pay(terms), "X-Referral-Agent": referral }, body: JSON.stringify({ url }) });
console.log(url, "paid", paid.headers.get("PAYMENT-RESPONSE"), await paid.text());
}
Zero signup · live JSON with 4 copy-paste snippets
GET /v1/integrations
JSON endpoint returning all 4 verified developer integration snippets
Free $0.00
POST /mcp
Claude Code & Desktop streamable HTTP MCP server (@x402/mcp v2)
Free config
X-Referral-Agent
10% referral commission (1000 bps) accrued on every settled x402 payment
10% payout