The problem

The client is a well-funded AI-native startup whose product ships several LLM-powered features. Its monthly model API bill had grown fourfold over two quarters without anything like matching growth in users, which is why they brought us in. Nobody on the small engineering team could see where the spend was going (which features, model tiers, or code paths were driving it), because there was no centralized cost monitoring, just a single combined monthly invoice.

There was a reliability gap too. When a model provider had a brief outage or degraded performance, the team found out from user complaints rather than their own monitoring, because nothing tracked latency or error rates for the AI-dependent features separately from general application monitoring.

Why we started with an audit, not a rebuild

The instinct with a cost problem is often to jump to optimization: smaller models, aggressive caching, rate limiting. We insisted on a two-week audit first, instrumenting cost and usage tracking across every AI-dependent code path before changing anything. Optimizing without knowing where the cost is concentrated risks solving the wrong problem well.

Architecture

Cost attribution by feature and code path

We added structured logging at every model API call in the codebase, tagging each call with the feature, user tier, and code path responsible, and fed it into a cost dashboard broken down by those dimensions. This was the single highest-value piece of the engagement: it took about a week to instrument and immediately exposed three cost leaks that had been invisible in the combined invoice.

What the audit found

Infrastructure-as-code for reproducible environments

Beyond the immediate cost fixes, we moved the client's model configuration (model versions, rate limits, fallback behavior per feature) into version-controlled infrastructure-as-code, replacing manual changes made directly in a provider dashboard with no change history or easy rollback.

Latency and drift monitoring with alerting

We built dedicated monitoring for AI-specific reliability signals (latency percentiles per feature, error rates by provider, and a basic drift check comparing recent output characteristics against a baseline), with alerts routed to the team's existing on-call system. A model provider issue now surfaces as an alert within minutes rather than a support ticket hours later.

A design decision worth calling out
We recommended against migrating the simple classification step to a self-hosted model, which the team had been considering as a further cost optimization. The engineering time to build and maintain self-hosted inference wasn't justified by the extra savings over the smaller managed model we'd already moved it to. The math didn't support it at their scale, and we said so rather than pursuing a more impressive-sounding infrastructure project.

Challenges and tradeoffs

Results

AI infrastructure spend dropped 38% within six weeks of the audit starting, mainly from fixing the retry-loop bug and right-sizing the classification model, with caching adding a smaller but meaningful reduction. Detection of AI-feature incidents became 4.6 times faster, comparing time to first alert before and after the new monitoring (based on two incidents in each period, so a small sample).

The cost-attribution dashboard has become a standing tool the team checks weekly, not a one-time audit artifact. It caught a new anomaly on its own within a month of the engagement ending, which the client's engineering lead cited as proof that the instrumentation was the most durable part of the work.

What we'd do differently

We'd push for the shared model-call wrapper as a first step rather than a byproduct of instrumentation work. Introducing it earlier would have made cost-attribution tagging faster to add and surfaced the retry-loop bug's severity sooner, because every call would have been visible in one consistent place from day one rather than scattered across ad hoc call sites.