Case study · Proxy
Side projectProject period2026 – Present
Layered protection for a public AI endpoint
Combined Tor blocking, Cloudflare Turnstile, per-IP rate limits, a shared daily budget and an owner-only authenticator pass, so a request that should not reach a model never does.
01
Why
Proxy is public, has no login, and every answer spends model tokens. Left alone, one script could drain the budget or turn a portfolio assistant into a free general-purpose chatbot. The cheapest place to stop that is before any model is called.
02
Decision
I put the checks in a deliberate order, cheapest first: Tor blocking, a Cloudflare Turnstile bot check, a per-visitor limit, then one shared daily budget for the whole service. The order matters: a bot that fails Turnstile cannot use up a shared address's allowance. Failed requests are refunded, so a visitor's three answers are three real answers, not three attempts. The per-visitor counters live in a Durable Object so they are exact across locations and survive restarts. For testing I added an owner-only pass (a signed, one-hour code from an authenticator app) that skips the visitor limit, so the limit never gets in my way and no secret sits in the code.
How it fits
Hover or focus a box for the story behind it.
The question passes the checks, the router picks the part of the notes it needs (a small model, with keyword rules as the fallback), and the main model writes a short answer from only that context. Project cards or a contact card are added when they help.
03
What I built
An endpoint that answers for me is public, so abuse has to be stopped before it costs anything. Combined Tor blocking, Cloudflare Turnstile verification, per-IP rate limits, a shared daily budget and an owner-only authenticator pass (signed, one-hour, TOTP-based). A request that should not reach a model never does.
04
Trade-offs
- Three answers per visitor is strict: I treat it as a lifetime cap on purpose, because every answer spends model tokens. It is counted per network address, so people on one shared network share an allowance.
- Tor users are blocked outright.
- The shared daily budget means a very busy day ends with a polite "please get in touch" for later visitors instead of a bigger bill.
05
Outcome
A request that should not reach a model never does, and the worst-case spend is a known number (about $7 a month at the daily cap) instead of "whatever traffic brings".