r/devops • • 4d 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?

11 Upvotes

27 comments sorted by

4

u/TellersTech DevOps Speaker & Advisor + DevOps Podcaster 4d 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 4d 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?

3

u/happysmileygogetter 4d 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 4d 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.

1

u/happysmileygogetter 3d ago

Yeah exactly, a cheap run that passes validation but extracts the wrong stuff is just a hidden cost. Worth spot-checking a sample by hand before trusting the numbers.

5

u/mralex215 4d ago

middlemen only increase costs.

4

u/_bloed_ 4d 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.

-6

u/mralex215 4d 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.

3

u/deimos 4d ago

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 ).

This level of delusion invalidates any other opinion you voice.

1

u/Low-Opening25 3d ago

looks like it’s AI now producing code that is producing revenue rather than Devs, while maintaining Production systems and Security of those products still needs DevOps, a DevOps can write code with AI the same as any Dev, so tables are basically turning where DevOps type resources, especially with Dev experience, become much more value for money than code writing monkeys

1

u/Valuable_Leave_7314 3d ago

This take has the same problem as the original rant about "Devs create revenue" - writing syntax was never the main job of a strong dev. The value isn't in banging out classes to spec it's in understanding the domain logic the contracts between services and what your architecture choices do to you six months later. If whoever - a devops guy a junior anyone - dumps AI generated code without understanding the domain then in a couple months that same prod falls apart from hidden bugs in the business logic and the whole team has to fix it

1

u/Low-Opening25 3d ago

I agree that “writing code was never main job of strong dev”, however the reality of the industry is that there is 1 strong dev and he works with 10 mediocre ones that only dish out code without care or ability to grasp big picture. DevOps not being an entry-level job and there being many less around has fewer problems with this arrangement. I could replace most devs with AI in the majority of projects I worked on, and no one would notice any difference.

1

u/Sparcrypt 4d ago

Someone hasn’t tried to manage developers directly…

-1

u/mralex215 4d ago

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

6

u/Sparcrypt 4d 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.

0

u/mralex215 3d ago

Yes, that's what happens in the orgs that are driven by engineering. I know. It is outside the comprehension of the crowd here.

2

u/Sparcrypt 3d ago

Hahahahaha.

Oh nevermind, I have you pegged now. Met so many like you.

All the best.

2

u/Dobsen_Runjie 4d 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 4d 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.

2

u/JustXanderOne 4d 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/Valuable_Leave_7314 3d ago

We also hit a non obvious thing with a similar execution_id - it helps to separately log the share of requests that went through on the first try with no retries. Sometimes the average cost per valid response looks fine but inside it one specific doc type keeps hitting the fallback - easier to just send that one straight to the big model and skip the router

1

u/Neat_Basket8230 4d 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.

1

u/Valuable_Leave_7314 3d ago

Kinda weird to see "Ramp Router" mentioned here but if we're being practical - before buying any router it's easier to hack together a simple config with a fallback and run 5-10% of real prod traffic through it for a week and look at the actual bill instead of synthetic stuff

1

u/Muted_Jellyfish_6784 2d ago

Measure cost per successful output, not cost per request. Log every attempt with the request ID, model, tokens, validation result, and whether it escalated, then divide total spend by outputs that passed schema validation. Compare against a week of sending everything to the expensive model. Track latency too, since retries can cost more there than in dollars.
The habit that matters is keeping the whole retry chain under one request ID. I use a decision intelligence tool to join routing logs, validation failures, and the downstream records the pipeline produced, so you see the true cost of a usable result rather than the cheap first attempt