Skip to content

How it works

Last updated: 2026-10-28T13:54:53-03:00 (UTC-3)

What happens to a request, from the moment it arrives until the response goes back to the app. Each stage exists only if its flag is on.

  1. Correlation. The request gets a request_id and a traceparent, or inherits the ones the client sent. Both are carried through to the end.
  2. Authentication. The client’s key is checked by its hash, in PostgreSQL, on every request. A revoked or expired key gets 401; if the database is down, a managed key fails closed. JWTs from an IdP and ephemeral realtime tokens are also accepted.
  3. Authorization. The gateway checks the route scope (route:chat…), the key’s model allowlist, the team policy and the organization ceiling. Anything outside that: 403.
  4. Validation. The body is read with a size limit and a deadline, and the JSON must be unambiguous. The alias must declare the requested capability.
  5. Input guardrails. The team’s policies mask or block sensitive data before anything is sent.
  6. Limits and budget. RPM is checked, and budget and TPM are reserved atomically in PostgreSQL. No balance left: 429.
  7. Cache. With the policy on, a hit in the exact or semantic cache returns the response without calling the provider. Authorization and limits have already been applied before the cache.
  8. Routing. Among the alias’s targets, the gateway chooses by weight, latency, cost, load, tags or the meaning of the question, respecting the circuit breaker and each target’s concurrency ceiling.
  9. Translation and sending. If the provider does not speak the OpenAI format, the protocol adapter translates the request, or refuses with 422 whatever has no equivalent. The provider credential is added here; the client’s key never leaves the gateway.
  10. Fallback. A transport error, 429 or 5xx before the first byte of the response makes the gateway try the next target. Once the response has started, there is no new attempt.
  11. Response. The response comes back in the OpenAI format, streaming when requested. Output guardrails can mask or block non-streaming responses.
  12. Measurement. The gateway records tokens, latency, status and estimated cost, settles the budget reservation, feeds analytics, metrics and traces and, if configured, sends the capture to evals and the record to log destinations. Prompts and responses do not go to logs or telemetry.
Piece Role
Gateway (Go binary) Stateless; several replicas behind a load balancer
PostgreSQL Keys, managed configuration, usage, budgets, audit, evals. It is the system’s only state
Redis or Memcached (optional) Exact cache shared between replicas
OTLP Collector, Prometheus, Grafana (optional) Telemetry outside the request path; the gateway works without them
Console (/ui) and documentation (/docs/) Served by the gateway itself
  • Database down: inference continues with the last configuration snapshot. Managed keys, RPM and budgets fail closed.
  • Provider down: fallback and circuit breaker.
  • Cache down: the gateway continues without a cache.
  • Incident: the emergency stop cuts all inference traffic at once.

Continuity · Incident response.

m7gtwcontact@m7gtw.com