{"slug": "i-front-14-llm-providers-with-one-gateway-here-s-the-health-probe-that-keeps-it", "title": "I Front 14 LLM Providers With One Gateway - Here's the Health Probe That Keeps It Alive", "summary": "A developer built a health-probe system for a local LLM gateway that fronts 14 AI providers, checking each endpoint with a minimal one-token chat completion every five minutes rather than relying on the models-list endpoint. The probe treats any non-200 response as a failure and verifies the response body contains a choices field, catching providers that return HTTP 200 with an error object when quota is exhausted. The author reports the checks cost roughly $0.02 per day per provider and the implementation fits in about 120 lines of Python.", "body_md": "*How to build an endpoint health monitor that catches dead AI endpoints before your users do.*\n\nIf 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.\n\nI 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.\n\nSo I built a health probe. This post is the full design 鈥?you can build it yourself in an afternoon.\n\nMost 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).\n\nA real health check needs three signals per provider:\n\nSignal 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.\n\nThe whole thing fits in ~120 lines. Here's the heart of it:\n\n``` python\nimport time, json, statistics\nfrom collections import deque\n\nclass EndpointProbe:\n    def __init__(self, name, base_url, api_key, model, window=50):\n        self.name = name\n        self.base_url = base_url.rstrip(\"/\")\n        self.api_key = api_key\n        self.model = model\n        self.history = deque(maxlen=window)  # (ok: bool, latency: float)\n\n    def check(self, timeout=10):\n        t0 = time.monotonic()\n        ok, status = False, None\n        try:\n            r = requests.post(\n                f\"{self.base_url}/chat/completions\",\n                headers={\"Authorization\": f\"Bearer {self.api_key}\"},\n                json={\"model\": self.model,\n                      \"messages\": [{\"role\": \"user\", \"content\": \"ping\"}],\n                      \"max_tokens\": 1},\n                timeout=timeout,\n            )\n            status = r.status_code\n            ok = r.status_code == 200\n        except requests.RequestException as e:\n            status = str(e)[:80]\n        latency = time.monotonic() - t0\n        self.history.append((ok, latency))\n        return {\"endpoint\": self.name, \"ok\": ok, \"status\": status, \"latency\": latency}\n\n    def health(self):\n        if not self.history:\n            return {\"success_rate\": None, \"p95_latency\": None}\n        oks = [ok for ok, _ in self.history]\n        lats = sorted(l for ok, l in self.history if ok)\n        p95 = lats[int(len(lats) * 0.95) - 1] if lats else None\n        return {\"success_rate\": sum(oks) / len(oks), \"p95_latency\": p95}\n```\n\nKey design decisions:\n\n`max_tokens: 1`\n**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\".\n\n**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:\n\n```\nok = r.status_code == 200 and \"choices\" in r.json()\n```\n\nThat one line has saved me more debugging time than any other.\n\nRaw check data is noise. What you want is one JSON report per run:\n\n```\n{\n  \"generated_at\": \"2026-11-29T03:12:00Z\",\n  \"endpoints\": [\n    {\"name\": \"provider-a\", \"ok\": true,  \"success_rate\": 1.0,  \"p95_latency\": 1.42},\n    {\"name\": \"provider-b\", \"ok\": false, \"success_rate\": 0.62, \"p95_latency\": 8.91,\n     \"last_error\": \"HTTP 429\"}\n  ]\n}\n```\n\nSuccess 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.\n\nThe probe is the nervous system. On top of it you can build:\n\nI 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.\n\nIf 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](https://www.fiverr.com/faguo7) for your exact provider list, with the report format you want.\n\n*Next post: model routing rules that cut LLM costs 40-60% without dropping quality 鈥?the same system this probe feeds.*", "url": "https://wpnews.pro/news/i-front-14-llm-providers-with-one-gateway-here-s-the-health-probe-that-keeps-it", "canonical_source": "https://dev.to/1715404020/i-front-14-llm-providers-with-one-gateway-heres-the-health-probe-that-keeps-it-alive-66f", "published_at": "2026-11-29 05:04:26+00:00", "updated_at": "2026-11-29 05:13:08.393245+00:00", "lang": "en", "topics": ["ai-infrastructure", "large-language-models", "mlops", "ai-tools"], "entities": ["OpenAI", "DeepSeek", "GLM", "MiniMax"], "also_reported_by": [], "takeaway": "Probe each LLM endpoint with a max_tokens=1 chat completion and count it healthy only when the status is 200 and the body contains a choices field, since some providers return 200 with an error object when quota is exhausted.", "recommendation": {"advice": "Run a one-token completion probe against every provider endpoint every five minutes and require both a 200 status and a choices field before marking it healthy.", "playbook": "production-ops", "playbook_url": "https://wpnews.pro/playbooks/production-ops"}, "alternates": {"html": "https://wpnews.pro/news/i-front-14-llm-providers-with-one-gateway-here-s-the-health-probe-that-keeps-it", "markdown": "https://wpnews.pro/news/i-front-14-llm-providers-with-one-gateway-here-s-the-health-probe-that-keeps-it.md", "text": "https://wpnews.pro/news/i-front-14-llm-providers-with-one-gateway-here-s-the-health-probe-that-keeps-it.txt", "jsonld": "https://wpnews.pro/news/i-front-14-llm-providers-with-one-gateway-here-s-the-health-probe-that-keeps-it.jsonld"}}