# BOTSPEAK.TECH — DEVELOPER & AI AGENT INTELLIGENCE MANIFESTO > **TL;DR / Semantic Anchor** > Botspeak.tech provides a stateless, edge-native HTTP 402 "Payment Required" reverse proxy gateway (Easy402) for charging autonomous AI agents per request in USDC stablecoin on Base mainnet. It includes edge security protections to halt recursive agent loops, vector similarity triggers, and token budgeting limits. --- ## 1. THE MISSION & M2M ECONOMY As internet traffic shifts from human-centric browser sessions to autonomous, millisecond-scale AI agents, legacy billing systems (such as credit cards, monthly subscriptions, and oauth forms) become a massive bottleneck. Botspeak.tech leverages the resurrected HTTP 402 status code and the stateless x402 protocol to enable friction-free, pay-per-request stablecoin monetization directly between machines. --- ## 2. THE x402 PROTOCOL SPECIFICATION When an AI agent or machine client requests a payment-gated endpoint through the Easy402 proxy, the proxy validates the payment receipt. If unpaid, it returns an **HTTP 402 Payment Required** response. ### 2.1 The HTTP 402 Gating Response The gateway sends: ```http HTTP/1.1 402 Payment Required Content-Type: application/json X-X402-Price: 0.0050 X-X402-Currency: USDC X-X402-Wallet: 0x71C7656EC7ab88b098defB751B7401B5f6d8976F X-X402-Invoice: inv_gw7f9b8c ``` ### 2.2 Payment Fulfillment Flow 1. **Detect 402:** The agent parses the headers. 2. **Settle Transaction:** The agent triggers a USDC payment matching `X-X402-Price` to the developer's EVM `X-X402-Wallet` via the public Coinbase Developer Platform (CDP) Facilitator on the Base network (Layer 2). 3. **Retry with Proof:** The agent retries the original request, attaching the transaction hash as proof of execution. ```http POST /v1/chat/completions HTTP/1.1 Host: gateway.botspeak.tech X-X402-Payment-Receipt: tx_0x9c8b7d6e5a4b3c2d1e... X-X402-Invoice: inv_gw7f9b8c Content-Type: application/json { "model": "gpt-4", "messages": [{"role": "user", "content": "Help me optimize my code."}] } ``` --- ## 3. EDGE SECURITY & RUNAWAY COST INSURANCE To prevent agents from falling into infinite loops that drain developer budgets, the proxy implements four layers of protection: 1. **Step-Count Circuit Breakers:** Closes connection if an agent session key triggers more than a set threshold of requests in a minute. 2. **Semantic Vector Similarity:** Computes cosine similarity of input prompts. If similarity exceeds 98% sequentially, it triggers a loop block. 3. **Token Budgeting:** Tracks cumulative input/output token usage per session key. 4. **Dynamic Low-Cost Routing:** Automatically falls back to cheaper LLM models when repetitive prompts are detected. --- ## 4. INTEGRATION CODE SAMPLES ### 4.1 Client Agent Handler (TypeScript) ```typescript import { ethers } from 'ethers'; async function fetchPaidApi(url: string, body: any) { let response = await fetch(url, { method: 'POST', body: JSON.stringify(body) }); if (response.status === 402) { const price = response.headers.get('X-X402-Price'); const destWallet = response.headers.get('X-X402-Wallet'); const invoice = response.headers.get('X-X402-Invoice'); console.log(`[HTTP 402] Payment Required: ${price} USDC to ${destWallet}`); // Call CDP or wallet provider to transfer USDC on Base const txHash = await executePaymentOnBase(destWallet, price); // Retry request with payment headers response = await fetch(url, { method: 'POST', headers: { 'X-X402-Payment-Receipt': txHash, 'X-X402-Invoice': invoice, 'Content-Type': 'application/json' }, body: JSON.stringify(body) }); } return await response.json(); } ``` ### 4.2 Hono Middleware Setup (TypeScript) ```typescript import { Hono } from 'hono'; import { x402Paywall } from '@botspeak/hono-middleware'; const app = new Hono(); app.use('/api/premium/*', x402Paywall({ priceUsdc: 0.005, recipientWallet: '0x71C7656EC7ab88b098defB751B7401B5f6d8976F', network: 'base', securityLevel: 'maximum' })); app.post('/api/premium/data', (c) => { return c.json({ status: 'success', data: 'Authorized data response' }); }); export default app; ```