Tempo Hackathon submission | Live Demo
An AI inference gateway where machines pay machines for intelligence. Cloudflare Workers AI serves LLM completions and embeddings behind MPP payments with real-time demand-based surge pricing. More agents requesting completions simultaneously? The price climbs.
Agent ──POST /api/chat──▶ Worker ──402 + surge price──▶ Agent pays via Tempo
│
Agent ◀──AI completion + Payment-Receipt──◀ Workers AI ◀──────┘
- Agent requests
/api/chatwith messages - Worker returns
402 Payment Requiredwith the current surge price - Agent's wallet signs a Tempo payment at the dynamic price
- Worker runs inference via Workers AI (Llama, Mistral, etc.)
- Response includes
Payment-Receipt+ JWT cookie for 1-hour repeat access - Every request is recorded — more agents = higher price
A Durable Object tracks demand per route with a sliding window and 5-tier piecewise pricing curve. EMA smoothing prevents price jitter.
| Tier | Demand threshold | Multiplier | Price at $0.001 base |
|---|---|---|---|
| Base | 0 | 1.0x | $0.001000 |
| Normal | 50 | 1.5x | $0.001500 |
| Elevated | 200 | 2.5x | $0.002500 |
| High | 1,000 | 5.0x | $0.005000 |
| Surge | 5,000 | 10.0x | $0.010000 |
Between tiers, the multiplier is linearly interpolated. All thresholds, multipliers, and the base price are configurable per route.
├── proxy/ # Cloudflare Worker (fork of cloudflare/mpp-proxy)
│ ├── src/
│ │ ├── index.ts # Hono app, AI handlers, routing
│ │ ├── auth.ts # MPP payment middleware + surge pricing
│ │ ├── pricing/
│ │ │ ├── pricing-engine.ts # Sliding window, tiers, EMA smoothing
│ │ │ └── engine.ts # Durable Object wrapper + WebSocket
│ │ └── api/routes.ts # /__mpp/api/* pricing endpoints
│ └── wrangler.jsonc # DO, Workers AI, protected patterns
├── simulator/ # Svelte 5 + Vite visualization dashboard
│ └── src/
│ ├── App.svelte # Charts, scenarios, controls
│ └── lib/ # Canvas/SVG charts, traffic scenarios
└── src/ # Standalone JS pricing engine (used by simulator)
| Endpoint | Auth | Description |
|---|---|---|
POST /api/chat |
MPP payment | AI chat completion (dynamic pricing) |
POST /api/embeddings |
MPP payment | Text embeddings (separate pricing tier) |
GET /__mpp/api/prices |
Public | Current dynamic prices for all routes |
GET /__mpp/api/status |
Public | Full status: demand, tier, config |
GET /__mpp/api/ws/:pattern |
Public | WebSocket live pricing stream |
GET /__mpp/health |
Public | Health check |
cd proxy
npm install
echo "JWT_SECRET=$(openssl rand -hex 32)" > .dev.vars
echo "MPP_SECRET_KEY=$(openssl rand -hex 32)" >> .dev.vars
npm run dev# Health check
curl http://localhost:8787/__mpp/health
# See dynamic prices
curl http://localhost:8787/__mpp/api/prices
# Trigger 402 with surge pricing
curl -X POST http://localhost:8787/api/chat \
-H "Content-Type: application/json" \
-d '{"messages":[{"role":"user","content":"hello"}]}'
# Watch prices climb
for i in {1..50}; do
curl -s -o /dev/null -X POST http://localhost:8787/api/chat \
-H "Content-Type: application/json" \
-d '{"messages":[{"role":"user","content":"x"}]}'
done
curl http://localhost:8787/__mpp/api/pricescd simulator
pnpm install
pnpm devDashboard at localhost:5173 with traffic scenarios (Super Bowl, DDoS, Black Friday), real-time charts, pricing curve visualization, and revenue analysis.
cd proxy
PRIVATE_KEY=0x... npm run test:clientcd proxy
npx wrangler login
npx wrangler deploy
npx wrangler secret put MPP_SECRET_KEY
npx wrangler secret put JWT_SECRETLive at: https://mpp-dynamic-pricing.0x471.workers.dev
- On-theme: MPP is for machine payments — machines paying for AI inference
- Real utility: AI agents with wallets can actually use this as an API gateway
- All Cloudflare: Worker + Durable Object + Workers AI = single platform, zero infra
- Visual demo: Simulator shows prices climbing as agents flood the endpoint
- Surge pricing is novel: No other MPP implementation does demand-based dynamic pricing
- Cloudflare Workers + Durable Objects + Workers AI
- MPP + mppx SDK + Tempo
- Hono (routing)
- Svelte 5 + Vite (simulator)
Built by trionlabs