r/devops • • 8h ago

Discussion How do you determine whether your LLM routing layer is reducing costs once retries and failed outputs are factored in?

Routing requests to cheaper models sounds straightforward until you start accounting for what happens when the output isn't usable. Take a data extraction pipeline for example where a smaller model handles most requests fine but occasionally returns malformed JSON or misses required fields (those requests need to be retried and in some cases passed to a more expensive model anyway) which is why this is something I'd want to benchmark with a cost/quality based routing solution like Ramp Router because the initial routing decision might save money while the cumulative cost of getting a usable response tells me something else.

Would it make more sense to measure the cost per successfully validated output against a fixed model baseline rather than looking at average inference cost?

I also wanna understand how people are handling this on the observability side so like are you grouping all inference attempts under a single trace ID and attributing the cumulative cost to the original request? How are you factoring the additional latency into your benchmarks?

7 Upvotes

15 comments sorted by

2

u/TellersTech DevOps Speaker & Advisor + DevOps Podcaster 8h ago

Yeah… I’d look at cost per successful request, including all the retries and fallbacks. I’d keep everything under the same trace ID and compare the total cost, success rate and latency against just using the better model from the start

You might find that the cheaper model isn’t actually saving you much 😅

2

u/impassionedultimatum 8h ago

Grouping everything under the same trace ID makes sense. Would you also include requests that never produce a usable output in the overall cost calculation?

2

u/happysmileygogetter 8h ago

Compare cost per successful request, not cost per call. Log every attempt with a request id that stays the same across retries, then for each request sum the tokens across all attempts, including the ones that came back as malformed JSON and any repair or fallback calls.

Then pin a slice of traffic (even 5-10%) to your single default model as a control and compare total cost per completed request, retry rate, parse failure rate and p95 latency. Routers often look cheaper per call while the cheap model's retries and fallbacks to the big model eat the savings, and you only see it once retries are attributed back to the original request.

If you can, track a quality signal on both arms too (user corrections, downstream validation failures). Otherwise you can save money by quietly getting worse.

2

u/impassionedultimatum 8h ago

The quality signal is a good point especially since passing JSON validation doesn't necessarily mean the extracted information is correct.

That's something I'd wanna account for before drawing any conclusions from the cost comparison.

4

u/mralex215 8h ago

middlemen only increase costs.

2

u/_bloed_ 5h ago

If people think they speak with Opus or Sol, but secretly get GPT Luna and are still happy with the results could actually decrease costs.

I mean most devs just turn everything to max, despite never needing it actually.

GPT Luna is enough for 99% of your work.

1

u/mralex215 5h ago

I find it hilarious when devops decide what developers should or should not do. It is like the return of systadmin BOFH. Remember what happened to those folks ( or in case you dont know - they were all fired and ended up being greeters at Walmart or similar kind of places ).

Devs create revenue.
Devops create costs.

Sane companies never allow those who create revenue to be limited by opinions of those who create costs. Especially if those opinions have not been socialized and agreed to by the revenue generators.

There's one and only one reason to use a routing layer - it is so you avoid tightly integrating with an individual AI provider and thus dumping the flux API contract tracking costs onto someone who promises you to track those contracts at an enormous speed in exchange for skimming on the top. It works for virtually everything except for the code.

1

u/Sparcrypt 3h ago

Someone hasn’t tried to manage developers directly…

1

u/mralex215 1h ago

Had hundreds below me. I can assure you that "this is how it would be done" does not work. Only buy in works.

•

u/Sparcrypt 2m ago

Ah so you individually managed hundreds of people?

You're either lying or were an absolutely awful manager. I've been in this industry for decades and I get so very tired of people who pretend management has no value.

2

u/Dobsen_Runjie 8h ago

cost per valid response is the right way to look at it. One thing to watch out for is that retries also burn through your rate limits faster, which doesnt show up on the billing dashboard but can still bottleneck the pipeline

2

u/FUSe 8h ago

Maybe don’t have your model writing json directly. Make a tool call (local function/template) that generates the json and your model calls that tool with just the inputs.

1

u/JustXanderOne 7h ago

Measuring average cost per inference call is definitely a trap when smaller models trigger retries or produce subtly broken outputs. The metric that worked best for us is **cost per deterministically verified outcome**: grouping all attempts (including fallback escalations to a larger model) under a single `execution_id`, validating the output with a strict schema/linter gate before accepting it, and dividing total token spend across the whole retry chain by the number of outputs that actually passed the gate.

1

u/Neat_Basket8230 1h ago

The rate-limit hit was the one that caught me out — it never showed on the bill, but retries burned through the quota and the pipeline stalled while the cost dashboard looked fine. I ended up tracking cost per validated output, retries included, and the cheap model stopped looking cheap once the fallbacks were counted. Latency went in the same bucket, or the router kept winning on paper and losing in practice.