Run AI Locally preview

Chapter 1: Why run AI locally

Running AI locally means the model lives on your machine. The weights are on your disk. Inference happens on your GPU or CPU. No API key, no network round trip, no billing dashboard. For some work this is a curiosity. For other work it is the only viable path.

Learning objectives

After this chapter you will be able to:

  • Compare the real cost of cloud APIs against local inference on consumer hardware
  • Identify the use cases where local models are the right call and where they are not
  • Understand the privacy, availability, and control advantages that local inference provides
  • Read the adoption signals that tell you this is not a fringe hobby

Why this matters

You are probably paying more per token than the hardware amortization cost, and you might not need the frontier model you are sending every query to. You might be sending proprietary source code, user data, or regulated information to a third party when a local model could handle the task on your machine. You might be blocked by a rate limit or an outage right when you need the model most. These are not hypothetical problems. They are the daily experience of anyone who has built on cloud APIs long enough. Local inference is not about replacing cloud models. It is about knowing when each belongs and what you give up in either direction.

The economics of local inference

Cloud API pricing has dropped substantially over the last two years, but the numbers are still worth examining honestly. As of mid-2026, GPT-5.6 costs $5 per million input tokens and $30 per million output tokens. Claude Fable 5 is $10 per million input tokens and $50 per million output tokens. These numbers look small until you translate them into real usage.

A coding session with an AI assistant can burn 100,000 tokens in an afternoon. That is $3.50 with GPT-5.6 at the current rates. One session. Multiply by 20 working days and you are at $70 per month for one person’s coding assistant usage alone. Add content generation, document analysis, and experimentation, and the monthly API bill for a heavy user can cross $200 without effort.

Now look at the hardware side. A MacBook Pro M4 draws roughly 40 watts under load. At the US average electricity rate of $0.14 per kWh, running inference continuously costs about $0.0056 per hour. That is roughly $4 per month if you ran inference 24/7. You will not run inference 24/7, and the hardware has an upfront cost, but the marginal cost of each additional token from a local model is zero.

The hardware is not free. A $2,399 MacBook Pro M4 amortized over three years costs roughly $67 per month before electricity. Add that to the $4 for power and you are at $71 per month for hardware that runs local models and also happens to be your development machine. The crossover point where local hardware becomes cheaper depends entirely on your API usage volume - but for anyone using AI as a daily tool, the math tilts toward local within the first year.

The more interesting economic argument is not about cost savings. It is about removing the per-token psychology. When every prompt carries a meter, you edit your prompts smaller, ask fewer follow-up questions, and avoid the exploratory “what if I try this approach” query that might waste 5,000 tokens. Local inference removes the meter. You burn tokens like you burn CPU cycles: freely.

Privacy and data sovereignty

Code you write for a client moves through the API provider’s servers when you paste it into a cloud chat interface. User data you are debugging moves through those same servers. Proprietary models, internal documentation, unreleased product specs - all of it leaves your machine and lands on infrastructure you do not control.

The providers publish privacy policies. OpenAI and Anthropic both state they do not train on API data by default. Those are contractual promises backed by corporate policy, not technical guarantees. A policy change, a court order, a subpoena, or a security incident changes the equation instantly. For many use cases the risk is acceptable. For some it is not.

Three categories where local inference is not negotiable:

Regulated data. GDPR requires data controllers to ensure adequate protection when personal data leaves the EU. HIPAA in the US imposes specific requirements for protected health information. Financial regulations in most jurisdictions restrict where customer financial data can be processed. If your data falls under any of these, sending it to a cloud API creates a compliance burden that local inference eliminates entirely. The model runs in your controlled environment. The data never leaves.

Proprietary code and trade secrets. If you would not paste your source code into a public GitHub repository, you should think twice before pasting it into a cloud chat interface. The same logic applies to internal strategy documents, unreleased product designs, and anything covered by an NDA. Local models keep that information on your machine.

User-generated content. If your application processes user-uploaded documents, chat messages, or any content your users create, routing that through a cloud API means you are sharing your users’ data with a third party. Your privacy policy must disclose this. Your users may not want it. Local inference sidesteps the entire concern.

The privacy argument is not absolute. Cloud providers have security teams larger than your entire company. Their infrastructure is hardened in ways your laptop is not. But privacy is about data locality, not about security posture. A secure vault in someone else’s building still puts your data in someone else’s building.

Offline and always available

Cloud APIs fail in predictable ways:

  • Rate limits cut you off after N requests per minute
  • Regional outages take down entire API surfaces for hours
  • Account billing issues suspend access without warning
  • Provider deprecation kills the model you built your pipeline around

Then there are the environments where cloud is not an option period. A laptop on an airplane. A workstation in a manufacturing facility with no internet by policy. A field deployment in a region with intermittent connectivity. A government or defense context where air-gapped machines are the only permitted environment. In each of these, local inference is not a preference. It is the only way to run any model at all.

The reliability argument extends to your own development workflow. A model that ran yesterday should run today with the same behavior. Cloud models receive silent updates that change output quality in ways you cannot pin down. A prompt that produced perfect JSON last week now adds an extra field you did not ask for. Local models are frozen at the version you downloaded. They produce the same output for the same input every time, controlled by the same temperature and seed. That determinism is worth more than any benchmark number when you are building a system that must behave predictably.

Control without compromise

Cloud models impose limits that have nothing to do with capability:

System prompts are filtered. Cloud providers scan your system prompt and reject anything that violates their content policies. Want to build a red-teaming tool that stress-tests other AI systems? Blocked. Want to generate content about security vulnerabilities for a defensive guide? Flagged. The provider decides what is acceptable, and the boundary moves without notice.

Rate limits are per-account, not per-model. You might pay $200 per month for a Pro tier and still hit a rate limit during a coding sprint. Local models are rate-limited only by your hardware. If your GPU can handle 50 tokens per second, you get 50 tokens per second whether it is your first query of the day or your thousandth.

Model availability is subject to deprecation. Providers retire models on their own schedule. When GPT-4 was deprecated in favor of GPT-4o, every system built around GPT-4’s specific behavior had to be retested and recalibrated. With local models, you control the upgrade cycle. You move to the new model when you decide the new model is better for your use case.

Output filtering is non-negotiable. Cloud APIs insert safety classifiers between the model and your response. These classifiers catch some genuinely harmful outputs and many entirely benign ones. A model explaining how SQL injection works for a security training module can trigger the same filter as a model generating an actual attack. Local models give you the raw output with no intermediary making content decisions on your behalf.

None of this means cloud models are bad. It means they are opinionated infrastructure built for the median user, and the median user is not you. You have a specific use case with specific requirements. Local models let you match the tool to the task without asking permission.

A concrete example: the code review pipeline

You run a code review pipeline that reads pull requests, summarizes the changes, and flags potential bugs. On a cloud API, that pipeline processes roughly 200,000 tokens per day across all PRs. At GPT-5.6 pricing, that is $7 per day, roughly $150 per month. The pipeline stalls when you hit the 500-request-per-minute rate limit during a busy merge window. Your proprietary codebase - the one that constitutes your company’s competitive advantage - passes through a third-party server on every review.

Move that pipeline to a local Qwen 3.6 35B model running on an M4 Pro MacBook Pro. The model is purpose-built for coding tasks. It runs continuously, handles every PR without rate limits, and produces comparable review quality for the bug-flagging and summarization tasks. The code never leaves the machine. The monthly cost is electricity. The model you chose stays the same model until you decide to upgrade it.

This is not hypothetical. It is the pattern that teams running local inference adopt within weeks of setting it up: identify the high-volume, moderate-difficulty task that burns API credits, move it to local, and keep the cloud API for the hard problems. The economics and the privacy benefits compound with every task you migrate.

When local does not make sense

Honest tradeoffs make better decisions than blanket recommendations. Here is where local inference is the wrong tool:

Frontier reasoning. If your task requires the best available reasoning - complex legal analysis, advanced mathematics, multi-step research synthesis - the frontier cloud models are materially better. GPT-5.6 and Claude Fable 5 outperform local models on reasoning benchmarks by meaningful margins. You run them because the task demands it, not because they are cheaper.

Rapid prototyping. When you are exploring an idea and need the model to just work without configuration, cloud APIs are faster. No model download, no quantization choice, no hardware compatibility check. Type an API key and go. Optimize for local once you know what you are building.

Tiny budget with infrequent use. If you send fewer than 50,000 tokens per month, the hardware math does not work. A $20 per month API subscription costs $240 per year. A capable local-inference machine costs at least $600. Run the cloud API for two years before the hardware breaks even, and by then the hardware is two years old.

One million token context. Gemini 2.5 Pro handles 2M tokens of context. The best local models cap out around 128K. If your task requires reasoning over an entire codebase or a multi-hundred-page document in a single call, cloud models are the only realistic option right now. (Available in full handbook.)

Full multimodal pipelines. Cloud models accept images, video, and audio natively. Local multimodal support exists - Gemma 4 handles images, Qwen 3.5 handles images and video - but the integration is rougher, the vision encoders are smaller, and the tooling is less mature. If your pipeline is primarily visual, cloud models save you real engineering time. (Available in full handbook.)

The adoption signals are not subtle

You can measure the shift by watching where developers put their attention:

Ollama has 176,000 GitHub stars and counting. llama.cpp has 119,000 stars. These are not vanity metrics for a niche project. They represent hundreds of thousands of developers who downloaded a tool, ran a model locally, and found the experience worth sticking with.

Hacker News has published 2,628 stories tagged “local LLM.” Ollama-related posts routinely hit 300 to 1,100 points, numbers that indicate broad developer interest rather than a small enthusiast bubble.

The pull counts on Ollama’s model registry tell the same story: Gemma 4 has 16.9 million pulls. Ornith, a self-improving coding agent model released under the MIT license, accumulated 204,000 pulls in its first week alone. These are not researchers downloading models to study architecture. These are engineers downloading models to use them.

The integration story is maturing fast. Ollama models now launch directly from the major coding assistants: ollama launch claude, ollama launch codex, ollama launch opencode, ollama launch copilot. The same tools you use with cloud APIs now accept a local backend without changing your workflow. You type the same prompts. The model just happens to run on your GPU.

Key takeaways

  • Cloud API costs add up for daily users. A heavy AI user can spend $200+ per month on API calls, while local hardware amortizes to a fixed monthly cost with zero marginal per-token expense.
  • Privacy is a data-locality issue, not a security-posture issue. Local inference keeps regulated data, proprietary code, and user content on your machine.
  • Local models work offline, never hit rate limits, never receive silent updates that break your pipelines, and give you raw output with no content filter.
  • Local inference is the wrong tool for frontier reasoning, infrequent low-budget use, million-token contexts, and multimodal-heavy pipelines. Know which tool fits which task.

Common pitfalls

Assuming local equals free. Hardware has an upfront cost and a lifespan. Run the numbers for your usage pattern. If you use AI sparingly, the API bill is cheaper than the hardware amortization.

Downloading the biggest model first. Start with a model that fits comfortably in your VRAM with overhead to spare. A 7B model that runs fast and answers immediately is more useful than a 70B model that generates two tokens per second and swaps to disk.

Treating local and cloud as mutually exclusive. The productive setup for most engineers is a hybrid: local models for daily coding assistance, document analysis, and iteration; cloud models for the hard reasoning problems and tasks that genuinely need frontier capability. Run both. Switch based on the task, not on ideology.

Further reading

Checkpoint exercise

Audit your current AI usage for one week. Track every API call you make: what model you used, roughly how many tokens, and what the task was. At the end of the week, categorize each task as “could run locally,” “needs cloud,” or “unsure.” For each “could run locally” task, note which capability you need: text generation, code completion, document Q&A, or classification. This audit tells you whether local inference fits your workload and which model size you actually need before you spend a dollar on hardware.