Flat-rate AI SaaS pricing breaks in three predictable ways: a customer with a past_due Stripe subscription keeps calling your /v1/chat/completions endpoint, a runaway coding or research agent gets stuck retrying the same failing tool call 80 times in a minute, or a heavy user burns more in frontier model tokens than their monthly subscription brings in.
Putting a reverse proxy in front of OpenAI, Anthropic, or Gemini sounds simple until you try to inspect multi-megabyte JSON payloads (with embedded screenshots, 32 KB tools definitions, and SSE streams) on the hot path without blowing up latency or container memory.
Here is how we engineered the hot path of MarginSwitch ( GitHub ), a self-hosted Go reverse proxy that ties Stripe subscription state to real-time token spend.
1. Why json.Unmarshal Fails on the LLM Proxy Hot Path
A naive proxy unmarshals every incoming request body into map[string]any to extract the model, customer ID, and recent messages.…