Local and Edge Inference Beyond the Browser

A team I advised was proud of the plan. Their AI bill had crossed a number that made someone in finance nervous, an open-weight model looked good enough for the work, so they rented a GPU and stopped paying per token. Three weeks later the GPU cost more than the API it replaced.

The model was not slow. The problem was that the box sat idle most of the day, and a rented GPU bills every hour whether or not a request is in flight. The API had charged them for the tokens they used. The GPU charged them for the tokens they could have run and didn’t. Same workload, bigger bill, plus a new pager rotation.

That is the trap in one sentence, and nobody mentions it when they tell you self-hosting is cheaper. This article is the counterweight to running models in the browser. Same instinct, own the inference instead of renting it, but a different scale: a server, an edge node, or a machine somewhere outside the tab. When that is a smart move, and when it quietly costs you more than it saves.

Why anyone runs their own model

Start by being honest that the default is still a hosted API, and it is the right default for most teams most of the time. You get frontier quality, no hardware, no ops, and a bill that scales with use. You should need a reason to leave that. There are five good ones, and they are worth naming precisely because people reach for self-hosting on vibes and regret it.

  • The data cannot leave. Some information is not allowed off your infrastructure, by law, by contract, or by a promise you made to users. If a regulator or a customer’s security team effectively requires that the text never touches a third party, that is not a preference you can prompt your way around. Running the model yourself means the sensitive bytes never leave the perimeter. This is the reason that most often actually justifies the burden.
  • Cost, at high and steady volume. Past a threshold, owning the hardware beats per-token pricing. The important words are high and steady, and we will spend real time on why, because this is where the intuition is backwards.
  • You want off the provider treadmill. Hosted models rate-limit you, have bad afternoons, and get retired on a schedule. You already met that pain in model routing and fallbacks. A model you run does not get deprecated out from under you, and it does not rate-limit you against someone else’s capacity plan.
  • You need to change the model itself. Fine-tuning open weights on your own data, or running a custom variant, is something you can only do when you hold the weights.
  • It has to work with no internet. Air-gapped networks, factory floors, ships, secure facilities. If there is no route to a cloud API, the model has to live on-site.

If none of those is true for you, stop reading and keep calling the API. Genuinely. The rest of this is about the cases where at least one of them is, and about counting the cost honestly before you commit.

Open weights are good now, but not equally good

The thing that makes any of this possible is that open-weight models got seriously capable. As of 2026 the open frontier is close. Families you can download and run yourself clear the bars that used to belong only to closed APIs: strong reasoning, real coding ability, long context in the hundreds of thousands of tokens. For a large share of production work, a well-chosen open model is simply enough.

“Close” is not “equal,” though, and the gap is exactly where it hurts most. On the hardest tasks, the deepest multi-step reasoning, the trickiest code, the long-context needle-in-a-haystack work, the very top closed models still lead. So the trade you are actually making is this: you give up a slice of peak capability and a lot of convenience, and in return you get control and, maybe, cost. Whether that trade is good depends entirely on whether your work lives in the part of the distribution where open models are already fine.

Three places a model can run

Before the money, get the map straight. Once you leave the hosted API there are three physical places the inference can happen, and they score very differently on the things you care about.

cloud APIyour server / GPUedge / devicedata controlleaves your infrastays in your infrastays regionalcost at scalelinear, foreverlowest if kept busycheap, small jobspeak capabilityfrontierstrong, sub-frontiersmall models onlyops burdennoneall yourssome
The same model, three homes. Each column trades differently: the cloud API is easiest and most capable but your data leaves; your own server gives you control at the cost of owning everything; the edge puts a small model close to users for latency and data locality.

No column wins every row. That is the whole point. The cloud API is the top-left-to-bottom-right diagonal of convenience and capability, and its price is that your data goes somewhere else and you rent forever. Your own server flips privacy and long-run cost in your favor and hands you the entire operational bill. The edge is a specialist: it puts a small model physically near the user, which is unbeatable for latency and for keeping data in a region, and useless for anything that needs a big model.

The cost story people get backwards

Here is the mental model that fixes the idle-GPU mistake. A per-token API is pay per use: you are billed for exactly the work you did, and zero when you do nothing. Owned hardware is pay for capacity: you are billed for the machine’s existence, and an idle GPU costs the same as a saturated one. Those are different shapes, and if you plot them against volume you get the picture everyone half-remembers and gets slightly wrong.

monthly costmonthly token volumeowned hardware, fixedAPI, pay per tokena cheaper APIbreak-evenAPI cheaperowning cheaper, if busy
Cost against monthly volume. The API rises with every token, forever. Owned hardware is a flat line, the same whether the GPU is busy or idle. They cross at a break-even, and where that point sits depends heavily on which API you are comparing against.

Two things in that chart matter more than the crossing itself.

The first is the flat line. It does not care about your volume. Buy a GPU for a spiky workload that is busy two hours a day and you pay the flat line all twenty-four. Your effective cost per token is the fixed cost divided by the tokens you actually pushed through, so low utilization inflates it without limit. This is why “we do a lot of AI” is not the same as “we should self-host.” Bursty-but-large can still lose to the API, because the API only bills the bursts.

The second is that there is no single break-even, because there is no single API price. Compared against a premium frontier model, owning your hardware can pay off at a fairly modest volume. Compared against a cheap, fast hosted model, the break-even slides way out to the right, sometimes past hundreds of millions or even billions of tokens a month, which is the dashed line that never crosses the flat one inside this chart. As of 2026 the honest summary is that a hosted API wins on cost for the large majority of workloads, and self-hosting starts to make cost sense only at sustained, high volume against the more expensive tiers.

// Break-even is just arithmetic. The trap is believing the fixed cost is really fixed.
function breakEvenTokensPerMonth({ fixedMonthlyCost, apiPricePerMToken }) {
  // requests are irrelevant; only total tokens and the API's price matter
  return (fixedMonthlyCost / apiPricePerMToken) * 1_000_000;
}

// $6,000/mo of owned capacity vs a $3.00 / 1M-token API:
breakEvenTokensPerMonth({ fixedMonthlyCost: 6000, apiPricePerMToken: 3 });
// -> 2,000,000,000 tokens/month before owning is cheaper... IF the GPU stays busy

That two-billion-token number is not a law, it is an illustration, and the input that moves it most is the API price you picked to compare against. Swap in a budget model at a tenth the price and the break-even goes up tenfold. That is the single most common way the self-hosting business case is quietly wrong: it compares owned hardware against the expensive model the team was overpaying for, when the right comparison was the cheap model they should have routed most traffic to in the first place.

What you actually take on

The flat line hides a lot of labor. When you move off a hosted API you are not just paying for a GPU, you are inheriting the entire stack the provider used to run for you. This is the part that turns a spreadsheet win into an operational loss if you underestimate it.

cloud APIself-hostedapp + promptsyouyouownership flips heremodel weightsprovideryou: pick, store, updateserving runtimeprovideryou: batching, KV cacheGPU + memoryprovideryou: scarce, expensivescaling, latency, opsprovideryou: on-call at 3am
On a hosted API, everything below your app is the provider's problem. Self-host and every layer becomes yours: the weights, the serving runtime, the scarce GPU, and the ops of keeping it fast under load and awake at 3am.

Two of those layers deserve a closer look, because they are where the “real work” actually is.

GPUs are scarce and expensive, and idle ones still bill. Renting a capable accelerator by the hour in 2026 runs from a couple of dollars to well over ten, depending on the chip and how long you commit, which is roughly a thousand to several thousand dollars a month per GPU held. Owning them outright means capital and a supply chain. Either way the meter runs on wall-clock time, not on tokens.

Serving a model efficiently is its own discipline. A naive loop that loads the weights and generates one request at a time wastes most of the hardware. The tools that make self-hosting economically real (the mature open-source serving runtimes as of 2026) win by attacking two different kinds of waste at once.

The good news for a JavaScript developer is that you rarely write any of this yourself. The serving runtime exposes an HTTP endpoint, usually one that mimics the same request shape the hosted providers use, and your app talks to it exactly like it talked to the cloud. If your code was already provider-agnostic, which routing and fallbacks pushed you toward, moving a slice of traffic to a self-hosted model is close to a config change.

// Your app speaks one HTTP shape. Where the model runs is just an address.
// Yesterday, a hosted provider:
const client = makeClient({ baseUrl: "https://api.some-provider.com/v1", key: env.KEY });

// Today, a model you serve yourself on a GPU box, same call site:
const client = makeClient({ baseUrl: "http://gpu-box.internal:8000/v1", key: "unused" });

// The generate() call downstream does not change at all.

That portability is the practical reason to keep the model behind an interface. The hard part was never the JavaScript. It is everything under the endpoint.

The three shapes of running it yourself

“Self-hosting” is not one thing. It spans from a model file on your laptop to a GPU fleet, and the three points on that spectrum suit very different jobs.

A local runtime on one machine. The ecosystem now makes running an open model about as hard as starting a database. A small stack of tools, built on a common C-family inference core, lets you pull a quantized model file and serve it with a single command, on a developer’s laptop or a modest server. A mid-size model quantized to four bits drops to a few gigabytes and runs at readable speed on a single consumer GPU or an Apple Silicon laptop, tens of tokens a second, no cluster involved. This is perfect for local development, for offline tools, and for privacy-first desktop apps. It does not scale to serve thousands of concurrent users, and it is not trying to.

A single GPU serving a real workload. Step up to a serving runtime on a rented or owned accelerator and you can handle genuine production traffic for a small-to-medium model, with the batching and cache tricks earning their keep. This is the sweet spot for the cost and privacy cases: enough throughput to matter, small enough to reason about.

The edge. Instead of one central GPU, push a small model out to many locations physically near your users. You already have the runtime mental model from edge and serverless runtimes; here the payload is a tiny quantized model. The wins are latency, because there is barely any network between the user and the model, and data locality, because inference for a European user can happen on European soil without a round trip to a distant region. The hard limit is size: edge nodes run small models, think classification, embeddings, language detection, moderation, and small chat, not a 200-billion-parameter reasoner. The common architecture is a split, the edge handles the small-and-local majority and routes the heavy requests back to a regional GPU or a cloud model.

Build vs buy, framed like any infrastructure decision

None of this is special to AI. It is the same build-versus-buy call you would make about a database, a search cluster, or a payments stack, and it has the same healthy answer: buy first, build later, and only where it pays. There is a maturity path most teams walk whether or not they plan to.

1 · start on an APIvalidate the productzero ops, frontier quality2 · go hybridself-host the easy bulkcloud for the hard tail3 · self-hostprivacy, volume, or controlworth the burdenmost teams settle here
The path most teams actually walk. Start on an API to prove the product exists. Move to a hybrid split when a real reason appears. Fully self-host only where privacy, sustained volume, or control clearly pay for the operational burden. Plenty of teams stop at hybrid on purpose.

The hybrid middle deserves emphasis because it is the answer far more often than either extreme. You self-host a small or open model for the fat head of easy, high-volume, privacy-sensitive work, and you keep a hosted frontier model on call for the thin tail of genuinely hard requests. Most traffic never leaves your infrastructure and never pays a per-token bill, and the expensive capability is there for the small slice that needs it. This is the exact routing shape from model routing and fallbacks, just with “a model we run” as the cheap default tier instead of a cheap hosted model. The nice property is that you get most of the privacy and cost benefit without betting the whole product on your ability to serve a frontier-grade model reliably at 3am.

Owning the model is not the only way to make it better

People often reach for self-hosting and fine-tuning as the answer to “the model is not good enough at my task.” Usually it is the wrong first move, because there are three different levers labeled “make it better” and they do different jobs. Confusing them wastes the most time.

promptshape the instructionscheapest · try firstRAGsupply your data at query timegrounds facts · stays currentfine-tunechange form and behaviornot for facts · most workif promptingfalls shortif RAGfalls shortCombine, don’t replace: a thin fine-tuned adapter paired with retrieval is a common end state.
Three escalating ways to improve quality. Prompting shapes the instructions and is nearly free. RAG feeds the model your own, current data at query time. Fine-tuning changes the model's form and behavior, and is the most work. Climb only when the rung below is genuinely not enough.
  • Prompting shapes behavior. Better instructions, examples, and structure. It is nearly free, instant to change, and it is astonishing how often it is the entire fix. Always start here.
  • RAG supplies knowledge. Retrieval-augmented generation fetches the relevant facts at query time and puts them in the prompt, so the model answers from your data instead of its frozen training. This is the right tool when the model lacks information: private documents, current data, anything that changes weekly. You are not changing the model, you are handing it the right notes right before it answers.
// RAG in one breath: fetch the facts, put them in the prompt, no retraining.
const docs = await search(userQuestion);   // your data, always current
const prompt = [
  "Answer using only these notes:",
  docs.join("\n"),
  "",
  "Question: " + userQuestion,
].join("\n");
const answer = await model.generate(prompt);
  • Fine-tuning changes form. Training on examples shifts the model’s behavior: its style, its formatting, its refusal patterns, its consistency on a narrow task. The rule that saves people the most grief is that fine-tuning is for form, not facts. Do not fine-tune to teach the model new, changing information; that is RAG’s job, and a fine-tuned model goes stale the moment the facts move. Fine-tune to make it reliably answer in your voice, your JSON shape, your house rules.

The order is almost always prompt, then RAG, then fine-tune, and you stop as soon as quality is good enough. Fine-tuning is last not because it is bad but because it is the most work to build and the most work to keep alive, and in 2026 the highest-value version of it is usually a thin, cheap adapter layered on a strong open base plus retrieval, not a from-scratch retrain that replaces everything. Reaching for a fine-tune before you have exhausted a good prompt and solid retrieval is the classic way to spend a month solving a problem a paragraph of instructions would have fixed. And notice: none of prompt or RAG requires you to host anything. Only fine-tuning nudges you toward holding the weights, and even then a hosted provider will often fine-tune for you.

Put a number on it

The calculator below is fully simulated. It touches no network and calls no model. It only does the arithmetic from earlier so you can feel where the lines cross. Move the sliders and watch the break-even point slide, then flip the non-cost factors on the right, because those are the ones that override the math entirely.

interactiveBuild vs buy: where owning the model pays off

Play with it and two lessons fall out. Drop the API price toward a cheap, fast model and the break-even shoots off the right edge: against a budget model, owning almost never wins on cost alone. And tick a single box on the right and the chart stops being the point. A hard data-residency requirement or an air-gapped deployment justifies self-hosting at any volume, because you are no longer buying a lower bill, you are buying an outcome the API cannot sell you.

When to actually own the model

Strip away the enthusiasm and the honest checklist is short. Run the model yourself when the task fits an open model’s real ability, and at least one of these is clearly true:

  • The data is not allowed to leave. This is the strongest reason and it stands on its own, cost be damned.
  • You are at sustained, high volume against an expensive tier, and you can keep the hardware busy. Not spiky-large. Steady-large, with the utilization to back it up.
  • You cannot tolerate the provider dependency. Uptime, rate limits, or model deprecations are an unacceptable risk to your product.
  • You must customize the model itself, and a hosted fine-tune will not do.
  • There is no network, so the model has to be on-site.

And keep calling the hosted API when the work needs frontier reasoning, when volume is modest or bursty, when your team has no appetite to run GPUs, or when the honest answer to “why self-host” is “it feels like it should be cheaper.” Feelings are not utilization. The most common right answer, by a wide margin, is the boring one: start on an API, prove the thing works, and move only the specific slice of traffic that has a specific reason to move.

Summary

  • Cloud APIs are the right default. Self-host only for a concrete reason: data that cannot leave, sustained high volume against a pricey tier, provider-dependency risk, model customization, or an offline requirement.
  • Open-weight models are genuinely capable in 2026 and close the gap on most work, but still trail the top closed models on the hardest reasoning, coding, and long-context tasks. You trade a slice of peak capability and a lot of convenience for control and possibly cost.
  • A per-token API is pay-per-use; owned hardware is pay-for-capacity. An idle GPU bills the same as a busy one, so utilization, not raw volume, decides the cost case.
  • There is no single break-even, because there is no single API price. Owning can beat a premium model at modest volume and lose to a cheap model until absurd volume.
  • Self-hosting means inheriting the whole stack: scarce, expensive GPUs, an efficient serving runtime (continuous batching and a paged KV cache do the heavy lifting), latency under load, and on-call ops.
  • Running it yourself spans a laptop-scale local runtime, a single GPU serving real traffic, and small models pushed to the edge for latency and data locality.
  • Hybrid is usually the real answer: self-host the easy, high-volume, private bulk and keep a hosted frontier model for the hard tail, the same routing shape with the device or your own GPU as the cheap tier.
  • To make a model better at your task, escalate prompt, then RAG, then fine-tune, and stop when it is good enough. RAG is for facts, fine-tuning is for form, and neither prompting nor RAG requires you to host anything.