Turnstile is a zero-friction, wallet-based API gateway designed for AI agents.
Agents struggle with traditional "Human" commerce:
- Signups & CAPTCHAs block bots.
- Credit card forms are un-navigable.
- Monthly subscriptions don't fit "one-off" task needs.
Turnstile implements the HTTP 402 Payment Required status code correctly for the agent economy.
- Middleware-First: Easy to drop into any Express app.
- Replay Protection: Prevents transaction reuse.
- Session Tokens: Pay once, get a 1-hour "Day Pass" (JWT) for unlimited access.
- Agent requests resource -> 🔴 402 Error (Payment Details returned).
- Agent pays USDC on-chain (Base Sepolia).
- Agent retries with
x-payment-txheader. - Gateway verifies TX & issues Session Token -> 🟢 200 OK.
- Agent uses
Authorization: Bearer <token>for subsequent requests.
No API Keys. No Accounts. Just Pay & Play.
npm install turnstile-gatewayimport { turnstile } from 'turnstile-gateway';
app.get('/premium-resource',
turnstile({
receiver: "0xYourWallet...",
price: "1.0"
}),
(req, res) => {
res.json({ data: "Premium Content" });
}
);git clone https://github.com/tracychen/turnstile-agent-gateway
cd turnstile-agent-gateway
npm installEdit server.js and set your RECEIVER_WALLET.
node server.js# Step 1: Get Rejection
curl -i http://localhost:3001/api/ace-insight
# Step 2: Pay 1.0 USDC (Base Sepolia) & Get TX Hash
# Step 3: Exchange TX for Session Token
curl -i -H "x-payment-tx: 0x..." http://localhost:3001/api/ace-insight
# Step 4: Use Session Token (Free Access for 1h)
curl -i -H "Authorization: Bearer <token>" http://localhost:3001/api/ace-insight- Chain: Base Sepolia (USDC Testnet)
- Backend: Node.js + Express + JSONWebToken
- Crypto: Viem
- Token: Circle USDC
It turns every API endpoint into a vending machine. Agents can "buy" capabilities (computation, storage, data) from each other instantly. With Session Tokens, we move from "Pay-Per-Request" to "Pay-Per-Session", enabling real SaaS models for bots.