Repo: github.com/bhavishyajain545/gcp-ai-llm-router · rebuild: REBUILD.md · project 1: MCP gateway with identity
auto vs all pinned to 3.8 Flash| step | what happens | where |
|---|---|---|
| identity | Keycloak JWT (audience agentgateway, the same token the MCP gateway accepts); anonymous → 401 | llm.policies.jwtAuth |
| guards · request | two deployments chained by agentgateway: presidio-guard masks PERSON, e-mail, phone, PAN, Aadhaar, cards and counts them; nemo-guard runs NeMo's self-check-input rail (Gemini Flash-Lite as judge, called through the egress) and blocks jailbreaks, credential theft, harm → 400 with a guardrail error. The user's subject travels with each webhook call | guards/presidio, guards/nemo |
| budget | a token bucket per jwt.sub: 50k tokens an hour, prompt and completion → 429 beyond | localRateLimit type: tokens |
| routing | vLLM Semantic Router: domain classifier (MMLU categories) + keyword signals → decisions by priority → x-vsr-selected-decision/-model; cloud tiers only, every tier an alias for the egress | vsr/config.yaml.tpl |
| egress | agentgateway routing-form ai backend with no model set: the chosen Gemini id passes through to Vertex AI under Workload Identity; tokens and cost in the access log | routes[].backends[].ai.provider.vertex |
| ledger | the access log leaves agentgateway over OTLP → OpenTelemetry collector → ledger service → Postgres llm_access; the guards post guard_events; ledger.jainosoft.com shows users × tiers, tokens, dollars, blocks, budget hits; a log sink keeps the long tail in BigQuery | ledger/app.py |
| guards · response | presidio-guard masks what the model produced; nemo-guard's self-check-output rail can withhold it | /response on both |
| the app | ops-chat: OIDC sign-in; conversations in Postgres; MCP servers registered per user (the platform gateway built in under the user's token, more can be added and toggled); models discovered from the door; a live step stream per turn (SSE) with an inspector for guards, routing, cost, latency and the tool trail; the model gets the tools as functions and they run through the MCP gateway under the user's identity (role filter, approvals, ledger of project 1 unchanged). React 19 + TypeScript + Tailwind 4 front end, FastAPI back end | chat/app.py, chat/web/ |
TOKEN=$(python drills/llmctl.py token --as bob)
curl https://llm.jainosoft.com/v1/chat/completions -H "Authorization: Bearer $TOKEN" -H 'content-type: application/json' \
-d '{"model":"auto","messages":[{"role":"user","content":"Prove binary search is O(log n)"}]}' # → gemini-3.8-flash
python drills/llmctl.py route --as bob # 12 prompts → tiers, tokens, cost
python drills/llmctl.py guard --as bob # PII masked · jailbreak 400 · normal passes
model needs agentgateway's simplified llm mode; passing an arbitrary model id through to Vertex needs the routing-form ai backend without a model. Both run in one process on two ports.role and content only, so tool-calling turns are passed or rejected, never rewritten; the app previews the guard's verdict with /check instead.