Topic 6 of 6 · 5 min read
Monitoring and securing a self-hosted endpoint
Goal: Write a checklist that secures and monitors a self-hosted model endpoint before real users reach it.
A model endpoint is a costly API that answers anyone who can reach it, so authenticate it, limit it, measure it, and roll out changes one replica at a time.
Check yourself · 1 of 3
What is the safest way to place a vLLM server on a company network?
Why it matters
A hosted provider gives you keys, quotas, dashboards and rollbacks. When you self-host, you build each of those. Without them, one leaked URL turns your GPUs into free compute for strangers, and one long prompt or runaway loop can starve everyone else. The OWASP list of LLM risks names unbounded consumption and insecure deployment among them.
Secure it
- Do not expose the engine directly. Put a gateway or reverse proxy in front, with TLS.
- Require keys, one per client or team, so you can revoke one without breaking the rest. The engine's own
--api-keyis a baseline, not a full key system. - Rate-limit and cap sizes: requests per minute per key, maximum input tokens, maximum
max_tokensper request, and a request timeout. - Network: keep the engine on a private network; only the gateway can reach it.
- Logging: log key id, model, token counts and latency. Do not log full prompts unless you have a reason and a retention rule, because prompts often contain personal data.
Monitor it
vLLM exposes Prometheus metrics at /metrics, including the number of waiting requests. Track:
- queue depth (waiting requests) and time in queue;
- time to first token and inter-token latency, as percentiles (p50, p95);
- tokens per second and request errors;
- KV cache usage;
- GPU memory, temperature and errors from the GPU driver.
Alert on queue depth and p95 latency, which users feel, before GPU metrics.
Roll out a new model
Load the new version on one replica, send it a small share of traffic, compare latency, errors and a sample of answers, then continue replica by replica. Keep the old version loadable for a quick rollback.
Before and after
Weak: vllm serve my-model --host 0.0.0.0 on a public IP, no key, no alerts.
Better:
vllm serve my-model --api-key "$VLLM_API_KEY" --max-model-len 16384
# bound to a private address; the gateway enforces per-key limits and TLS
with a dashboard on queue depth and p95 latency and an alert when either crosses its limit.
What goes wrong
- A single shared key in every app, so a leak means rotating everywhere.
- No output cap, so one request asks for a huge answer.
- Watching only GPU use, which looks healthy while users wait.
- Replacing every replica at once with an untested model.
Examples
A pre-launch checklist
security:
- engine reachable only from the gateway subnet
- TLS terminated at the gateway
- one API key per client, revocable
- rate limit 60 requests/min/key
- max input 16000 tokens, max_tokens 2000, timeout 120 s
monitoring:
- scrape /metrics every 15 s
- alert: waiting requests > 10 for 5 min
- alert: p95 time to first token > 3 s
- GPU memory, temperature and driver errors on the dashboard
rollout:
- canary replica takes 5 percent of traffic for 1 hour
- rollback = repoint to previous model tag
A leaked URL
A team opens port 8000 to demo a model to a partner and forgets to close it. Within days the endpoint is busy with traffic nobody recognises, the queue grows, and real users wait. A key requirement, a private network and a per-key rate limit would have made the leak harmless.
Key points
- Keep the engine on a private network behind a gateway with TLS, keys per client, rate limits and request size caps.
- Cap input length,
max_tokensand request time so one request cannot starve others. - Alert on queue depth and p95 latency; GPU metrics explain causes but users feel the queue.
- Do not log full prompts by default; log key id, model, token counts and latency.
- Roll out a new model version on one replica first and keep the old one ready for rollback.
Common mistakes
- Exposing the engine's port directly to the internet.
- Sharing one API key across every application.
- Setting no maximum on input size, output size or request time.
- Monitoring GPU utilization but not queue depth or latency percentiles.
Check yourself · 2 of 3
Users report slow answers, but GPU utilization is 70 percent. Which metric should you check first?
Check yourself · 3 of 3
You have a new fine-tuned model version. What is the best rollout?
Practice items, not counted towards your mastery.
Start here
- vLLM documentation (opens in a new tab)DocsFree
The serve command, engine arguments, metrics and parallelism pages for the most widely used open serving engine.
- SGLang documentation (opens in a new tab)DocsFree
Docs for the SGLang server, with prefix caching (RadixAttention) and multi-GPU launch options.
- Efficient Memory Management for LLM Serving with PagedAttention (opens in a new tab)PaperFree
The vLLM paper: why KV cache fragmentation wastes memory and how paging it raises throughput.
More for this topic
- vLLM production metrics (opens in a new tab)DocsFree
The Prometheus metrics the server exposes, including queue length and latency histograms.
- OWASP Top 10 for LLM Applications (opens in a new tab)StandardFree
The standard risk list for LLM apps, including unbounded consumption and insecure deployment.