
We've been building AiKey, an LLM API gateway focused on cost governance. In the process, we've talked to a lot of teams running LLMs in production. After a while, the same patterns kept surfacing. Here are the three that came up most — and what we built to handle them.
The scenario: a team has multiple model providers — say OpenAI, Anthropic, and Gemini. Each formats their billing differently. One breaks down by token type, another by model, a third mixes both. The finance team asks for a breakdown by project, and engineering can't provide one. Not because they're not trying — because the data doesn't exist in a mergeable form.
This is where every cost conversation has to start. Not with "how do we optimize" — with "can we even see where the money goes?"
The approach we landed on: attribution metadata at the proxy layer. Every API call gets tagged — project, environment, team, purpose — before it reaches the provider. The proxy runs as a sidecar, so zero application code changes. The tagged data feeds into whatever observability stack you already have.
The non-obvious lesson: pick your attribution taxonomy carefully. We started with just project_id and immediately regretted it — test environment and production calls became indistinguishable in the data. "Project + environment" turned out to be the right starting point. Over-engineering the labels upfront slows adoption to a crawl.
Once attribution is in place, common surprises surface fast: idle subscriptions that have been auto-renewing for months, CI pipelines running model inference with no one aware, entire environments burning budget under the radar.
You can't optimize what you can't see.
Most teams hand out API keys like prepaid debit cards with no balance check. When the team is five people, nothing bad happens. At ten, the cracks show. At twenty — with agents and MCP tools firing calls nobody is monitoring — it's only a matter of time before something goes wrong.
We've seen the same failure mode multiple times: a test script with a bug starts looping overnight, no alerting or circuit breaker in place, and by the time someone notices the next morning the damage is done.
The defense should be at the request level, not the billing level. We think about it in four layers:
Identity and permissions. Not everyone needs access to flagship models. Issue scoped credentials. Reject unauthorized requests before they leave your network.
Budgets and quotas. Three-tier: which models this key can access, max tokens per call, daily/monthly hard cap. Stack them for fine-grained control.
Threshold alerting and blocking. Set a budget red line per team. At 90%, fire an alert. In sensitive environments, configure hard blocks — no exceptions.
Anomaly detection and circuit breaking. Sudden usage spikes, failure rate jumps, consumption curves going vertical — these should trigger automatic circuit breaks, not manual patrol.
Implementation detail: cache policy configs locally with periodic refresh. Minimal latency overhead means developers don't notice the guardrails are there — until they try to do something they shouldn't.
After you can see where money goes and you've stopped the obvious leaks, the real optimization starts.
A recurring pattern: teams routing everything through their flagship model. Code reviews, format conversion, basic Q&A, "summarize this paragraph" — all hitting the most expensive endpoint. The reason is almost never technical. It's that switching models means changing config across multiple repos and CI pipelines, so nobody bothers.
The engineering answer is to make model routing a property of the proxy, not the application code:
Smart routing. Classify task complexity at the proxy. Simple tasks (format conversion, summarization, basic Q&A) go to lightweight models. Heavy reasoning and long-form writing hit the flagship. Set a quality floor — if a lightweight model's output degrades, auto-fallback. No application changes needed.
Data-driven A/B selection. "Is this model good?" shouldn't be answered by reputation. Run two models side by side on your actual workload for a week. Your own production data beats any public benchmark.
Dynamic pool allocation. When multiple provider accounts are unified under one management layer, you can prioritize: high-value workloads get flagship quota, low-priority tasks use lightweight models. During peak, automatically downgrade non-critical traffic. If a provider has issues, one-click removal.
Downgrade detection. When calling models through third-party channels, the actual model serving your request may not match what was advertised. You're billed for the flagship tier, getting responses from a downgraded version. Validate the response model identifier in real-time — if it doesn't match, alert or switch. This plugs a hidden leak most teams aren't checking for.
The biggest mistake we see: teams jumping to optimization before they have visibility. "Let's use a cheaper model" is a guess if you don't know where the money is going.
The order matters — and it's non-negotiable. Visibility first. Guardrails second. Optimization last. Only then are you working with data instead of guesswork.
If we were starting over, we'd tell every team: ship a bare-minimum visibility layer before anything else. Even just project_id tags feeding into a dashboard. That alone surfaces things you'd never notice otherwise.
AiKey is a local proxy-based LLM API gateway focused on cost governance — attribution, guardrails, routing, and downgrade detection in one sidecar. Your data never leaves your machine.
If you're dealing with opaque LLM bills, we'd love to hear how you're handling it.
aikeylabs.com | Enterprise: aikeyfounder@gmail.com