AI platform project 01

One door for every model.

Teams should not each hold their own Bedrock and Azure OpenAI credentials, limits and cost reports. This gateway gives them one endpoint and puts those controls in one place.

BedrockAzure OpenAIAPIMFastAPIPrometheus

The request path

Six stages, each in its own module. Select one to see what it does and why.

Select a stage to see what happens there and which file implements it.

Break the primary and watch it fail over

A browser port of the gateway's router, breaker and team limits. Move the outage, change the breaker, or make the primary refuse prompts instead of failing.

240 requests through the router

Each bar is one request, 0.5 s apart. The shaded window is the primary's outage. The band underneath is the primary's circuit breaker. Click a bar, or use the slider, to inspect a request.

primary outagecircuit: green closed · red open · amber half-opent = 120 s
Bedrock (primary)Azure OpenAI (failover)429 team limit400 content filter503 no target
Served by Bedrock164
Failed over to Azure57
Primary calls while it was down3
Throttled (429)19
Blocked (400)0
Failed (503)0
#62 at t=31.0 s · team search · Azure OpenAI (failover)
primary: 500 → fallback: ok
Breaker after this request: open
What goes wrong on the primary?

Per-team attribution

Every successful request is priced as tokens × that target's price table (illustrative prices, ~30 input and 20 output tokens per request). Failover changes the bill as well as the latency.

search120 ok · 0 × 429 · $0.0098support72 ok · 0 × 429 · $0.0058batch29 ok · 19 × 429 · $0.0024
servedthrottled
Target$ / 1K in$ / 1K out
Bedrock Claude 3.5 Haiku0.00080.004
Azure OpenAI gpt-4o-mini0.000150.0006

Illustrative list prices from the repo config. Check the AWS and Azure pricing pages before using them for real chargeback.

The real run. scripts/simulate.py drives the actual Python gateway (auth, limiter, router, breaker, metrics) with mock providers. Its committed output: 161 requests served by Bedrock and 59 by Azure. Only 3 calls reached Bedrock while it was failing. The batch team had 20 of 48 requests throttled. The lab above is a browser port of the same rules. Its team mix is a fixed pattern rather than seeded random, so counts differ slightly.

Test me

Questions an interviewer could ask about this design, including numbers from the committed run.

LLM gateway8 questions

Concept checks, scenario calls and numbers from the real runs. Answer, then read why. Wrong answers can be retried at the end.

Run it yourself

Free and local: pip install -e ".[dev]" && pytest -q (36 tests), python scripts/simulate.py, and docker compose -f deploy/docker-compose.yml up for Prometheus and Grafana. The Terraform for a Bedrock Guardrail, least-privilege IAM, a Bedrock budget, an Azure OpenAI deployment with a custom content filter, and an optional APIM policy is cost-flagged. It is validated but has not been applied.