Getting Started
Botspeak.tech offers the easiest way to payment-gate any API endpoint, enabling secure micro-transactions directly between autonomous AI agents and servers.
How it Works
API providers register their endpoint on our platform, setting a per-call cost in USDC. When an agent queries the proxy gateway URL, the proxy evaluates the request status: if unpaid, the proxy responds with HTTP 402 Payment Required; once payment is processed via the Base network, the proxy proxies the request to your origin server.
Deployment Workflow
- Input your backend target endpoint URL.
- Define the cost per request in USDC.
- Input your EVM payout wallet address.
- Deploy the proxy in a single click and retrieve your paywalled endpoint.
import { BotSpeakProxy } from '@botspeak/sdk'; const proxy = await BotSpeakProxy.create({ originUrl: 'https://api.openai.com/v1', pricePerCall: 0.002, walletAddress: '0x71C7656EC7ab88b...', network: 'base-mainnet' }); console.log(`Proxy deployed at: ${proxy.url}`);
x402 Protocol Specification
The x402 protocol resurrects HTTP 402 "Payment Required" to handle machine-to-machine micro-payments statelessly at the serverless edge.
HTTP 402 Response Format
When a client calls a paid gateway without a valid payment receipt, the gateway returns status 402 with the following metadata headers:
HTTP/1.1 402 Payment Required Content-Type: application/json X-X402-Price: 0.005 X-X402-Currency: USDC X-X402-Wallet: 0x71C7656EC7ab88b098defB751B7401B5f6d8976F X-X402-Invoice: inv_7f9b8c8d8a7c29be
Fulfillment Flow
- The autonomous agent reads the headers, gets the invoice ID, destination wallet, and price.
- The agent calls the CDP (Coinbase Developer Platform) Facilitator on Base to trigger a transaction.
- Upon transaction execution, the agent retries the API request, adding the payment receipt:
POST /v1/chat/completions HTTP/1.1 Host: gateway.botspeak.tech X-X402-Payment-Receipt: tx_0x9a8b7c6d5e4f3a... X-X402-Invoice: inv_7f9b8c8d8a7c29be
Edge Security & Loop Traps
A primary risk for developers deploying AI agent toolkits is the "recursive loop trap"—an infinite loop where an agent repeatedly executes the same API tool, draining budgets within minutes.
Four-Layer Protection Suite
Our Pro-tier gateway mitigates this at the Edge using four protective layers running with sub-millisecond overhead:
- Step-Count Circuit Breaker: Monitors the execution depth of a single agent session. If requests exceed a preset depth threshold (e.g., 20 requests/minute), the circuit breaks, returning
429 Too Many Requests. - Semantic Vector Similarity: Ingests the agent's prompts and matches embedding vectors against previous calls. If similarity exceeds 98% sequentially, it triggers a warning and halts execution.
- Cumulative Token Budgeting: Maintains a rolling token allowance for each token key. Once exceeded, the session is gated until the next billing window.
- Dynamic Low-Cost Model Routing: Detects repetitive reasoning and automatically downgrades prompt execution to cheaper models to save cost.
Hono Middleware Setup
Integrating BotSpeak proxy logic directly into your serverless API is straightforward using Hono, running on Cloudflare Workers, Bun, or Node.
import { Hono } from 'hono'; import { x402Paywall } from '@botspeak/hono-middleware'; const app = new Hono(); // Apply x402 paywall to premium routes app.use('/api/premium/*', x402Paywall({ priceUsdc: 0.01, recipientWallet: '0x71C7656EC7ab88b098defB751B7401B5f6d8976F', network: 'base', securityLevel: 'maximum' // Enables vector loop-trap detection })); app.post('/api/premium/generate', (c) => { return c.json({ data: 'Super high value AI computation result.' }); }); export default app;