An AI gateway was supposed to lock each API key to a set of models. It turns out one guard checks the wrong place, so a key limited to a cheap model can quietly reach an expensive one. Here is what broke, how serious it is, and how it connects to a second fix that is already open.
If you have never run an AI gateway, here is the whole world in one picture. A company puts a gateway (LiteLLM) in front of several AI models. Each user gets an API key, and the operator can scope that key to only certain models, for example "this key may only use the cheap model."
flowchart LR
U["App / user
holds an API key"] --> G{{"Gateway (LiteLLM)
checks the key's allowed models"}}
G -->|allowed| C["Cheap model
$0.0002 / call"]
G -.->|blocked| P["Premium model
$0.20 / call"]
classDef ok fill:#edf6f1,stroke:#1f6f54,color:#16130f;
classDef no fill:#f3efe6,stroke:#b8b0a0,color:#8a8275,stroke-dasharray:4 3;
classDef gw fill:#eef3fb,stroke:#2b5fa8,color:#16130f;
class C ok; class P no; class G gw;
That "allowed models" list is the whole point. Operators rely on it to control cost and access, for example giving a customer a key that can only touch one inexpensive model.
Imagine a nightclub. The bouncer checks the name on your ticket, but the DJ plays whatever name is on your wristband. Put an allowed name on the ticket and a VIP name on the wristband, and you walk in cheap but get the VIP treatment.
flowchart TB
R["Your request"] --> B["Body says:
cheap-model (allowed)"]
R --> Ur["URL says:
premium-model (forbidden)"]
B --> Guard{{"Guard reads the BODY
sees cheap-model -> allow"}}
Ur --> Router{{"Router reads the URL
sees premium-model -> run it"}}
Guard --> OK["Request passes the check"]
Router --> Served["Premium model is served
and billed"]
OK --> Served
classDef bad fill:#fbeeec,stroke:#c0392b,color:#16130f;
classDef g fill:#eef3fb,stroke:#2b5fa8,color:#16130f;
class Served,Ur bad; class Guard,Router g;
403. The bypass needs both: an allowed model in the body to pass the guard, and a forbidden model in the URL for the router to run.
This "URL vs body" split only bites on routes where the handler takes the model from the URL. The gateway already fixed the main chat route the same way (an open community fix, PR #41852). The routes still open are the ones that fix does not list:
On all of these, a key scoped to the cheap model is served the premium model. The /v1/messages route, by contrast, correctly ignores the URL model, so it is not affected.
Honest severity: medium. Here is the balanced view, both the worrying parts and the limits.
$1 budget drained by five premium calls that the key should never have been able to make.200.budget_exceeded after 5 drain a $1 budgetThis gateway is being hardened route-by-route. Two findings tackle the same underlying bug on different routes. They touch one route in common.
Covers /v1/images/generations, /v1/images/edits, the ?model= form and the /openai/deployments/{model}/images/... form. Proven with a real database-backed key and two separate upstreams, so the served model is shown by which upstream actually got the call. Open.
Covers :generateContent and :streamGenerateContent (plus the one shared image route). Adds the billing and budget-drain proof, and a control that applies the upstream fix and shows these routes still bypass. Open.
flowchart TB
RC["Same root cause
guard reads body model · router reads URL model"]
RC --> P76["PR #76 / 098
image routes"]
RC --> P77["PR #77 / 111
Gemini routes"]
P76 --> A["/v1/images/generations ?model="]
P76 --> Bn["/v1/images/edits"]
P76 --> S["/openai/deployments/{model}/images/generations"]
P77 --> S
P77 --> C[":generateContent"]
P77 --> D[":streamGenerateContent"]
class S overlap
classDef overlap fill:#fbe7a6,stroke:#b8791a,color:#16130f,stroke-width:2px;
classDef p fill:#eef3fb,stroke:#2b5fa8,color:#16130f;
class P76,P77 p;
generateContent / streamGenerateContent routes plus the money proof. They share exactly one route, the image-deployment path.
There is also an open fix in the gateway project itself, BerriAI/litellm #41852. It closes this same bug, but only for the chat / completions / embeddings routes. Its route list does not include the Gemini or image routes, which is exactly why those findings are still needed: applying #41852 and re-testing shows the Gemini and image routes still bypass.
flowchart LR
Fix["Upstream fix
PR #41852 (open)"] -->|closes| Chat["chat / completions / embeddings ✓"]
Fix -.->|does NOT touch| Gem["generateContent ✗"]
Fix -.->|does NOT touch| Img["images routes ✗"]
classDef ok fill:#edf6f1,stroke:#1f6f54,color:#16130f;
classDef no fill:#fbeeec,stroke:#c0392b,color:#16130f;
classDef f fill:#eef3fb,stroke:#2b5fa8,color:#16130f;
class Chat ok; class Gem,Img no; class Fix f;