Supplementary Extension
Open Source
Models

The agent patterns you learned with Claude also run on Mistral-7B, Llama-3, and 100+ open models. Seven concepts: when to reach for open source, how to run it locally, and exactly what breaks when you swap providers.

Supplementary Extension ⏱ ~22 min read M28 / Appendix
Concept 1 of 7

"Right for the cert" is not "right for everything"

This course uses Claude throughout, and for good reason: the cert exam and Claude-only features (extended thinking, computer use, hooks) demand it. But three situations pull developers toward open source anyway.

Cost at scale — 10,000 simple classifications a day on a $40/month VPS beats per-token pricing by an order of magnitude. Data privacy — hospitals, banks, and defense contractors legally cannot send data to a third-party API; local inference is the only path. Portability knowledge — learning the swap tells you which parts of your agent are model-specific and which are yours forever.

Concept 1 of 7

Owning the delivery van vs hiring couriers

BEFORE: When you ship a few packages a week, you hire a premium courier. Fast, reliable, no overhead — you pay per delivery and never think about vehicles. That's Claude's per-token API.

PAIN: Now you ship 10,000 identical parcels a day, and some contain records that legally can't leave your building. Paying premium-courier rates per parcel becomes absurd, and handing sealed medical files to an outside driver breaks the law outright. The convenient default is now the expensive, non-compliant choice.

MAPPING: At that volume you buy your own van and driver — a local open source model on your own hardware. Higher upfront effort, but per-parcel cost collapses and nothing ever leaves your loading dock. You pick couriers or the van per route, not once forever.

Concept 1 of 7

The three forces, made concrete

  1. Cost bends at volumeLow volume: per-token pricing is invisible. High volume of simple tasks: a fixed-cost local model wins big, because the quality gap on easy work is tiny.
  2. Privacy is binarySome data can never touch an external API. Local inference keeps it inside your network — a compliance requirement, not a preference.
  3. Patterns are yoursRAG, ReAct loops, guardrails, and tracing work identically on any provider. The architecture belongs to you.
  4. The positionClaude for reasoning-heavy, agentic, cert work; open source for batch, private, and high-volume-simple work.
Concept 1 of 7

Claude, or open source?

# Which model should this workload use?

IF data cannot leave your network:
  USE local open source   # only legal option

ELIF task is simple AND volume is huge:
  USE open source          # cost wins, quality gap tiny

ELIF task is agentic / multi-step
      OR needs cert-only features:
  USE Claude                # reasoning + hooks + caching

ELSE:
  PROTOTYPE both, measure quality vs cost

The choice is per-workload, not a one-time religion. Most real systems use both.

Concept 1 of 7

Misconceptions

"Open source is always cheaper."
Only at scale on simple tasks. At low volume, hardware and ops overhead cost more than a few API calls. Cost advantage appears when fixed infra is amortized over huge request counts.
"Picking a provider is a permanent commitment."
It's per-workload. A hybrid system routes cheap tasks to a local model and hard tasks to Claude. The agentic architecture is model-agnostic, so switching is a config change.

Use Claude where reasoning, agentic reliability, or cert features matter; use open source where cost, privacy, or batch volume dominate.

The skill is knowing which lever you're pulling — and that most of your agent code doesn't care which model answers.

Concept 2 of 7

Four ways to run an open model

Providers differ on where the model runs, who owns the hardware, and what it costs. Four cover almost every case: Ollama (local, free, CLI), LM Studio (local, free, GUI), Groq (cloud, blazing fast, cheap), and Together AI (cloud, hundreds of models, pay-per-token).

The crucial thing they share: all four speak the same OpenAI-compatible dialect, so your code barely changes between them. Ollama is the recommended starting point — no key, no rate limits, nothing leaves your machine.

Concept 2 of 7

How you get your electricity

BEFORE: You need power. You could install rooftop solar (own it), buy a plug-in generator (own it, simpler), or just buy from the grid (someone else runs the plant).

PAIN: Pick one blindly and you regret it. Solar is great until a cloudy week; a generator is fine until you need industrial loads; grid power is easy until you need to run off-grid or keep usage private. Each option is right for a different constraint.

MAPPING: Ollama is rooftop solar (self-hosted, private, capped by your hardware). LM Studio is the same, with a friendlier control panel. Groq and Together AI are the grid — someone else's big plant, metered, effectively unlimited capacity. You choose by constraint, not by loyalty.

Concept 2 of 7

Who runs what, and when to pick it

  1. Ollama — local, freeRuns on your laptop/server. No key, no rate limits, offline. 100+ models. The default for dev and privacy.
  2. LM Studio — local, GUIDesktop app for Windows/Mac. Same OpenAI-compatible endpoint once a model is loaded. Good if you prefer clicking to CLI.
  3. Groq — cloud, very fastCustom LPU hardware, often faster than Claude, free tier. Use when local hardware isn't enough.
  4. Together AI — cloud, many modelsHundreds of models, pay-per-token, plus fine-tuning. Best for experimenting across families.
RAM by model size (4-bit)
Mistral 7B~5 GB
Llama 13B~9 GB
Llama 70B~40 GB
Claude API0 local
Concept 2 of 7

Which provider for which situation

# Match the situation to the provider

dev on a laptop        -> Ollama    # free, instant, offline
data-privacy required  -> Ollama    # nothing leaves machine
no GPU, need low latency-> Groq      # LPU, ~500 tok/s
exploring many models  -> Together  # 200+ models
Windows, prefer a GUI  -> LM Studio # desktop app
production agentic work -> Claude    # reasoning + caching

RULE: local for privacy/cost,
      cloud when hardware is the limit
Concept 2 of 7

Misconceptions

"Local always means slow."
A 7B model with a GPU (or Apple Silicon) is snappy. And when local hardware isn't enough, Groq's cloud LPUs are often faster than a frontier API — speed isn't a local-vs-cloud rule.
"Switching providers means rewriting my app."
All four expose the same OpenAI-compatible endpoint. In practice you change a base URL and a model string — not your logic.

Four providers, one shared API dialect. Ollama and LM Studio run locally; Groq and Together host in the cloud.

Start with Ollama for free local dev, and reach for a cloud provider only when your hardware becomes the bottleneck.

Concept 3 of 7

One request shape almost everyone speaks

OpenAI's Chat Completions schema became the de facto standard for talking to LLMs — not by decree, but because so many tools were built around it first. A request is {"model": ..., "messages": [...]}; the reply lives at choices[0].message.content.

Ollama, Groq, Together, and LM Studio all implemented that exact shape. So the same client code hits localhost:11434 (Ollama) or api.groq.com by changing one URL. Anthropic's Messages API is close but different — which is why a raw swap needs a thin adapter.

Concept 3 of 7

USB-C ended the cable drawer

BEFORE: Your phone wanted Lightning, your old tablet wanted Micro-USB, your laptop wanted a barrel jack. Every maker chose a plug shape independently, and you carried three cables to be safe.

PAIN: That divergence cost everyone. A charger that fit one device was useless for the next, so you hoarded adapters and still got caught without the right one. Each new gadget with its own port made the mess worse.

MAPPING: USB-C is one plug the whole industry agreed on — charge anything with one cable. The OpenAI schema is USB-C for LLMs: providers adopted it so any OpenAI client "plugs in" by swapping the base URL. The SDK becomes your universal remote.

Concept 3 of 7

Three fields that differ

  1. System prompt placementAnthropic: a top-level system field. OpenAI: a message with role: "system" at the front of the list.
  2. Response pathAnthropic reply is at content[0].text. OpenAI-compatible reply is at choices[0].message.content.
  3. max_tokensRequired in Anthropic (no default); optional in the OpenAI schema (falls back to a model default).
  4. Everything else matchesRoles, multi-turn history, temperature, and streaming behave the same — so a thin adapter, not a rewrite, bridges the two.
One client, swap the base URL
Your code
(OpenAI SDK)
base_url
Ollama /
Groq /
Together
Concept 3 of 7

Pseudocode

# ANTHROPIC request
request = {
  model:      "claude-model",
  system:     "You are helpful.",   # top-level
  max_tokens: 256,                # REQUIRED
  messages:   [ user_turn ]
}
reply = response.content[0].text  # Anthropic path

# OPENAI-COMPATIBLE request (Ollama/Groq/...)
request = {
  model:    "mistral",
  messages: [ system_turn, user_turn ]  # system = a msg
  # max_tokens optional
}
reply = response.choices[0].message.content
Concept 3 of 7

Misconceptions

"OpenAI-compatible means I must use OpenAI's models."
No — it's the request/response shape, not the vendor. Ollama serving Mistral speaks the same schema; you never touch OpenAI's servers.
"Claude and OpenAI schemas are identical, so I can point my Anthropic code straight at Ollama."
Close but not identical: system placement, response path, and required max_tokens differ. Use an OpenAI client or LiteLLM as the adapter.

The OpenAI Chat Completions schema is the universal adapter — adopted by most open source servers, so one client reaches many providers via a base-URL swap.

Only three fields differ from Anthropic's schema; a thin adapter, not a rewrite, bridges them.

Concept 4 of 7

Docker for AI models

Ollama is the simplest path to local inference. It handles model download, quantization, hardware detection, and serving behind one CLI. Install once, pull a model like a Docker image, and your laptop becomes an LLM server on localhost:11434.

Mistral-7B at 4-bit quantization needs about 5 GB of RAM and runs on an 8 GB MacBook Air or a 16 GB laptop, using a GPU if one's present and falling back to CPU if not. Tight on RAM? ollama pull phi3:mini is only 2.3 GB.

Concept 4 of 7

App store vs building from source

BEFORE: To run a program in the old days you fetched source code, installed the right compilers, resolved dependencies, and prayed it built. Powerful, but a day of yak-shaving before you saw "Hello, world."

PAIN: Running a raw open model is that same nightmare: pick weights, match a runtime, choose a quantization, wire up a server, detect your GPU. Every step is a chance to get stuck, and none of it is the thing you actually wanted to do.

MAPPING: Ollama is the app store — ollama pull mistral and it's installed, quantized, and served. It hides the compiler-and-dependencies pain behind one command, the way an app store hides the build behind "Install."

Concept 4 of 7

Install → pull → serve → call

  1. Install onceA one-line install script on Mac/Linux, or the Windows installer. Ollama detects your hardware automatically.
  2. Pull a modelFetch Mistral-7B (~4 GB, 4-bit) like a container image. It's cached locally for reuse.
  3. Serve the APIStart the server; it exposes an OpenAI-compatible endpoint at localhost:11434.
  4. Call itHit it with curl, the OpenAI SDK, or LiteLLM — all three behave identically. Connection refused usually just means the server isn't running.
The Ollama lifecycle
install
pull
mistral
serve
:11434
API
call
Concept 4 of 7

Pseudocode

# one-time setup (shell)
INSTALL ollama
PULL model "mistral"      # ~4 GB, 4-bit
START server              # listens on :11434

# first call — OpenAI-compatible endpoint
POST http://localhost:11434/v1/chat/completions
  body = {
    model:    "mistral",
    messages: [ user("Explain an LLM in 1 sentence.") ]
  }

IF connection refused:
  # server not up -> run `ollama serve`, retry
ELSE:
  reply = response.choices[0].message.content
Concept 4 of 7

Misconceptions

"You need a big GPU to run a local model."
Mistral-7B at 4-bit fits in ~5 GB and runs on an 8 GB laptop, CPU-only if needed. A GPU speeds it up but isn't required; Phi-3 Mini fits even smaller machines.
"Quantization ruins quality."
4-bit cuts RAM ~4× with only a slight, usually unnoticeable quality drop on typical text tasks. It's what makes 7B models practical on a laptop.

Ollama is Docker for models — pull, serve, call. It turns a laptop into a private, key-free, rate-limit-free LLM server.

4-bit quantization is the trick that makes a 7B model fit in ~5 GB; the endpoint is OpenAI-compatible, so your client barely changes.

Concept 5 of 7

Only three things change

Running the same "hello world" against Claude and against Mistral-7B, the concepts are identical — and just three things differ: the client (Anthropic SDK vs OpenAI SDK pointed at Ollama), where the system prompt goes (top-level vs a message), and the response path (content[0].text vs choices[0].message.content).

Two clean strategies: Strategy A uses the openai package with a different base_url. Strategy B uses LiteLLM, where the provider is just a prefix in the model string ("ollama/mistral", "groq/llama3-8b-8192").

Concept 5 of 7

Same wall socket, different appliance

BEFORE: Your kitchen wall socket delivers the same power whether you plug in a kettle or a toaster. The wiring in the wall — your app's message loop, history, error handling — never changes.

PAIN: If every appliance needed you to rewire the wall, swapping the kettle for a toaster would be a renovation. That's what it feels like when model-call details leak all through your code — a provider change touches a hundred lines.

MAPPING: Isolate the model call behind one thin function (the socket). Everything upstream plugs into that socket unchanged; swapping Claude for Mistral is swapping the appliance, not rewiring the house. LiteLLM makes the socket truly universal.

Concept 5 of 7

Isolate the call, swap behind it

  1. Wrap the callPut the model request in one function that takes messages and returns text. Nothing else in your app touches a provider.
  2. Branch once insideAnthropic path: top-level system, read content[0].text. OpenAI path: system-as-message, read choices[0].message.content.
  3. Point the base URLFor Ollama, an OpenAI client with base_url=localhost:11434/v1 and a dummy API key (Ollama ignores it).
  4. Or let LiteLLM routeOne completion() call; the provider is just a prefix on the model name. The loop above stays identical.
Concept 5 of 7

Pseudocode

# one function hides the provider
FUNCTION chat(provider, messages, system):
  IF provider == "claude":
    r = anthropic.create(
          system=system,        # top-level
          max_tokens=1024, messages=messages)
    RETURN r.content[0].text
  ELSE:                        # ollama / groq / ...
    msgs = [ system_msg(system) ] + messages
    r = openai_compat.create(model=..., messages=msgs)
    RETURN r.choices[0].message.content

# the loop above NEVER changes when you swap
Concept 5 of 7

Misconceptions

"Ollama needs a real API key."
The OpenAI SDK requires the field to be non-empty, so you pass a dummy like "ollama". Ollama doesn't authenticate it — it's just to satisfy the client.
"Swapping providers means rewriting the whole agent."
If the model call is isolated behind one function, only that function changes. History, the input loop, and error handling are provider-agnostic and stay put.

Isolate the model call behind a thin function and a provider swap is a one-place change, not a rewrite.

Three details differ — client, system placement, response path. LiteLLM collapses even those into a single call with a prefixed model name.

Concept 6 of 7

The swap covers a lot — but not everything

Basic completions, multi-turn chat, system prompts, temperature, and streaming all port cleanly. But several Claude capabilities have no open-source equivalent: prompt caching, extended thinking, computer use, Claude Code / hooks / sessions, a 200K context window, and native citations.

This isn't a knock on open source — it's the current feature landscape. The good news: your architecture (RAG, ReAct, multi-agent, guardrails, tracing) is model-agnostic and transfers directly. Only the model-specific features stay Claude-only.

Concept 6 of 7

Moving countries: skills travel, the SIM doesn't

BEFORE: You relocate abroad. Your language, your professional skills, your relationships — all come with you intact. Those are portable by nature.

PAIN: But your local phone plan, your transit card, your loyalty points, your specific bank's app — those were tied to the old place and simply don't work on arrival. Assuming they'd transfer leaves you stranded at the airport.

MAPPING: Your agent's architecture is your skills — it moves to any model. Prompt caching, extended thinking, computer use, and hooks are the local SIM and loyalty card: platform features bolted to Claude that don't come along. Know which is which before you pack.

Concept 6 of 7

What stays behind vs what travels

  1. Claude-only platformPrompt caching (cost/latency on long prompts), Claude Code, hooks, and session management are Anthropic platform features — no Ollama equivalent.
  2. Claude-only capabilityExtended thinking, computer use, native citations, and a 200K context window have no reliable open-source match today.
  3. Tool use is unevenOpen models can do function calling, but reliability varies — Mistral-7B is okay, Llama-3-70B far better. Test before you deploy agentic tool use.
  4. Architecture travelsRAG, ReAct, multi-agent, guardrails, tracing, and deployment patterns work identically on any provider.
Concept 6 of 7

Does this feature port?

# Before swapping, check each feature you rely on

IF feature is an agentic PATTERN
   (RAG, ReAct, multi-agent, guardrails,
    tracing, deployment):
  -> PORTS cleanly

ELIF feature is a Claude PLATFORM/capability
   (prompt caching, extended thinking,
    computer use, hooks, 200K ctx, citations):
  -> DOES NOT PORT  # rebuild manually or keep Claude

ELIF feature is tool use:
  -> TEST FIRST      # reliability varies by model
Concept 6 of 7

Misconceptions

"Swap to Mistral-7B and get the same quality."
On simple extract/classify tasks, quality is close. On multi-step reasoning and 5+ step tool chains, the gap between a 7B and a frontier model is large. Test your specific task first.
"Open models support tool use the same way."
Support depends on the model. Mistral-7B does function calling but less reliably than Claude; Llama-3-70B is much better. Never assume — verify before shipping agentic tool use.

Patterns port; platform features don't. RAG, ReAct, guardrails, and tracing move to any model unchanged.

Prompt caching, extended thinking, computer use, hooks, big context, and citations stay Claude-only — and tool-use reliability must be tested per model.

Concept 7 of 7

The honest answer is "it depends on the task"

There's no global winner — the right provider is chosen per workload. Claude for complex multi-step reasoning, agentic tool chaining (3+ steps), and cert-specific work. Open source for simple classification/extraction, batch offline processing, data-privacy requirements, and fine-tuning on proprietary data.

The most powerful pattern is hybrid routing: a cheap model (or even a regex) triages requests, and only the genuinely hard ones go to Claude. Mistral-7B as the traffic cop, Claude as the specialist it routes to.

Concept 7 of 7

The hospital triage nurse

BEFORE: Imagine every patient walking into an ER is sent straight to the head surgeon, no matter their problem. A paper cut and a heart attack get the same top specialist.

PAIN: The surgeon's time is scarce and expensive. Spending it on paper cuts means real emergencies wait, and the whole system pays a specialist's rate for trivial work — like paying a consultant to press an elevator button.

MAPPING: A triage nurse (a cheap, fast open source model) handles the routine cases and routes only the serious ones to the surgeon (Claude). Route cheap tasks to cheap models; reserve the expensive reasoning engine for the work that actually needs it.

Concept 7 of 7

Route by task, not by loyalty

  1. Classify the taskSimple/high-volume or complex/reasoning-heavy? Privacy-constrained or not? This decides the lane.
  2. Send simple & private work to open sourceClassification, extraction, batch jobs, and anything that can't leave your network go to a local model.
  3. Send hard work to ClaudeMulti-step reasoning and agentic tool chaining stay on the frontier model where reliability matters.
  4. Add a routerA cheap model triages intent up front and forwards only the complex cases — the hybrid pattern that optimizes cost and quality together.
Hybrid routing
request
router
(Mistral)
simple?
keep local
hard?
Claude
Concept 7 of 7

Task → provider

# Pick a provider per task type

complex multi-step reasoning  -> Claude
agentic tool chaining (3+)    -> Claude
cert prep (M25-M27)           -> Claude

simple classify / extract     -> open source
batch offline processing      -> open source
data-privacy requirement      -> Ollama  # only option
fine-tune on private data     -> open source

BEST: hybrid — cheap model triages,
      Claude handles the hard cases
Concept 7 of 7

Misconceptions

"Pick one model and run everything through it."
That pays a specialist's rate for trivial work, or ships weak results on hard work. Route by task type; a hybrid system is usually both cheaper and better.
"Open source can't be part of a serious production system."
It routinely is — for batch jobs, private data, and high-volume triage. The trick is using it where its strengths fit, not as a blanket replacement.

Choose per workload, and prefer hybrid routing. A cheap model triages; Claude handles the genuinely hard, agentic, or cert-critical cases.

Privacy makes the choice for you — when data can't leave, local open source is the only option.

Test the core insight

One question per concept. Tap to reveal the answer.

Open the full module on desktop

The desktop version is the full build — Ollama install steps, side-by-side Claude/Mistral swap code in Python and Node, a LiteLLM router, a provider-agnostic CLI chat, and a hands-on lab — with animated API-diff and hardware visualizers.

Open M28 on Desktop → Full build · Ollama + swap code + LiteLLM + lab · ~60–75 min

M28 · Supplementary Extension · End of Curriculum