I Front 14 LLM Providers With One Gateway - Here's the Health Probe That Keeps It Alive
How to build an endpoint health monitor that catches dead AI endpoints before your users do.
If you run anything serious on LLM APIs, you already know the pain: OpenAI works, a smaller provider dies silently, your app serves errors to users, and nobody notices until a customer complains.
I run a local gateway that fronts 14 AI providers 鈥?OpenAI-compatible endpoints, DeepSeek, GLM, MiniMax, and several others. Every provider has its own context window limits, token limits, and reasoning-effort settings. When one endpoint goes down, my router needs to know immediately, not when the first user hits it.
So I built a health probe. This post is the full design 鈥?you can build it yourself in an afternoon.
What "healthy" actually means
Most people ping the models list endpoint and call it a day. That's not enough. A provider can list models fine and still fail every completion request (quota exhausted, auth revoked, upstream 404s).
A real health check needs three signals per provider:
- Reachability 鈥?does the TCP/TLS handshake complete?
- Auth + quota 鈥?does a real (tiny) completion return 200?
- Latency + success rate 鈥?how fast, and how often does it actually succeed over time?
Signal 2 costs a fraction of a cent per check. Run it every 5 minutes and you're spending maybe $0.02/day per provider to never serve a dead endpoint. Cheap insurance.
The core probe (Python, stdlib + requests only)
The whole thing fits in ~120 lines. Here's the heart of it:
import time, json, statistics from collections import deque class EndpointProbe: def __init__(self, name, base_url, api_key, model, window=50): self.name = name self.base_url = base_url.rstrip("/") self.api_key = api_key self.model = model self.history = deque(maxlen=window) # (ok: bool, latency: float) def check(self, timeout=10): t0 = time.monotonic() ok, status = False, None try: r = requests.post( f"{self.base_url}/chat/completions", headers={"Authorization": f"Bearer {self.api_key}"}, json={"model": self.model, "messages": [{"role": "user", "content": "ping"}], "max_tokens": 1}, timeout=timeout, ) status = r.status_code ok = r.status_code == 200 except requests.RequestException as e: status = str(e)[:80] latency = time.monotonic() - t0 self.history.append((ok, latency)) return {"endpoint": self.name, "ok": ok, "status": status, "latency": latency} def health(self): if not self.history: return {"success_rate": None, "p95_latency": None} oks = [ok for ok, _ in self.history] lats = sorted(l for ok, l in self.history if ok) p95 = lats[int(len(lats) * 0.95) - 1] if lats else None return {"success_rate": sum(oks) / len(oks), "p95_latency": p95} Key design decisions:
-
max_tokens: 1鈥?the cheapest possible real completion. You're testing the full path: auth, routing, inference, response parsing. - Rolling window of 50 checks 鈥?one bad result doesn't flip your router; five in a row does.
- p95 latency, not average 鈥?averages hide tail spikes, and tail spikes are what time out your users.
The two failure modes everyone misses
1. The 404 with an empty body. Some gateways return HTTP 404 with a zero-byte body when you request a model build tag that doesn't exist. If your client sends model: some-model-1017 and the gateway only knows some-model, you get a cryptic empty 404 鈥?not a helpful "model not found" JSON. Your probe should treat any non-200 as a failure and log the status code + first 80 bytes of the body, so you can tell "wrong model id" from "auth dead" from "server on fire".
2. Quota exhaustion masquerading as success. Some providers return 200 with an error object in the JSON body. If you only check status_code == 200, you'll mark a dead provider healthy. Always check the response body has choices before counting it as a win:
ok = r.status_code == 200 and "choices" in r.json() That one line has saved me more debugging time than any other.
The report that actually gets read
Raw check data is noise. What you want is one JSON report per run:
{ "generated_at": "2026-11-29T03:12:00Z", "endpoints": [ {"name": "provider-a", "ok": true, "success_rate": 1.0, "p95_latency": 1.42}, {"name": "provider-b", "ok": false, "success_rate": 0.62, "p95_latency": 8.91, "last_error": "HTTP 429"} ] } Success rate over a window + p95 latency + last error. That's the whole dashboard. Wire it to a cron job every 5 minutes, and if you want alerts, push to a webhook when success_rate < 0.8 for 3 consecutive runs.
Where this fits in a bigger system
The probe is the nervous system. On top of it you can build:
- Model routing 鈥?send easy tasks to fast/cheap models, hard tasks to strong ones, using live health data to skip dead endpoints
- Automatic failover 鈥?retry on 429/5xx against the next healthy provider with exponential backoff
- Run traces 鈥?JSONL logs of every attempt so a failed run can be replayed
I build these three together for clients 鈥?it's the difference between "an API key in a script" and infrastructure that survives a provider outage at 3am.
If you'd rather have this set up for your stack than build it yourself, that's literally what I do: my Fiverr gig builds endpoint health monitoring with success rate and latency tracking for your exact provider list, with the report format you want.
Next post: model routing rules that cut LLM costs 40-60% without dropping quality 鈥?the same system this probe feeds.