LLM egress router with guardrailsone door for every model call · intent routing across Gemini tiers · Presidio + NeMo on both sides · the app that uses it together with the MCP gateway

agentgateway front + egressvLLM Semantic Router v0.4Vertex AI Gemini 3.5 Flash-Lite / 3.5 Flash / 3.8 Flashpresidio-guardnemo-guardKeycloakPostgres ledger (OTLP) + BigQueryMCP tools from project 1

Repo: github.com/bhavishyajain545/gcp-ai-llm-router · rebuild: REBUILD.md · project 1: MCP gateway with identity

Demo (narrated)

Measured on the recorded run

11 / 12
of 12 prompts (simple / general / coding / reasoning) sent to the intended tier by the semantic router
$0.00377 vs $0.00430
list-price cost of the 12 prompts via auto vs all pinned to 3.8 Flash
400 in 1988 ms
personal values masked before the model in the recorded calls; the jailbreak was refused with 400
≈ 0.7 s
what the door adds to a call (JWT + guard judge + routing decision), median
2
tool calls ops-chat made through the MCP gateway under the user's identity in the recorded conversation
19
calls until a user's 50k-token hourly budget answered 429

How it works

stepwhat happenswhere
identityKeycloak JWT (audience agentgateway, the same token the MCP gateway accepts); anonymous → 401llm.policies.jwtAuth
guards · requesttwo 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 callguards/presidio, guards/nemo
budgeta token bucket per jwt.sub: 50k tokens an hour, prompt and completion → 429 beyondlocalRateLimit type: tokens
routingvLLM 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 egressvsr/config.yaml.tpl
egressagentgateway 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 logroutes[].backends[].ai.provider.vertex
ledgerthe 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 BigQueryledger/app.py
guards · responsepresidio-guard masks what the model produced; nemo-guard's self-check-output rail can withhold it/response on both
the appops-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 endchat/app.py, chat/web/

Use it

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

What I learned

Part of the GCP AI-platform series by Bhavishya Jain · portfolio.futurnex.io · cloud models only, no GPU anywhere · ledger in Postgres and BigQuery.