Gateway Cache Bug Served One Model's Answer to Another Until Model Was Added to Key

A developer built a lightweight LLM gateway with per-key rate limiting, response caching, provider fallback, and cost tracking, using Python, FastAPI, and pytest. An early version keyed its cache only on messages and temperature, so different models given identical prompts could silently return each other's cached responses without any error being raised. Model-specific tests exposed the flaw, which was fixed by including the model name in the hashed cache payload. The rate limiter's check-and-consume step runs under a single lock, and a 50-thread test against a 10-token bucket confirmed exactly 10 requests were admitted each run. The project's 21 tests run identically in local development and CI, and the code is available on GitHub.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in