Skip to content

LLM Gateway Overview

Document ID: LLM-001
File Path: docs/05-llm-gateway/overview.md
Version: 1.0.0
Status: Draft
Owner: AI Platform Team
Last Updated: 2026-06-27


This document specifies the LLM Gateway, the deployable service that fronts every AI model provider used by the Wovyr AI Platform.

The Gateway provides a single, governed, provider-neutral endpoint for model inference. It centralizes everything that should not be re-implemented inside each calling service: credentials, routing, failover, caching, rate limiting, token accounting, cost control, and observability.


The LLM Gateway is responsible for:

  • A network API for inference (chat, completion, embeddings, image, moderation)
  • Provider and model selection (routing)
  • Resilience: retries, failover, timeouts, circuit breaking
  • Streaming responses to callers
  • Token accounting and cost attribution
  • Budget and quota enforcement
  • Response caching
  • Centralized credential management
  • Per-request audit and telemetry

The LLM Gateway is not responsible for:

  • Defining provider adapters — see Provider SDK
  • Prompt construction — see Context Manager
  • Deciding what to ask a model — that is the Agent Runtime’s job

Agent Runtime ─┐
Workflow Engine├──► LLM Gateway ──► Provider SDK ──► Provider APIs
Tool Runtime │ │
Dashboard ┘ ├── Cache (Redis)
├── Credential Vault
└── Telemetry → Event Bus / Prometheus

The Gateway is a horizontally scalable, stateless-per-request service. Shared state (cache entries, quota counters, circuit-breaker status) lives in Redis so any instance can serve any request. See C4 Container §4.5.


The Gateway exposes one request schema for all providers. Callers select a capability and optionally a model class; the Gateway resolves the concrete provider and model. Provider-specific payloads never leak to callers.

The Router selects a provider/model based on explicit request, capability match, cost, latency, availability, region, and tenant preference. See Routing.

The Resilience Engine applies timeouts, bounded retries with backoff, failover to alternate providers, and circuit breaking for unhealthy providers. See Resilience & Failover.

Token, tool-call, and progress events are delivered over a single unified streaming protocol independent of provider wire format. See Streaming.

Every request is metered. Prompt, completion, and cached tokens are recorded; cost is computed from the model registry pricing; budgets and quotas are enforced. See Token Management & Cost.

Exact-match and semantic caching reduce cost and latency for repeated or similar requests. See Caching.

Each request carries a tenant, organization, project, and principal. The Gateway authenticates the caller, applies Policy Engine rules, enforces quotas, and writes an audit record.


CapabilityDescription
chatMulti-turn chat completion
completionSingle-prompt text completion
embeddingsVector embeddings
function_callingTool/function calling
structured_outputJSON / JSON-Schema constrained output
visionImage input understanding
image_generationImage output
audioSpeech-to-text / text-to-speech
moderationContent safety classification

Supported providers are defined by the Provider SDK.


1. Receive request (REST / gRPC / WebSocket)
2. Authenticate caller (JWT / mTLS / service token)
3. Resolve tenant + principal
4. Apply policy checks (Policy Engine)
5. Pre-check budget + quota (Token Manager)
6. Cache lookup (exact, then semantic)
├── hit → record usage(cached) → return
└── miss → continue
7. Route (select provider + model)
8. Execute with resilience (retry / failover / circuit breaker)
9. Stream or collect response (Provider SDK → provider API)
10. Meter usage + compute cost
11. Emit cost event + telemetry
12. Store in cache (if cacheable)
13. Return response + usage metadata

ModeDescription
EmbeddedGateway runs in-process within the all-in-one dev binary
SidecarCo-located with the Agent Runtime for low-latency calls
StandaloneDedicated horizontally scaled service (enterprise default)

In all modes the API contract is identical. See Deployment Architecture.


service-llm-gateway/
├── api/ # REST + gRPC + WebSocket handlers
├── router/ # provider & model selection
├── resilience/ # retry, failover, circuit breaker
├── streaming/ # unified streaming engine
├── tokens/ # accounting, budgets, cost
├── cache/ # exact + semantic cache
├── credentials/ # secret references, rotation
├── telemetry/ # logs, metrics, traces, cost events
└── main.rs

The router, resilience, and streaming modules call into the Provider SDK rather than provider APIs directly.


RequirementTarget
Gateway overhead (non-cached)< 8 ms p95
Cache lookup< 3 ms p95
Routing decision< 5 ms p95
Failover decision< 10 ms
Streaming first-token added latency< 15 ms
Availability99.99%
Throughput10k+ concurrent in-flight requests per instance

FailureBehavior
Provider timeoutRetry, then failover to next provider
Provider 5xxRetry with backoff, then failover
Provider rate limit (429)Backoff, optionally reroute
All providers downReturn 503 with retry-after
Budget exceededReject with 402-style budget error
Quota exceededReject with 429 quota error
Cache backend downBypass cache, serve live (degraded)

Details in Resilience & Failover.


  • Provider credentials are stored as secret references and never returned to callers.
  • All caller traffic requires authentication (JWT, service token, or mTLS).
  • Inter-service traffic uses mTLS.
  • Requests and responses may be PII-masked before logging.
  • Every request produces a structured audit record (tenant, principal, model, tokens, cost).

See Policy Engine and the planned 13-security/ section.


Every request emits:

  • Logs — structured, correlation-ID tagged
  • Metrics — latency, tokens, cost, cache hit ratio, failover count, error rate
  • Traces — OpenTelemetry spans across routing, provider call, and streaming
  • Cost events — published to the Event Bus

KPIs are tracked in Success Metrics — LLM Gateway KPIs.




  • Quality-aware routing using live model scoring
  • Multi-model ensemble and speculative routing
  • Prompt registry integration
  • MCP gateway integration
  • Edge / regional inference pools
  • Automatic prompt compression before dispatch

VersionDateDescription
1.0.02026-06-27Initial LLM Gateway Overview