x402-paywall-pattern

x402-paywall-pattern is a skill for Claude Code, Codex from gblinproject/gblin-treasury-risk-regime. It costs 61 tokens per session (1,674 once invoked), scanned A, original, MIT.

A pattern for charging agents or programs for access to an MCP server, web API, or agent endpoint. It uses x402, an HTTP payment method, with USDC cryptocurrency on Base and signed payment details.

In plain words
What is it for?
Use it to charge per tool call or API request, accept USDC micropayments, and add a paywall to an MCP server or AI-agent endpoint. It also documents an optional automatic treasury hook.
Why use it?
It provides a defined flow for rejecting unpaid requests, receiving payment information, checking it, and then running the requested tool or API call. This removes the need to design that payment exchange from scratch.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one. Also seen: positional $N argument.

Good fit Use it to charge per tool call or API request, accept USDC micropayments, and add a paywall to an MCP server or AI-agent endpoint. It also documents an optional automatic treasury hook.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/gblinproject/gblin-treasury-risk-regime/x402-paywall-pattern
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add gblinproject/gblin-treasury-risk-regime --skill x402-paywall-pattern
Clone the repo
git clone --depth 1 https://github.com/gblinproject/gblin-treasury-risk-regime

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for x402-paywall-pattern

README.md
[![agentmods](https://agentmods.dev/badge/skills/gblinproject/gblin-treasury-risk-regime/x402-paywall-pattern/github.svg)](https://agentmods.dev/skills/gblinproject/gblin-treasury-risk-regime/x402-paywall-pattern)
Your own site
<a href="https://agentmods.dev/skills/gblinproject/gblin-treasury-risk-regime/x402-paywall-pattern"><img src="https://agentmods.dev/badge/skills/gblinproject/gblin-treasury-risk-regime/x402-paywall-pattern/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for x402-paywall-pattern

Your own site · 80×15
<a href="https://agentmods.dev/skills/gblinproject/gblin-treasury-risk-regime/x402-paywall-pattern"><img src="https://agentmods.dev/badge/skills/gblinproject/gblin-treasury-risk-regime/x402-paywall-pattern.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 61 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,674 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00061 $0.01674
Opus 5 $0.00030 $0.00837
Sonnet 5 $0.00012 $0.00335
Haiku 4.5 $0.00006 $0.00167

Measured 11d ago against content hash 794993808046, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-11, from the pricing page.

Security

Grade A, and why

x402-paywall-pattern scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 11d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

const response = await fetch(url);
skills/x402-paywall-pattern/SKILL.md · 175 lines

How it starts

The opening of the file, as written. The whole thing — 175 lines — stays where its author put it; the contents beside it link to each section on GitHub.

x402 Paywall Pattern for MCP Servers and APIs

When this skill applies

Trigger when the user describes any of:

  • "Add a paywall to my MCP server"
  • "Charge per tool call"
  • "Monetize my AI agent's API"
  • "Accept USDC micropayments"
  • "x402 implementation"
  • "How do I get paid for my MCP tools?"

Architecture overview

x402 is Coinbase's HTTP 402 payment protocol. When a client (typically an AI agent) calls a paywalled endpoint without payment, the server returns HTTP 402 with a JSON manifest. The client signs an EIP-3009 transferWithAuthorization USDC transfer, embeds the signed payload in the X-Payment header, and retries.

Client → GET /api/my-tool
Server → 402 { amount, currency, recipient, facilitator, ... }
Client → signs EIP-3009 with USDC
Client → GET /api/my-tool, header X-Payment: <base64>
Server → verifies, executes, returns 200 with result

Reference implementation

// src/middleware/x402-paywall.ts
import type { NextApiRequest, NextApiResponse } from 'next';

const USDC_BASE = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913';
const FACILITATOR = process.env.X402_FACILITATOR_URL || 'https://x402.org/facilitator';

interface PaywallConfig {
  price: string;          // USDC amount, e.g. "0.01"
  recipient: string;      // Your wallet address
  description?: string;
}

export function withPaywall(handler: (req: NextApiRequest, res: NextApiResponse) => Promise<void>, config: PaywallConfig) {
  return async (req: NextApiRequest, res: NextApiResponse) => {
    const paymentHeader = req.headers['x-payment'] as string | undefined;

    if (!paymentHeader) {
      res.setHeader('Content-Type', 'application/json');
      return res.status(402).json({
        amount: config.price,
        currency: 'USDC',
        currencyAddress: USDC_BASE,
        chain: 'base',
        chainId: 8453,
        recipient: config.recipient,
        facilitator: FACILITATOR,
        description: config.description || 'Payment required',
      });
    }

    let proof: any;
    try {
      proof = JSON.parse(Buffer.from(paymentHeader, 'base64').toString('utf-8'));
    } catch {
      return res.status(400).json({ error: 'invalid_payment_header' });
    }

    if (!proof.signature || !proof.payer || !proof.amount) {
      return res.status(402).json({ error: 'invalid_payment' });
    }
    if (proof.expiresAt && proof.expiresAt < Date.now() / 1000) {
      return res.status(402).json({ error: 'payment_expired' });
    }

    return handler(req, res);
  };
}

Read the full file on GitHub · 175 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 11d ago First seen · 175 lines · 61 tokens per session scan A 794993808046

Subscribe to this mod's changes

x402-paywall-pattern is a skill published in the GitHub repository gblinproject/gblin-treasury-risk-regime (1 stars, last pushed yesterday), licensed MIT. It adds 61 tokens to every session and 1,674 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.