LIVE · Thursday 3 December

LLM Router Build vs Buy: Self-Host the Gateway Above About $118K a Month, and Build the Routing Policy Yourself

A router is three things priced differently: gateway plumbing, routing policy and the models behind it. At 40 million requests a month, two ML engineers should rent or adopt the first, build the second and price the third.

By Surya10 min read

For a team with two ML engineers and 40 million requests a month, the LLM router build-vs-buy answer splits in two. Do not build the gateway: open-source LiteLLM handles far more traffic than you have, and a 5.5% fee gateway such as OpenRouter costs more than self-hosting once LLM spend passes about $118,000 a month, or about $0.003 per request at your volume. Do build the routing policy, starting with rules and moving to a learned RouteLLM-style router only if your own eval set shows savings left on the table. And if most of your spend is one repeated task, price specialising a model on your logs before you spend months routing between rented ones.

A router is three jobs, not one

"Build or buy a router" bundles three decisions that have different costs and different owners.

The first is the gateway: one API in front of every provider, with retries, fallbacks, rate limits, key management, logging and caching. It is generic plumbing, and it is the part vendors sell.

The second is the routing policy: the logic that decides which model each request goes to. This is where savings come from, and it depends entirely on what your traffic looks like.

The third is the model layer: the models the policy chooses between. Routing only moves traffic among models you rent. Replacing the model that carries most of your traffic is a different lever, and often a larger one.

Each layer has its own build-or-buy answer, and confusing them is how small teams end up maintaining an HTTP proxy instead of improving their product.

Why performance is not a reason to build the gateway

Forty million requests over a 30-day month is about 15 requests per second on average. Assuming peaks run three to six and a half times the average, that is 46 to 100 requests per second at the busiest moments. At 100 million requests a month the average is still under 40.

LiteLLM's own benchmark page reports 1,170 requests per second on four instances of 4 vCPU and 8 GB each, with gateway overhead of 2 milliseconds at the median and 8 at the 95th percentile. Two instances managed 1,035.7 requests per second. Those tests ran against a mock OpenAI endpoint, so they measure only the proxy's own overhead, and they are the vendor's numbers. Even with a wide margin for error, your peak is a tenth of what two small instances handled. LiteLLM's production guide says the extra Redis buffer for spend writes only becomes necessary at roughly 1,000 requests per second or more.

What a self-hosted gateway does require is operations. LiteLLM's gateway overview lists Docker, Helm or Terraform for deployment, a Postgres database, and Redis in production. In return you get virtual keys per team with budgets and rate limits, fallbacks and retries across deployments, and logging to tools such as Datadog, Prometheus or OpenTelemetry. The code is MIT-licensed, except for an enterprise directory that carries its own licence.

When a fee gateway costs more than running your own

Managed gateways mostly charge a percentage of spend rather than a per-request price. OpenRouter's documentation says it adds "no markup on inference pricing" but charges 5.5% when you buy credits by card. If you bring your own provider keys, it charges 5% of list-price usage above a $25,000 monthly allowance on pay-as-you-go. Cloudflare's AI Gateway pricing page says its core features are free on all plans, and its Unified Billing option adds a 5% fee to credit purchases.

Self-hosting is not free either. The cost is engineer time. This model assumes a fully loaded engineer costs $20,000 a month, about 1.76 times the $135,980 median software developer salary the Bureau of Labor Statistics reported for May 2025, to cover benefits, payroll tax and seniority. It assumes running the gateway takes 0.3 of an engineer, or $6,000 a month, plus a $500 placeholder for servers, Postgres and Redis. That is $6,500 a month. All three numbers are assumptions; substitute your own.

The table shows what a 5.5% credit fee comes to at each volume and average spend per request. Cells above $6,500 are where self-hosting wins on these assumptions.

Requests/month $0.001 per request $0.003 per request $0.01 per request
10M $10K spend, $550 fee $30K spend, $1,650 fee $100K spend, $5,500 fee
40M $40K spend, $2,200 fee $120K spend, $6,600 fee $400K spend, $22,000 fee
100M $100K spend, $5,500 fee $300K spend, $16,500 fee $1M spend, $55,000 fee

The break-even sits at $118,182 of monthly spend for the 5.5% credit fee. With your own keys and the $25,000 allowance, the 5% fee crosses $6,500 at $155,000 of spend. At 40 million requests, that means about $0.00295 per request on credits and $0.0039 on your own keys. The answer is sensitive to the ops estimate: at 0.1 of an engineer, the credit-fee break-even falls to about $45,000 a month; at half an engineer, it rises to about $191,000.

Run the numbers for the team in question at $0.003 a request, or $120,000 a month of spend. On credits, the 5.5% fee is $6,600 a month, or $79,200 in year one. With your own keys, the 5% fee on usage above the $25,000 allowance is $4,750 a month, or $57,000. Self-hosting is $6,500 a month, or $78,000, plus 1 to 2 engineer-weeks to set up, for $82,600 to $87,200. At this spend the three are close, and bringing your own keys to a fee gateway is cheapest. At $0.01 a request the gap opens: $264,000 a year in credit fees and $225,000 on your own keys, against the same $82,600 to $87,200 for self-hosting.

If you buy, note one catch in OpenRouter's bring-your-own-key docs: by default, when all your keys hit a rate limit or fail, it falls back to its shared endpoints and spends your credits, unless you change a per-key setting.

For the team in question, then, the gateway decision turns on one number they already know: average spend per request. A team calling frontier models with long prompts is probably past the line. A team mostly calling small models is not, and a managed gateway's fee is cheaper than the hours.

The routing policy is where two ML engineers earn their keep

The research behind learned routing is real, but it is narrower than its headline. The RouteLLM paper from LMSYS and UC Berkeley reported cost reductions of over 85% on MT Bench, 45% on MMLU and 35% on GSM8K against sending everything to GPT-4, while keeping 95% of GPT-4's performance. Two caveats in the same work decide how a small team should use it.

First, cost in the paper is the share of requests sent to the strong model, not dollars. The weak model, Mixtral 8x7B, was treated as nearly free. Your saving depends on the price gap between your own model pair.

Second, routers did not transfer on their own. The LMSYS post says that on MMLU "all routers perform poorly at a near-random level when trained only on the Arena dataset," because most MMLU questions were out of distribution. The gains came after the authors added about 1,500 golden-label MMLU questions and about 120,000 samples labelled by a GPT-4 judge, which cost about $700. The RouteLLM repository, released under Apache 2.0, makes the same point in practical terms: calibrate the threshold "on a dataset that closely resembles the types of queries you receive."

That is the case for owning this layer. An off-the-shelf router trained on someone else's traffic is close to a coin flip on yours. A router trained on your own logged traffic is not, and 40 million requests a month produces that training data quickly.

The paper also settles the cost of running a learned router. Its matrix-factorisation router served 155 requests per second on a single GPU virtual machine with an NVIDIA L4 at $0.80 an hour, or $3.32 per million requests. Run around the clock, that machine is about $584 a month and covers a 100 requests-per-second peak. The repository recommends the matrix-factorisation router, but notes it still needs an OpenAI API key to generate embeddings, even when neither routed model is OpenAI's.

What each stage costs a two-person team

The estimates below are planning figures for a two-person ML team, not measurements. At $20,000 a month, an engineer-week costs about $4,615.

  • Gateway deploy and logging: 1 to 2 engineer-weeks. Deploy LiteLLM or connect a managed gateway, and turn on full request logging.
  • Rules-based routing and fallbacks: 2 to 3 weeks. Route by endpoint, task type, prompt length or customer tier.
  • Eval set from production logs: 2 to 3 weeks. Sample real requests, define pass criteria per task.
  • LLM-judge labelling: 1 to 2 weeks, plus judge spend. The RouteLLM authors labelled 120,000 samples for about $700 at 2024 GPT-4 prices.
  • Learned router: 3 to 6 weeks to train a matrix-factorisation or BERT classifier, calibrate it and A/B test it against the rules.

The full path is 9 to 16 engineer-weeks, or about $41,500 to $73,800, which two engineers can cover in roughly five to eight calendar weeks. The learned stage should be gated on evidence: if the eval set shows the rules router already sends nearly all easy traffic to the cheap model, stop there.

A payback test helps decide. At $120,000 a month of spend, recovering the top of that range in six months requires the learned router to save about $12,300 a month, or a little over 10% of spend, on top of whatever the rules already save.

The step most build-vs-buy comparisons skip

Routing chooses among models you rent. If one repeated task carries most of your spend, such as classification, extraction or a fixed-format reply, the larger saving may come from replacing the model on that task rather than routing around it. The eval set and labelled logs you built for the router are the same assets you need to fine-tune a smaller model for that task, so the work is not wasted either way.

Parsec, a small language model lab, sells this approach as a service: it post-trains models on a customer's traffic, routes per turn rather than per task, and sends low-confidence requests to a closed frontier model. Its comparison page claims "savings on real workloads" of 60% against "typical router savings" of 15%. Those are Parsec's own figures; the page defines no workload or baseline, no independent measurement has been published, and the service has no published price, so its net saving cannot be calculated. Parsec says customers own their models, and its inference page says "Weights: Yours. Download them."

Whether specialising beats routing on your traffic has not been measured by anyone outside the vendors. The way to find out is to run both against the eval set you already built: score the rules router, the learned router and a fine-tuned candidate on the same held-out requests, and compare cost per passing answer.

Vendor risk and who owns what

Build-versus-buy is also a question of what you keep if a vendor changes. Three gateway events this year make the point. Palo Alto Networks announced on April 30, 2026 that it would acquire Portkey and fold it into its Prisma AIRS security product. OpenRouter's sale to Stripe was announced on August 19, 2026, with terms undisclosed. And on October 21, 2026, a malicious LiteLLM 1.107.0 carrying credential-stealing malware sat on PyPI for about two hours and behind LiteLLM's latest Docker tags for longer; LiteLLM told affected users to rotate every provider key stored in the proxy database. Self-hosting removes the acquisition risk but not the supply-chain risk: pin versions and verify image signatures, which LiteLLM now publishes.

Ownership follows the option. Self-hosted LiteLLM keeps logs in your own infrastructure; its docs say no data or telemetry is stored on LiteLLM's servers and usage telemetry is off by default. OpenRouter says it does not log prompts or completions by default but may store account and billing data in the US, and offers EU and US in-region routing only on Business and Enterprise plans. Your eval set and router weights are yours under any option, provided you keep the logs that produced them. A specialised model's weights are yours if you train them yourself or if the vendor's terms let you download them.

Bottom line

If average spend per request at 40 million requests is under about $0.003, buy a managed gateway and spend your engineers on routing rules. If it is above that, or if data residency matters, self-host LiteLLM with pinned, signed images. If you only call one model, a thin gateway for logging and fallbacks is all you need. Build rules first, build the eval set second, and train a learned router only if the eval set shows a gap worth more than about 10% of spend. If one repeated task dominates the bill, test a specialised model against your routers on the same eval set before committing to more routing work.

Sources

More in Chips & Compute

All Chips & Compute →