Floryne Pierson
← All posts

Cost-aware LLM engineering: why I didn't optimize what everyone told me to

When gross margins are very high, optimizing AI cost per reading saves a few cents a sale. Here's what I actually measured, and what I changed instead.

The standard advice for LLM-powered products is: use the cheapest model that gets the job done, cache aggressively, shorten your prompts. It's good advice in the abstract. The problem is that "cheapest model that gets the job done" only makes sense if you first know how much the current model is actually costing you — per request, per sale, per month.

When I ran those numbers for Magical Chart, the results made some common optimizations obviously worth doing and others obviously pointless. The difference was measurement.

The model tiering decision

The product has two tiers of AI-generated content:

The tiering was set early based on testing both models on each task and observing where quality degraded, not on a blind cost decision.

Haiku on a short conversational reading: indistinguishable from Sonnet in feel. Haiku on a 3,000-token structured natal report: noticeably thinner, section transitions rougher, less specific to the user's data. The tier split was real.

The latency myth I almost acted on

At one point, I had documentation claiming that Sonnet would need "approximately 76 seconds" to complete a deep report — and that this exceeded the 60-second serverless function timeout. This was the stated reason for keeping everything that could tolerate it on Haiku.

When I queried the actual production logs, the claim was wrong. Sonnet was completing deep reports in well under 60 seconds in production. It had been doing so for weeks. The "76 second" figure came from a napkin estimate, not measurement.

The trap: a plausible-sounding technical constraint that nobody verified against production data. It was shaping architecture decisions for a constraint that didn't exist.

This matters because it had a downstream effect: when evaluating whether to run certain report types on Haiku to cut costs, the latency constraint was being cited as the reason Sonnet was necessary. Remove the false constraint, and the actual decision becomes: is Haiku's output quality good enough for this product? That's a quality question, answerable by testing. The latency framing had made it look like a technical constraint with no room to explore.

What the actual margin numbers showed

Gross margin on paid products, after AI cost, is well above 98% across all product tiers. At those numbers, the saving from downgrading a report to a cheaper model is a few cents per sale.

To put that in perspective: at early-stage sales volumes, the total potential savings from a model switch would be measured in cents. The engineering time to make the switch, test for quality regression, and monitor for user complaints costs orders of magnitude more in time value.

ProductAI cost (est.)Gross margin
Daily reading (smaller model)fraction of a centvery high
Deep report (larger model)a few centsvery high
Premium subscriptioncents per monthvery high

The conclusion wasn't "don't optimize cost." It was: at this scale, the meaningful cost levers aren't per-token model selection — they're volume-level decisions. If I ever reach a point where AI cost is a real line item (thousands of users, millions of tokens/month), the tiering decisions will need revisiting. At current scale, the cost ceiling that actually matters is the monthly cap imposed as a safety rail against runaway usage, not the per-request model choice.

What I did optimize

The useful cost work was elsewhere:

A hard monthly spend cap. An API key with no spending limit on a product with a free tier is a risk vector — not from normal usage, but from abuse (prompt injection attempts, automated scraping that triggers AI calls, bugs in rate limiting). I set a hard cap as an alert threshold. If anything hits that ceiling, something is wrong operationally before it's a cost problem.

Instrumentation before optimization. The LLM monitoring dashboard — tracking model usage, latency, token counts, and cost per endpoint — came before any cost optimization decisions. Without it, the "76 second Sonnet" myth would have lived on indefinitely. With it, I could see that Sonnet was clearing the timeout with margin to spare, that Haiku was handling 90%+ of all calls, and that the actual cost distribution was completely different from what the documentation claimed.

Not caching generation output. An obvious optimization that I deliberately skipped: caching generated readings. Each reading is personalized — different cards drawn, different question asked. Caching wouldn't work without defeating the purpose. The only cacheable layer is the retrieval (card meanings, interpretive frameworks), which is already lightweight. Applying a caching pattern designed for static content to generative output would be optimizing the wrong thing.

The framework

When evaluating whether an LLM cost optimization is worth doing, the question isn't "would this reduce cost?" — it almost always would. The question is: what is the actual cost today, and what fraction of it does this optimization address?

If the answer is "4 cents per sale at current volume," the optimization is worth noting and revisiting at scale, not worth implementing now. If the answer is "30% of monthly infrastructure spend," it's worth doing this week.

Measurement first. Optimization second. In that order.