Turn any API or MCP server into a paid service
paygate-402 is an early-stage TypeScript project in the AI payments / x402 ecosystem, focused on api-monetization, http-402, mcp-server, paid-api. It currently has 6 GitHub stars and 0 forks, and sits alongside related tools like toll-booth, t2000, awesome-mpp, tdm-sdk, inflow-cli, mcp-server-bloomfilter.
Turn any API or MCP server into a paid service
npm install paygate-402
import { PayGate } from 'paygate-402';
const paygate = new PayGate({
provider: 'stripe',
apiKey: process.env.STRIPE_KEY,
pricing: {
perRequest: 0.01,
perToken: 0.0001
}
});
// wrap your express app
app.use(paygate.middleware());
// or wrap specific routes
app.get('/api/premium', paygate.protect(), (req, res) => {
res.json({ data: 'premium content' });
});
import { MCPPayGate } from 'paygate-402/mcp';
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
const server = new Server({
name: 'my-mcp-server',
version: '1.0.0'
});
const paygate = new MCPPayGate({
provider: 'stripe',
apiKey: process.env.STRIPE_KEY,
pricing: {
perTool: {
'expensive_tool': 0.10,
'cheap_tool': 0.01
}
}
});
paygate.wrap(server);
import axios from 'axios';
const response = await axios.get('https://api.example.com/premium', {
headers: {
'Authorization': 'Bearer YOUR_PAYMENT_TOKEN'
}
});
// handle 402 Payment Required
if (response.status === 402) {
const paymentUrl = response.headers['payment-url'];
console.log('Payment required:', paymentUrl);
}
PayGate(options)Creates a new payment gateway instance.
Options:
| Option | Type | Description |
|---|---|---|
provider |
string |
Payment provider ('stripe', 'paypal', 'lightning') |
apiKey |
string |
Provider API key |
pricing |
PricingConfig |
Pricing configuration |
allowCredits |
boolean |
Allow prepaid credits (default: true) |
quotaLimits |
QuotaConfig |
Optional rate limits per user |
paygate.middleware()Returns Express middleware that intercepts requests and enforces payment.
paygate.protect(options?)Returns middleware for protecting specific routes.
Options:
| Option | Type | Description |
|---|---|---|
price |
number |
Override default price for this route |
creditsRequired |
number |
Require specific credit amount |
paygate.createPaymentToken(userId, credits)Generates a payment token for a user with prepaid credits.
Returns: Promise<string>
paygate.checkBalance(token)Checks remaining balance for a payment token.
Returns: Promise<{ credits: number, spent: number }>
// per-request pricing
{
pricing: {
perRequest: 0.05
}
}
// token-based pricing (for LLM APIs)
{
pricing: {
perToken: 0.0001,
perInputToken: 0.00005,
perOutputToken: 0.00015
}
}
// route-specific pricing
{
pricing: {
routes: {
'/api/basic': 0.01,
'/api/premium': 0.10,
'/api/enterprise': 1.00
}
}
}
// credit bundles
{
pricing: {
bundles: [
{ credits: 100, price: 9.99 },
{ credits: 500, price: 44.99 },
{ credits: 1000, price: 79.99 }
]
}
}
{
provider: 'stripe',
apiKey: process.env.STRIPE_SECRET_KEY,
webhookSecret: process.env.STRIPE_WEBHOOK_SECRET
}
{
provider: 'paypal',
clientId: process.env.PAYPAL_CLIENT_ID,
clientSecret: process.env.PAYPAL_CLIENT_SECRET,
sandbox: true
}
{
provider: 'lightning',
lndHost: process.env.LND_HOST,
macaroon: process.env.LND_MACAROON,
cert: process.env.LND_CERT
}
This project uses HTTP status code 402 (Payment Required) as defined in RFC 7231. When a request requires payment, the server responds with:
HTTP/1.1 402 Payment Required
Payment-URL: https://pay.example.com/checkout/xyz123
Payment-Amount: 0.05
Payment-Currency: USD
Content-Type: application/json
{
"error": "payment_required",
"amount": 0.05,
"currency": "USD",
"payment_url": "https://pay.example.com/checkout/xyz123"
}
PRs welcome. Open an issue first for big changes.
Run tests:
npm test
MIT
Any API becomes a Lightning toll booth in one line. L402 middleware for Express, Hono, Deno, Bun, and Workers.
Agentic finance infrastructure.
The MPP registry — 100+ Machine Payments Protocol tools, SDKs, services, and payment methods across 15+ chains. The definitive directory for Stripe + Tempo agent payments.
Open contract-facing SDK for payable routes and gateway-backed integrations. Thin public surface for authorize, checkout, and session flows.
A wallet for your agents to onboard and pay. Agentic MPP / x402 payments from your machine - CLI + MCP server.
MCP server for Bloomfilter, a domain registration service for AI Agents.
The living ecosystem where AI agents complete tasks through workflow loops, improve through iterative execution, are evaluated by mentor agents or humans in the loop, and turn completed work into reusable work experience and data to improve future agents.
Daydreams is a set of tools for building agents for commerce
The first agentic payment network: policy-controlled, gasless, and real money-ready. OmniClaw CLI + Financial Policy Engine let autonomous agents pay and earn safely at machine speed.
Agent behavior that compiles
The A2A x402 Extension brings cryptocurrency payments to the Agent-to-Agent (A2A) protocol, enabling agents to monetize their services through on-chain payments. This extension revives the spirit of HTTP 402 "Payment Required" for the decentralized agent ecosystem.
Live data for AI agents — search, research, markets, crypto, X/Twitter. Pay-per-call via x402 micropayments.