Your Ollama agent runs great on your laptop. Now move it to the cloud so it runs 24 / 7, serves your team, and runs 5–10× faster — with the same code. Four concepts: why go cloud, which provider, managed hosted options, and one wrapper that hides them all.
The 4 concepts of cloud deployment
Tap any concept to jump to its 5-card cluster.
Same code, a machine that never sleeps
Local Ollama is perfect for building, but it dies when you close the lid, no teammate can reach it, and a 3 am job finds nothing listening. A cloud GPU VM fixes all three: it runs 24 / 7 and a T4's dedicated 16 GB VRAM delivers ~40 tokens/sec — five times a laptop CPU.
The magic is that nothing about your agent changes. Every call still points at base_url; you just swap localhost for the VM. It's a config change, not a migration.
The analyst who never sleeps
BEFORE: Picture a brilliant research analyst who only works at the one desk in your home office — your laptop. While you're there during the day, they're fast and helpful.
PAIN: But the moment you shut the office (close the lid), they vanish. A colleague overseas can't knock on your door, the 3 am batch job finds an empty desk, and when three people show up at once they all queue for the same single chair.
MAPPING: A cloud GPU VM hires that same analyst into an office that never closes. They work around the clock, sit behind a locked door only an SSH key opens, and their GPU desk is five times faster. You didn't retrain the analyst — you just gave them a better, always-open room.
Laptop to cloud, step by step
- Provision a GPU VMRent a VM with a GPU (e.g. a T4) and install Ollama on it.
- Run Ollama as a serviceRegister it so it starts on boot and restarts on crash — always listening.
- Open a secure tunnelForward your local port to the VM over an encrypted SSH channel; no public port needed.
- Point base_url at itRead the endpoint from an env var. Dev = localhost, prod = the VM. One value flips it.
laptop 8 tok/s → T4 40 tok/s → A100 200 tok/s — the code is identical.
Pseudocode
# the ONLY thing that changes: the host base_url = env("OLLAMA_BASE_URL", default = "http://localhost:11434/v1") # dev -> localhost (unset var) # prod -> set OLLAMA_BASE_URL to VM tunnel client = open_ai_client( base_url = base_url, api_key = "ollama") reply = client.chat(model="mistral", messages=[...]) # no if-branch, no adapter, no rewrite
Misconceptions
base_url, the only change is the hostname — ideally read from one env var. Same model name, same request format, same streaming and tool schema.A cloud GPU VM gives you 24/7 uptime, team access, and 5–10× speed — with byte-for-byte the same agent code.
Read base_url from an env var so dev and prod differ by one value, never a code path.
Not all GPU clouds are equal
Once you decide to host, you pick a provider — and they trade off on three axes: cost per hour, inference speed, and operational fit with your existing stack. A Vast.ai RTX 3090 spot instance is ~$0.20/hr and ~80 tok/s; a GCP T4 is ~$0.35/hr and ~40 tok/s; a CoreWeave A100 is ~$2.21/hr and ~200 tok/s.
There's no single "best" — the cheapest box for experiments is rarely the enterprise box for production. You match the provider to the job, not to a leaderboard.
Renting a car for the trip
BEFORE: Imagine every rental counter offered the exact same car at the same price. You'd just grab whichever line was shortest.
PAIN: Real lots aren't like that. A cheap subcompact is perfect for a solo errand but miserable for moving a family of six; a luxury SUV is overkill (and overpriced) for a quick grocery run. Pick wrong and you either can't fit the load or bleed money.
MAPPING: GPU providers are the rental lot. Vast.ai / RunPod are the cheap subcompact — great for dev and experiments. GCP / AWS are the mid-size sedan your company already has an account with. Lambda / CoreWeave are the heavy-duty haulers for real production throughput. Match the vehicle to the trip.
Read the comparison in 3 lenses
- Cheapest & fastVast.ai / RunPod RTX 3090: ~$0.20–0.22/hr, ~80 tok/s. Best for dev, spiky experiments.
- Native to your stackGCP T4 (~$0.35) or AWS g4dn (~$0.53): ~40 tok/s. Best if your team already lives there.
- Production throughputLambda A10 (~$0.60, ~100 tok/s) or CoreWeave A100 (~$2.21, ~200 tok/s).
| Provider | ~$/hr | Speed | Best for |
|---|---|---|---|
| Vast.ai 3090 | 0.20 | ~80 | Dev |
| GCP T4 | 0.35 | ~40 | GCP teams |
| AWS g4dn | 0.53 | ~40 | AWS teams |
| Lambda A10 | 0.60 | ~100 | Production |
| CoreWeave A100 | 2.21 | ~200 | High-throughput |
Which provider should I rent?
IF just experimenting / on a budget: → Vast.ai or RunPod (3090 spot) IF team already uses GCP or AWS: → stay native: GCP T4 / AWS g4dn IF steady production traffic: → Lambda A10 or CoreWeave A100 # also weigh: token volume vs a managed # per-token API (see Concept 3)
Rough crossover: a T4 at 8 hr/day is ~$56/mo — stop the VM when idle or the meter keeps running.
Misconceptions
Pick a provider by matching cost, speed, and stack-fit to the job — not by the cheapest headline rate.
Prices change constantly; always check the current pricing page, and stop idle VMs.
Someone else runs the GPU for you
You don't have to run a VM at all. Providers like Groq, Together AI, and Fireworks host open-source models and expose them through the same OpenAI-compatible API. You swap the URL and hand over a real API key instead of "ollama" — that's it.
Zero infra to manage, free tiers for development, and specialists like Groq deliver ~50 ms first-token latency on custom hardware. The price is per-token billing and shared rate limits instead of a flat hourly VM.
Owning a car vs. calling a taxi
BEFORE: Self-hosting a GPU VM is owning a car. Total control, but you buy it, park it, insure it, and it depreciates whether you drive or not.
PAIN: For occasional or bursty trips, ownership is wasteful — the car sits idle burning money, and you're on the hook for maintenance you never wanted.
MAPPING: A managed API is a taxi. You pay only per ride (per token), someone else owns and services the fleet, and a premium service (Groq) shows up almost instantly. You give up control of the vehicle and accept a meter — but for many trips that's exactly the right trade.
Swapping to a managed provider
- Sign up & get a keyCreate an account, grab an API key, store it in an env var — never in code.
- Swap the base_urlPoint the same OpenAI client at the provider's endpoint instead of localhost.
- Use the real keyPass the provider key in place of the
"ollama"placeholder. - Fix the model nameEach provider names models differently — check their docs for the exact string.
Groq ~50 ms TTFT, Together / Fireworks ~150–200 ms — all via the same SDK.
Managed API or self-hosted?
IF data may leave your infra AND usage is bursty / early dev: → managed API (Groq / Together / Fireworks) IF you need the fastest latency, free: → Groq (LPU hardware, ~50ms) IF data must stay in-house (HIPAA/GDPR) OR token volume is very high: → self-host Ollama on a VM # crossover ~2-5M tokens/month
Below ~2–5M tokens/month, per-token APIs win; above it, the flat VM rate is cheaper.
Misconceptions
base_url, the API key, and the model-name string change.Managed hosted APIs (Groq, Together, Fireworks) are drop-in Ollama replacements — no VM, same SDK, real key.
Choose managed for bursty dev and speed; self-host for privacy and high, steady volume.
One dial controls every backend
With four possible backends (local Ollama, Groq, Together, Fireworks), you don't want base_url and key lookups scattered across your code. Centralise them in a single factory — a LocalModelClient that reads one env var, LOCAL_MODEL_PROVIDER, and returns a configured client plus that provider's default model name.
Now switching every agent in the app from Ollama to Groq is one env var, not a code sweep. The factory hides the URL, the key handling, and the provider-specific model string behind a single call.
A universal power adapter
BEFORE: Imagine every country's wall socket needed you to rewire your laptop charger by hand before you could plug in.
PAIN: You'd carry a box of loose plugs, re-solder at each border, and one wrong wire fries the device. Every new country means touching the hardware again — error-prone and slow.
MAPPING: The wrapper is a universal travel adapter. You flip one selector to the country (set LOCAL_MODEL_PROVIDER) and the same charger works everywhere. Your agents plug into one socket; the adapter quietly routes power from Ollama, Groq, or Together — no rewiring per provider.
Inside the factory
- Read the providerTake the name from
LOCAL_MODEL_PROVIDER, defaulting toollama. - Look up its configEach provider has a stored base URL and a default model name.
- Validate & fetch the keyReject unknown providers; pull the API key from its env var, erroring early if missing.
- Return client + configHand back a ready OpenAI client and the config so callers use the right model.
Pseudocode
CONFIGS = { "ollama": (localhost_url, "mistral"), "groq": (groq_url, "llama-3.3-70b"), "together": (together_url, "Mistral-7B"), } FUNCTION create(provider = null): name = provider OR env("LOCAL_MODEL_PROVIDER", "ollama") IF name NOT IN CONFIGS: FAIL loudly url, model = CONFIGS[name] key = "ollama" IF name=="ollama" ELSE require_env(name + "_API_KEY") RETURN client(url, key), model
Misconceptions
LocalModelClient, you change one env var and every agent follows — no code edits, no scattered URLs.mistral on Ollama is mistralai/Mistral-7B-Instruct-v0.2 on Together. That's why the factory returns the provider's default model alongside the client.A provider-agnostic factory turns backend choice into one env var, returning both the client and the correct model name.
Centralise URL, key, and model lookups once; every agent inherits the switch for free.
Test the core insight
One question per concept. Tap to reveal the answer.
localhost:11434?localhost:11434 through the encrypted SSH channel to the VM's Ollama. Your code still points at localhost — that's the whole point of the one-env-var promise.LocalModelClient.create(). How do you make CI use Groq instead of Ollama?LOCAL_MODEL_PROVIDER=groq and GROQ_API_KEY=<key>. The factory reads the provider, returns a Groq client and Groq's default model. Every agent follows the single dial.Open the full module on desktop
The desktop version walks you through provisioning a GCP T4 VM and an AWS EC2 instance with Ollama as a systemd service, connecting over an SSH tunnel, wiring up managed APIs, and building the full LocalModelClient wrapper — in Python and Node, with a live cost estimator.
Module 23 of 24 · Open Source Track · Production & Deployment