Engineering deep-dive

Building a sovereign, self-hosted AI gateway for Indian startups in Rust

As AI adoption accelerates across India's startup ecosystem, engineering teams face a common set of infrastructure bottlenecks: routing traffic across multiple LLM providers, enforcing strict INR budgets per team, governing Model Context Protocol (MCP) tools for AI agents, and redacting sensitive Indian PII (Aadhaar, PAN, UPI IDs) before data leaves the network — all without steep enterprise licensing fees or Python proxies that burn gigabytes of RAM.

By combining Agentgateway (an Apache 2.0-licensed, pure-Rust AI gateway) with Docker Compose and a custom INR pricing catalog, you can deploy a lightweight, single-tenant AI control plane that startups self-host effortlessly.

Pure Rust · ~20–40 MB RAM Apache 2.0 Docker Compose INR metering MCP federation

Why this architecture

Python proxies and enterprise license walls aren't the only option

Traditional Python-based LLM proxies often consume gigabytes of memory under streaming loads and lock multi-tenant budgeting, SSO and RBAC behind commercial licenses. For teams advising or hosting infrastructure for multiple early-stage startups, a different foundation works better:

⚙️

Pure Rust performance (~20–40 MB RAM)

Agentgateway handles streaming LLM tokens, gRPC and MCP tool calls with sub-millisecond overhead. Completely isolated gateway instances per startup fit on a single modest VPS or Kubernetes node.

📄

Permissive open source (Apache 2.0)

Hosted under the Linux Foundation's Agentic AI Foundation, every governance feature — virtual keys, spend limits, MCP federation, PII guardrails — is open source, with zero seat-based royalties or proprietary license walls.

₹

Native INR accounting

Paired with Indian inference suppliers — Sarvam AI, Krutrim, Neysa, or INR-billed AWS/Azure India endpoints — a custom INR model catalog meters every token directly in Rupees, without foreign-exchange drift.

Solution architecture

High-level architecture

One container stack per startup: clients and agents hit a TLS-terminated gateway that meters, masks and routes before anything reaches an upstream provider.

Core pillars

Four design decisions that make it work

1

Single-tenant isolation via Docker Compose

Rather than cramming multiple startups into a shared multi-tenant proxy — with noisy-neighbour risks and cross-tenant data exposure — each startup gets its own lightweight container stack. A single Agentgateway instance idles at roughly 20 MB of RAM, so isolating each startup into its own directory with its own config.yaml and SQLite database keeps operations simple, secure and auditable.

2

Native INR budgeting & GST-aware cost metering

Agentgateway calculates spend by multiplying prompt and completion tokens against a JSON model catalog. Because upstream suppliers bill in INR, we supply a custom catalog-inr.json with exact per-token rupee rates — optionally multiplied by 1.18 so hard budget cutoffs automatically account for 18% GST:

{
  "models": {
    "sarvam-m": {
      "input_cost_per_token": 0.0000177,
      "output_cost_per_token": 0.0000708
    },
    "krutrim-2": {
      "input_cost_per_token": 0.0000236,
      "output_cost_per_token": 0.0000944
    }
  }
}
Note: Agentgateway's config schema labels the budget unit as USD, but supplying INR rates in catalog-inr.json makes an amount: 25000 limit act as a strict ₹25,000 cutoff.
3

India-specific PII masking at the edge

Before any prompt reaches an external inference API, Agentgateway passes the payload through a deterministic regex guardrail pipeline. Alongside standard patterns (emails, credit cards), we enforce custom patterns tailored to Indian compliance workflows such as the DPDP Act:

India-specific PII detection patterns
PatternRegex
Aadhaar numbers\b[2-9]{1}[0-9]{3}\s?[0-9]{4}\s?[0-9]{4}\b
PAN cards\b[A-Z]{5}[0-9]{4}[A-Z]{1}\b
UPI IDs\b[a-zA-Z0-9.\-_]{2,256}@[a-zA-Z]{2,64}\b
Indian mobile numbers\b(?:\+91[\-\s]?)?[6-9]\d{9}\b

Sensitive tokens are masked inline (e.g. [REDACTED_PAN]) prior to upstream dispatch, so raw customer identifiers never leave the startup's boundary. For contextual NLP redaction — person names, street addresses — a self-hosted Microsoft Presidio container can be attached via Agentgateway's external guardrail webhook.

4

Governed MCP tool routing for AI agents

Modern AI agents don't just call chat endpoints — they invoke tools over the Model Context Protocol (MCP). Instead of giving every agent direct credentials to internal databases, Slack or GitHub, Agentgateway federates multiple upstream MCP servers behind a single authenticated endpoint. Admins restrict which virtual keys may discover or execute specific MCP tools, giving engineering teams centralized visibility and kill-switch control over autonomous agents.

Deployment

The reference stack: four files, five minutes

Each startup deployment is packaged into four clean files. The Admin UI (port 15000) is bound strictly to 127.0.0.1, and only the inference/MCP gateway (port 4000) is exposed behind a TLS reverse proxy — a production-hardened AI gateway in under five minutes.

gateway/
├── docker-compose.yml    # gateway + admin UI containers
├── config.yaml           # listeners, virtual keys, guardrails, MCP routes
├── catalog-inr.json      # per-token rupee pricing for budget cutoffs
└── Caddyfile             # TLS termination in front of :4000
:4000

Inference & MCP gateway

The only port exposed. Terminated by Caddy or Nginx with TLS, reachable by the startup's apps and agents.

:15000

Admin UI

Gateway configuration, virtual keys, INR budgets and spend dashboards. Bound strictly to 127.0.0.1 — administration never touches the public interface.

Key takeaways

What engineering teams get

🔓

Zero vendor lock-in

Startups own their configs, SQLite spend history and routing logic — all under Apache 2.0. No export clauses, no data hostages.

📊

Predictable cloud bills

Hard rolling 30-day INR limits prevent runaway agent loops from exhausting a startup's monthly cloud credits.

🔀

Future-proof routing

Switching between Indian inference providers or local vLLM deployments means changing a single backend target in config.yaml — with zero code changes in client applications.

Want this stack running in your own VPC?

We deploy, tune and operate this architecture for pilot customers — live in one week, with your keys, your budgets and your data.