The client gets an API key A key service issues an API key and sets which models it may call and when it expires.
The raw key is shown only once. The server stores only a hash, so a lost key must be reissued.
Send an OpenAI-compatible request The client calls a path such as /v1/chat/completions with the key in an Authorization: Bearer header. vLLM provides an OpenAI-compatible API, so existing client code only needs a new URL and key.
The request passes the load balancer and reaches the API gateway. The model field in the body says which model it is for.
Key idea The key service is not on the request path. If it is briefly down, requests with already issued keys keep working.
The gateway checks the key on every request For each request, the gateway asks the auth service to check the key and forwards only requests that pass. Envoy-based gateways commonly do this with external authorization (ext_authz).
The auth service usually caches the key list, so a revoked key may keep working for up to one cache refresh interval.
Auth is useless if there is a path around the gateway If the model server’s Service is open to anyone inside the cluster, or exposed separately, a client can reach a replica directly without a key.
Use a NetworkPolicy so model Pods only accept traffic from the gateway and routing layer. vLLM’s --api-key option adds a key check on the model server, but only for paths such as /v1, so it does not replace the NetworkPolicy.
Watch out After changing auth settings, check both: a request without a key gets 401, and a direct request to the model Service is blocked.
Apply usage limits per key The gateway applies limits per key, such as requests per minute and tokens per minute. Requests over the limit get 429 Too Many Requests.
Decide whether limits count per key or per key and model. The result differs when one key calls several models.
Routing picks a replica When a model has several replicas, the routing layer picks one. A plain Service spreads connections without knowing how busy each replica is.
Inference-aware routing looks at queued requests and KV cache state. A replica that already computed the same prefix returns the first token sooner. Lesson 10 covers this in detail.
The model server generates the answer vLLM on replica 1 processes the whole input at once (prefill), then produces tokens one by one (decode). A serving layer such as KServe handles deploying and autoscaling these Pods.
With stream: true, each token is sent back right away as server-sent events.
Tokens are counted after the response The response goes back through routing and the gateway to the client. The output token count is only known when generation ends, so the gateway charges usage against the limit afterwards.
A request just under the limit still passes, so actual usage can slightly exceed the limit. Set gateway and load balancer timeouts long enough that long streams are not cut off.
Rejected requests show up in access logs Requests with a bad key (401) or over the limit (429) stop at the gateway and never reach the model server. They appear in the gateway’s access logs and metrics.
Never log the raw key. A key ID or a hash prefix is enough to find who hit the limit.
Entry → key and limit → routing → model server A request passes the load balancer, the API gateway (key and limit), routing (replica choice), and the model server, then returns the same way. The key service only issues keys and is not on this path.
Authenticate at the gateway, and block every path around it with NetworkPolicy.
Summary When responses are slow, separate gateway latency, the replica queue, and time to first token (TTFT). vLLM exports metrics such as vllm:num_requests_waiting and vllm:time_to_first_token_seconds.