OpenAI-Compatible Gateway Health Checks: Complete Workload Observations
Define scoped deployment and scheduled health observations, validate complete JSON or parsed SSE text, and distinguish failures with a complete offline Python example.

OpenAI-compatible gateway health checks should answer a concrete question: what outcome did this exact workload produce with this credential, model, method and mode at a recorded time? A reachable base URL, a listed model or HTTP 200 headers alone cannot answer that question.
Use a customer-owned check before deployment or on a bounded schedule when an application needs evidence about a required workload. Keep each result scoped and time-stamped. It can inform your application's release decision; it is not a global health declaration, SLA, promise of future success or authorization to replay a paid operation.
Define the workload before checking it
Record the environment, exact base URL, opaque credential alias and credential revision, exact model ID, method, mode and observation time. A key change invalidates the prior credential revision. Keep the request contract alongside this scope: ordinary text, tools, media and structured results need different validators. Run separate checks for JSON and streaming if the product needs both; success in one mode does not establish the other.
Start with the integration documentation. The current public OpenAPI documents multiple methods, including Responses, image editing, embeddings and audio. This guide's example is deliberately one ordinary-text Chat Completions contract. It is not a validator for every published method, option or model. A general OpenAI-compatible client interface does not make their semantics interchangeable.
Separate published information, same-credential model-list evidence, documented method support and optional paid observation. The public model catalog helps planning; it establishes neither your credential's access nor execution health. The authenticated list provides a different observation, with documented id and capabilities, but no proof of balance, remaining quota, context limits or future call success. Use the catalog selection guide for freshness, exact IDs and approved alternatives.
Decide whether a paid observation is appropriate
An active generation probe may bill and consume capacity, even with a short prompt and small output allowance. Decide its purpose, schedule, spending limit and ownership before enabling it. Use the exact required model rather than a cheaper substitute when the release depends on that model, but avoid probing when passive evidence is enough for the decision. A sample result cannot establish quality across real prompts or sustained workload capacity.
Keep the probe outside request retry loops. Bound overlapping checks and frequency in your application so monitoring does not create extra load during an incident. Define which missing or expired observations block a release and who can approve an exception. Those are application policies, not API429 features. The code below performs no probe and incurs no API usage.
Balance can be checked separately according to the customer documentation. It is commercial state, not proof that a specific request can execute. Do not infer a paid operation was cancelled because the local client stopped waiting.
Require a complete ordinary text result
For this configured JSON workload, completion requires a valid response with one ordinary assistant text choice, nonblank content and finish_reason equal to stop. A 200 response with an error, missing content, truncation or a tool result does not establish this ordinary-text contract. A tool result might be valid for a different application contract; this validator simply has insufficient evidence to accept it here.
For streaming, validate the complete sequence after parsing SSE framing. This example requires nonblank accumulated text, a terminal stop choice and the [DONE] marker, with no extra events after completion. First text is partial evidence. An explicit error event, premature disconnect, missing terminal marker or truncated result cannot pass just because HTTP headers succeeded. The streaming documentation explains that an error can arrive after successful headers.
The module accepts already parsed synthetic SSE objects; it is not a wire parser. Its narrow sequence does not accommodate extra usage-only chunks or every valid optional stream variant. A production client using those variants needs an application adapter and matching acceptance tests. Rejection by this narrow example is not evidence that a native feature is unsupported. Tools, media, Responses and content filtering also need their own documented result handling.
Interpret scenarios separately
Use the matrix to decide what evidence to preserve and what review it needs. It does not automatically authorize another paid call or a different model.
| Observed scenario | Interpretation | Application follow-up |
|---|---|---|
200, complete ordinary JSON text and stop |
Complete result for this scope and time | Record the observation; apply release policy |
200, parsed SSE text, stop, [DONE] |
Complete stream for this configured contract | Record streaming scope separately |
200, partial text, length, explicit error or missing end evidence |
Incomplete ordinary-text result | Preserve partial state; inspect the documented contract |
| 401 | Credential authentication failed for this observation | Check the configured credential safely |
| 403 | Access failed for this observation | Review access and support evidence; do not infer an internal cause |
| 404 | Exact method/model combination was not confirmed | Verify path, exact ID and current documentation |
| 429 | Rate-limit response for this observation | Preserve status and safe Retry-After metadata; consult retry policy |
| 5xx | Server-error response for this observation | Record its scope and time; review the actual outcome |
| Timeout or transport failure | Delivery or completion may be unknown | Reconcile the original operation before any paid replay |
| Wrong scope, expired or malformed observation | Evidence cannot qualify for this check | Obtain appropriate evidence through an authorized workflow |
RFC 6585 section 4 defines 429 without identifying the service's internal cause. Retry-After is optional, and 429 responses must not be cached. The retry budget guide owns delay parsing, deadlines and bounded recovery. A rate-limit response does not authorize failover, and a timeout does not prove cancellation. You must reconcile uncertain delivery or completion before starting another paid operation.
Complete offline observation interpreter
Run this complete standard-library Python module locally to inspect a fictional successful observation and an unknown_outcome. All demo model IDs are fictional. scope, observed_at, status, transport, response and events are synthetic application wrapper fields, not a proposed native API429 response schema. The module loads no key, makes no network call and performs no active probe.
The function compares observation scope with expected scope and checks finite, nonfuture observation times against an application maximum age. Credential errors, unconfirmed method/model, rate limiting, server errors, incomplete results and uncertain transport remain separate states. The response's returned model string is not compared to the requested ID: a response may identify a canonical or versioned alias. Scope records the exact model your application requested.
Download the complete offline health interpreter
"""Offline evidence interpreter for ONE ordinary-text Chat Completions workload.
No probes are sent. Scope, observed_at, status, transport, response and events
are application-captured observation fields, not a proposed API429 response.
Scope endpoint is relative to base_url: /chat/completions. Mode is json or sse.
SSE events below are ALREADY PARSED synthetic data objects plus '[DONE]'; this
is not a wire parser. A production caller must parse framing separately.
A complete verdict is evidence only for this scope at the recorded time, not
an SLA, admission decision, future availability, retry or fallback permission.
Timeout/transport failure may follow a paid operation: unknown outcome does not
authorize replay. max_age grants no HTTP-cache retention/sharing permission.
All demo model IDs are fictional, not API429 availability promises.
"""
import math
from typing import NamedTuple
class Verdict(NamedTuple):
state: str
reason: str
SCOPE_KEYS = ('environment', 'base_url', 'credential_alias', 'credential_revision',
'model', 'endpoint', 'mode')
def _text(value):
return isinstance(value, str) and bool(value.strip())
def _number(value):
try:
return type(value) in (int, float) and math.isfinite(value) and value >= 0
except OverflowError:
return False
def _choice(response):
if not isinstance(response, dict) or 'error' in response:
return None
choices = response.get('choices')
if not isinstance(choices, list) or len(choices) != 1 or not isinstance(choices[0], dict):
return None
choice = choices[0]
index = choice.get('index', 0)
if type(index) is not int or index != 0:
return None
return choice
def _ordinary(payload):
return (isinstance(payload, dict)
and not any(key in payload for key in ('tool_calls', 'function_call', 'refusal')))
def _json_complete(response):
choice = _choice(response)
if choice is None or choice.get('finish_reason') != 'stop':
return False
message = choice.get('message')
return (_ordinary(message) and message.get('role') == 'assistant'
and _text(message.get('content')))
def _sse_complete(events):
if not isinstance(events, list):
return False
text, terminal, done = '', False, False
for event in events:
if done:
return False
if event == '[DONE]':
if not terminal:
return False
done = True
continue
if terminal:
return False
choice = _choice(event)
if choice is None:
return False
delta = choice.get('delta')
if not _ordinary(delta) or delta.get('role', 'assistant') != 'assistant':
return False
content = delta.get('content', '')
if not isinstance(content, str):
return False
text += content
finish = choice.get('finish_reason')
if finish is not None:
if finish != 'stop':
return False
terminal = True
return bool(text.strip()) and terminal and done
def interpret_probe(observation, expected_scope, now, max_age):
"""Classify already-captured evidence, returning only generic safe reasons.
Optional transport='timeout' or 'transport_error' records uncertain delivery
or completion, including failures after headers. This conservative example
has no 'not sent' inference. It never compares response.model to request
scope: a provider may return a canonical/versioned model alias.
"""
if not isinstance(observation, dict):
return Verdict('invalid', 'invalid observation')
scope = observation.get('scope')
for candidate in (scope, expected_scope):
if (not isinstance(candidate, dict) or set(candidate) != set(SCOPE_KEYS)
or any(not _text(candidate[key]) for key in SCOPE_KEYS)):
return Verdict('invalid', 'invalid scope')
if scope != expected_scope:
return Verdict('invalid', 'scope mismatch')
if scope['endpoint'] != '/chat/completions' or scope['mode'] not in ('json', 'sse'):
return Verdict('invalid', 'outside this ordinary-text contract')
observed_at = observation.get('observed_at')
if not all(_number(value) for value in (observed_at, now, max_age)) or max_age <= 0:
return Verdict('invalid', 'invalid observation time')
if now < observed_at or now - observed_at >= max_age:
return Verdict('invalid', 'future or expired observation')
if 'transport' in observation:
if observation['transport'] in ('timeout', 'transport_error'):
return Verdict('unknown_outcome', 'delivery or completion is uncertain')
return Verdict('invalid', 'unknown transport observation')
status = observation.get('status')
if type(status) is not int or not 100 <= status <= 599:
return Verdict('invalid', 'invalid HTTP status')
if status in (401, 403):
return Verdict('access_error', 'access failed for the observed scope')
if status == 404:
return Verdict('method_model_not_confirmed', 'this method/model was not confirmed')
if status == 429:
return Verdict('rate_limited', 'rate-limit response; no internal cause inferred')
if 500 <= status <= 599:
return Verdict('server_error', 'server-error response for the observed scope')
if status != 200:
return Verdict('unknown', 'no complete result established')
complete = (_json_complete(observation.get('response')) if scope['mode'] == 'json'
else _sse_complete(observation.get('events')))
if complete:
return Verdict('complete', 'complete ordinary-text result observed at the recorded time')
return Verdict('incomplete', 'complete ordinary-text result not established')
def main():
scope = dict(environment='demo', base_url='https://example.invalid/v1',
credential_alias='offline-fixture', credential_revision='r1',
model='demo-chat-primary', endpoint='/chat/completions', mode='json')
observation = dict(scope=scope, observed_at=100, status=200, response={'choices': [
{'message': {'role': 'assistant', 'content': 'Synthetic OK'}, 'finish_reason': 'stop'}]})
print('Fictional complete observation:', interpret_probe(observation, scope, 110, 30))
observation['transport'] = 'timeout'
print('Fictional uncertain observation:', interpret_probe(observation, scope, 110, 30))
if __name__ == '__main__':
main()
Store useful evidence safely
Record the observation time, application scope, result state and a safe request identifier when available. Keep raw authorization headers, tokens, sensitive prompts and full response bodies out of monitoring output. Use an opaque credential alias with a revision; a key's last four characters are neither a safe universal identifier nor a unique identity. Keep credentials server-side and follow the bearer-token protections in RFC 6750.
Set an application freshness policy for release decisions, and retain refresh failures as failures rather than relabeling old evidence as current. Local maximum age is not permission to store or share an HTTP response. Honor actual cache directives and RFC 9111 authenticated shared-cache restrictions. Decide separately what operational metadata your privacy policy permits you to retain.
Review an incident using the precise timestamp, method, requested model, mode, safe status and request identifier. Ask support with that context when the evidence is insufficient; do not send credentials. The FAQ provides customer-facing integration and support context. A deployment gate can require fresh complete evidence while leaving an uncertain existing operation attached to its original identity for reconciliation.
FAQ
How often should health checks run?
Choose a bounded schedule based on the workload's release risk and the cost of probing. Before-deployment observations and scheduled observations serve different operational decisions. Neither a recent pass nor a fixed interval guarantees the next request succeeds.
Is HTTP 200 enough for a green result?
No. Validate completion according to the exact contract. This ordinary-text example requires JSON text plus stop, or parsed SSE text plus stop and [DONE]. Other documented workloads require their own validators.
Does a listed model or positive balance establish health?
No. Publication, credential-scoped listing, balance and a complete workload result are separate facts. Keep them separate in dashboards and release decisions so one green indicator does not hide missing evidence elsewhere.
Should a failed check automatically retry or switch models?
A failure classification alone grants neither replay nor substitution permission. Preserve uncertain outcomes and consult the application's approved recovery policy. An alternative must be independently approved and checked for the workload; it is not qualified merely because it answered once.
What does the offline example prove?
It demonstrates deterministic interpretation of synthetic evidence for one configured ordinary-text contract. It establishes no live API429 availability, account access, billing result, uptime or native monitoring capability.
Sources & further reading
- API429 customer documentation
- Current API429 public OpenAPI
- API429 public catalog contract
- API429 English API reference
- RFC 6585 section 4: Too Many Requests
- RFC 9110 section 10.2.3: Retry-After
- RFC 9110 section 9.2.2: Idempotent methods
- RFC 9111 section 3.5: Authenticated responses in shared caches
- RFC 6750 section 5.3: Bearer token protections
- API429 SSE response documentation
- API429 streaming clients
- API429 content filtering
- API429 client balance documentation
Put the next step into practice.
Check model IDs, current pricing and request formats before integrating. Availability can depend on the model and provider route.
