Usage Meter Lab
Per-session API metering with soft and hard limits backed by Redis/memory counters.
Run this experiment yourself
Demos are not embedded on this site. Deploy a standalone copy on Vercel or run the experiment app locally.
Local development
cd apps/experiments/usage-meter-lab pnpm install pnpm dev
Then open http://localhost:3010.
This is an experimental demo. Use it as a starting point for your own projects.
Usage Meter Lab is a Wave 3 Batch H composition lab. Pure helpers live in logic.ts; missing providers or stores degrade honestly (never fabricate AI output).
Features
- Soft + hard limits
- Per-session counters
- Redis/memory store
API Reference
POST /api/meter · GET /api/meter
{ "sessionId": "demo-1" }| Status | Cause |
|---|---|
200 | Allowed / soft warning |
429 | Hard limit |
400 | Missing session |
Implementation Details
Validate
Inputs are length-capped in logic.ts; APIs return 400 for missing fields.
Run
Route Handlers compose AI SDK, Redis/Neon, or ImageResponse as documented. Fallbacks include honest notes.
Limitations
- Not billing-grade metering.
- No stripe invoices.
- Demo caps only.
Use in your project
Copy the Route Handler(s) and logic.ts from apps/experiments/usage-meter-lab/.
Deployment
Local Development
cd apps/experiments/usage-meter-lab
pnpm install
pnpm devConfiguration
| Variable | Required | Purpose |
|---|---|---|
UPSTASH_REDIS_REST_* | No | Durable counters |