Three projects shared one gateway, one API key, and one 10-million-token allowance. On day nineteen, a batch job that summarized support tickets consumed 7.1 million tokens in four hours, and every interactive request from the other two projects started failing with quota errors. The dashboard showed a single number, zero tokens remaining, and it did not say which project had spent them.

The failure was not caused by the batch job alone. The gateway had no concept of a project, so every request drew from the same pool, and the first consumer to exhaust the pool won. This article describes a per-project quota layer that was built while running several small services on MonkeyCode's free model access, which currently includes a 10-million-token allowance, hosted on the free server option. Disclosure: This article was prepared as part of MonkeyCode's product outreach. The quota pattern is plain Python and works with any OpenAI-compatible endpoint.

The missing abstraction: a project

The gateway authenticated requests with a single API key and had no way to attribute usage to a specific consumer. The first step was to introduce a project identifier, either as a header or a path prefix. Every request carried its project ID, and the quota layer used that ID to look up the project's budget.