What I Learned Building a FinOps Control Plane for an AI Gateway
Hybrid RAG, cost routing, LangSmith traces, and Grafana metrics on a local AI gateway lab. Most teams add a chatbot and discover two problems later: token spend has no owner, and retrieval changes are impossible to compare. I built FinOps AI Gateway as a learning lab to tackle both. It is not a production deployment at Careem. It is a demo with real instrumentation: hybrid RAG, tiered model routing, LangSmith traces, and Grafana dashboards. Shipping RAG in production usually fails quietly: I wanted a gateway that treats those as engineering problems, not product guesses. One query flows through: Stack: Python, PostgreSQL/pgvector, Prometheus, Pushgateway, Grafana, LangSmith, Docker Compose. Retrieval is fast. Local generation is slow and free. That tradeoff is visible in the Grafana Latency Breakdown p50 panel. Demo mode uses Groq + Ollama ($0 actual spend). Grafana applies Claude list rates × tokens for medium/complex tiers as a counterfactual model. Label simulated numbers clearly. Do not present them as production FinOps proof. Eight Q&A pairs is enough to compare pipelines directionally. It is not statistically powered for strong faithfulness claims. Lead metric: context_precision +0.19 on the pilot set. Do not over-claim faithfulness at n=8. Grafana: http://localhost:3001 → dashboard FinOps AI Gateway. Muhammad Ahmed · Backend engineer @ Careem · GitHub · LinkedIn The problem I wanted to explore
What the gateway does
Measured results (from committed benchmarks)
Routing (load test, n=12)
Tier Share Simple (local Ollama) 7/12 (58%) Medium 3/12 Complex 2/12 Latency
Component p50 (approx.) End-to-end ~276s (concurrency=2, local Ollama) Retrieval ~2.3s Generation (simple tier) ~356s (local Ollama dominates wall time) Generation (medium/complex) ~1–4s (Groq in demo mode) Cost (simulated FinOps model, not actual API spend)
Metric Value Simulated spend (tier routing) $0.0143 (12 queries) Simulated all-complex counterfactual $0.0609 Modeled savings vs counterfactual ~77% (simulation only) Actual API spend (demo mode) $0 RAG eval (RAGAS pilot, n=8)
Metric Baseline (cosine) Hybrid+rerank Delta context_precision 0.6042 0.7917 +0.1875 faithfulness 0.7690 1.0000 +0.2310 (noisy at n=8) answer_relevancy 0.7716 0.7947 +0.0231 What I would do differently for production
What this lab is good for
What it is not
Try it locally
git clone https://github.com/muhammadahmed-01/FinOps-AI-Gateway
copy .env.example .env # GROQ_API_KEY + LANGCHAIN_API_KEY
.\scripts\bootstrap_demo.ps1