DEV Community

John
John

Posted on

Is Self-Hosting Ollama Cheaper Than the OpenAI API? Real Private Cloud LLM Costs for Small Agencies

For most small agencies, the OpenAI API is cheaper until client workloads become steady and predictable. A self-hosted Ollama server costs about the same whether it handles ten requests or ten thousand, so it only pays off when you keep the GPU busy, when a small open model is good enough for the task, or when a client contract bars sending data to a third party. If your usage is low or comes in bursts, paying per token wins. If it is sustained, or confidentiality matters, an Ollama server on dedicated hardware becomes the better choice for both cost and compliance.

TL;DR:

  • Two-person studio with occasional chatbot prototypes: stay on the OpenAI API, because a few hundred requests a month will never repay a GPU server.
  • Ten-person agency running summarisation and tagging pipelines for several clients: move those batch jobs to Ollama with an 8B-class model, because steady volume on a fixed-cost box drives the cost per request down.
  • Agency serving legal, medical or public-sector clients: self-host Ollama on dedicated hardware, because a contract clause forbidding third-party processors outweighs any per-token saving.
  • Agency whose clients expect frontier-level reasoning and coding quality: keep those tasks on the OpenAI API, because open models that fit in 24 GB of VRAM still trail on the hardest prompts.
  • Agency with a mix of routine and hard workloads: run a hybrid, with Ollama for high-volume routine work and the API for difficult prompts, because the OpenAI-compatible endpoint makes routing between them a configuration change.

The central tradeoff: with Ollama you pay a fixed monthly cost for capacity whether you use it or not, while the OpenAI API charges a variable cost only for what you actually use.


Table of contents


What are you actually paying for with the OpenAI API?

The OpenAI API bills by the token, not by the server. That makes it simple to start with and hard to predict. Before you compare it with Ollama, you need to know which parts of an agency workload actually make the invoice grow.

  • Input and output tokens, billed separately: Prices are quoted per 1 million tokens, and output tokens cost several times more than input tokens on every current model. A client chatbot that writes long answers costs far more than a classifier that returns one word, even when both receive the same prompt.
  • Model tier: The flagship models and the "mini" models can differ in price by more than an order of magnitude. Many agency tasks, such as tagging, extraction and short summaries, run well on the cheap tier. That narrows the gap any self-hosted setup has to beat.
  • Context you resend on every call: Chat history, system prompts and retrieved documents are billed again with each request. A RAG assistant that adds 4,000 tokens of context to every question pays for those 4,000 tokens every time. Prompt caching discounts repeated prefixes, but it only applies when the prefix is identical.
  • Batch discounts: The Batch API charges 50% less in exchange for results within 24 hours. Overnight report generation and bulk content jobs can therefore cost half as much on the API. This is the workload profile where Ollama looks strongest, so the discount narrows its advantage.
  • Rate limits and usage tiers: New accounts start at low request and token limits, which rise with cumulative spend. An agency that onboards a busy client can hit a limit before it hits a budget.
  • Zero idle cost: When no requests arrive, you pay nothing. No server you own can match that.

What does a self-hosted Ollama server cost per month?

Ollama itself is free. It is open source under the MIT licence, ships as the ollama/ollama Docker image and charges nothing per token. Your monthly cost is the hardware it runs on, the electricity or rent for that hardware, and your own time. Which of these dominates depends on where the server lives.

Hosting option What you pay each month What drives the bill
Rented dedicated GPU server A flat monthly rent, with bandwidth usually included The GPU model and its VRAM. A 24 GB card costs far more to rent than a 16 GB card.
Hourly cloud GPU instance Every hour the instance is running, plus storage and egress Uptime. If you leave it running 24/7 for 720 hours, the hourly rate becomes your largest cost line.
Home server with your own GPU Electricity, plus the purchase price spread over the card's lifetime Power draw. A 350 W card at full load uses about 252 kWh over 720 hours.
NAS or small VPS, CPU only Little or nothing beyond what you already pay Speed. Small models run, but slowly enough that interactive client use suffers.
Managed personal cloud The provider's plan for a dedicated server Whether the hardware has the VRAM your chosen model needs.

Yundera is a managed Personal Cloud Server, built on CasaOS, that runs self-hosted apps as Docker containers on a server dedicated to the user. It sits in this list beside a self-managed VPS, a home server and a NAS.

The key fact in this table is that almost every row is a fixed cost. You pay the same whether the model answers 50 prompts or 50,000. The OpenAI API scales from zero. Ollama does not, unless you shut down an hourly instance yourself.


Which open models fit in 8 GB, 16 GB, 24 GB and 48 GB of VRAM?

VRAM sets the ceiling on what your Ollama server can do, and it is the main thing you pay for when you rent or buy a GPU. A useful rule of thumb: at the default 4-bit quantization, a model needs a little over half a gigabyte of memory per billion parameters. On top of that comes the context window, which also uses memory. Once you run out of VRAM, Ollama moves layers to the CPU and speed drops sharply.

  • 8 GB tier: Fits the 7B to 8B class, such as Llama 3.1 8B, Qwen 2.5 7B or Mistral 7B. These download at roughly 4 to 5 GB. They handle classification, extraction, short summaries and simple chat well, and they cover a large share of routine agency work.
  • 16 GB tier: Adds the 12B to 14B class, such as Qwen 2.5 14B or Gemma 3 12B, with room for a longer context. Reasoning and instruction-following improve noticeably. This tier often hits the best balance between cost and quality.
  • 24 GB tier: Fits the 27B to 32B class, such as Gemma 3 27B or Qwen 2.5 32B, at around 17 to 20 GB. This is the point where open models become credible for drafting client-facing copy and multi-step tasks.
  • 48 GB tier: Opens up 70B models such as Llama 3.3 70B, which takes around 43 GB at 4-bit. This tier is usually two cards or one workstation card, and the rent jumps accordingly.
  • Context is not free: Raising num_ctx to 32,768 tokens can push a model that fits into one that spills over. Run ollama ps after loading. It shows whether the model sits 100% on the GPU or is split with the CPU.

Where is the break-even point between Ollama and per-token pricing?

The break-even calculation fits in one line. Divide your fixed monthly server cost by the blended API price per million tokens for the model you would otherwise use. The result is the number of millions of tokens a month you must process before Ollama costs less. Below that volume, the API wins. Above it, every extra token on your own server is close to free.

  • Use your real token mix: Take input and output volumes from your OpenAI usage dashboard rather than guessing. A workload with a lot of output reaches break-even sooner, because output tokens are the expensive part of the API bill.
  • Compare against the right model: If an 8B model on Ollama replaces a "mini" API model, the break-even volume is high, because the API side is already cheap. If a 32B model replaces flagship calls, break-even comes much earlier.
  • Check the throughput ceiling: A fixed server can only produce so much. At a hypothetical 50 tokens per second, running nonstop for 30 days produces 129.6 million tokens. If your break-even point is above what your card can physically generate, self-hosting never pays.
  • Factor in utilisation, not capacity: Agency traffic follows office hours. A GPU that sits idle 16 hours a day delivers only a third of its theoretical output, which pushes your effective cost per token up threefold.
  • Price the hosting option honestly: The fixed cost should be the full monthly figure for wherever the server runs, whether that is a rented GPU box, a home server, a NAS or a managed personal cloud such as Yundera, plus your maintenance hours.

If the result lands near your current volume, treat it as a tie and let privacy requirements decide.


How much does quantization change cost and output quality?

Quantization is the lever that decides which hardware tier you pay for. Ollama's default tags pull 4-bit Q4_K_M builds. You can request other levels explicitly, for example ollama pull llama3.1:8b-instruct-q8_0. Each step up in precision takes more VRAM, and more VRAM means a more expensive card or rental.

Quantization Approx. memory for an 8B model Quality tradeoff
FP16 (unquantized) About 16 GB The reference quality, but it doubles your hardware cost for gains most clients will never notice
Q8_0 About 8.5 GB Nearly indistinguishable from FP16 for most tasks, a safe choice when VRAM is available
Q5_K_M About 5.7 GB A small, mostly invisible loss, with room left over for a longer context
Q4_K_M (default) About 4.9 GB Small loss, most visible in maths, code and strict output formats
Q3 and Q2 levels Below 4 GB Noticeable drift, broken JSON and weaker instruction-following. Avoid for client work.

These memory figures follow from simple arithmetic: FP16 stores 2 bytes per parameter, and the quantized levels store a fraction of that. They do not include the context window.

For cost, the practical question is which comes first: a larger model or a higher-precision small one. On a fixed 24 GB budget, a 27B or 32B model at Q4 usually beats an 8B model at FP16 on reasoning and writing. That makes quantization mostly a way to fit a bigger model on the card you already pay for. The exception is structured output. If a client pipeline depends on valid JSON or exact field extraction, test Q4 against Q8 on 100 or so real samples before you commit. A higher failure rate quietly erodes the savings, because every retry uses GPU time.


How many clients can one Ollama server handle at the same time?

Concurrency is where the fixed cost has to prove itself. One GPU shared across five client projects costs a fifth as much per client, but only if requests do not pile up behind each other. Ollama exposes a few environment variables that set these limits, and they are worth setting deliberately instead of trusting the defaults.

  • OLLAMA_NUM_PARALLEL: Sets how many requests one loaded model serves at the same time. The default is chosen automatically from available memory, usually 4 or 1. Each parallel slot reserves its own context, so 4 slots at num_ctx 8,192 take memory for 32,768 tokens of context. That can push a 24 GB card over its limit.
  • OLLAMA_MAX_LOADED_MODELS: Controls how many different models stay in memory at once. If client A uses Qwen 2.5 14B and client B uses Llama 3.1 8B, both must fit in memory together, or Ollama unloads one and reloads it on the next request. That reload costs seconds every time.
  • OLLAMA_MAX_QUEUE: Requests beyond the parallel slots wait in a queue that defaults to 512 entries. Past that, Ollama returns an error. A queue that is full during office hours tells you the server is too small for the number of clients on it.
  • OLLAMA_KEEP_ALIVE: Models unload after 5 minutes of inactivity by default. Setting it to 24h for the main model avoids cold starts for clients who send requests occasionally, at the price of VRAM that stays permanently allocated.
  • Standardise on one model: The cheapest way to add more clients is to agree on a single shared model. Five projects on one 14B model scale far better than five projects on five different models.

Rented GPU server, home server or managed personal cloud: where should Ollama run?

Once you know the monthly cost of each option, the decision comes down to operations: who exposes the API safely, who fixes the GPU driver, and how quickly you can move up a tier. Ollama listens on 127.0.0.1:11434 by default and has no built-in authentication. So wherever it runs, something has to stand between it and the internet.

  • Rented GPU server: You get a data-centre network connection, a fixed address and hardware you can swap for a bigger card by changing your order. You also take on the whole stack: the NVIDIA driver, the NVIDIA Container Toolkit so that docker run --gpus=all ollama/ollama can see the card, a reverse proxy, TLS certificates and firewall rules.
  • Home or office server: You own the GPU outright and can reuse a workstation card you already have. The weak points are the connection: residential upload bandwidth, carrier-grade NAT that blocks inbound traffic, and a single power circuit. A home server suits internal agency tooling better than client-facing endpoints that must not go down.
  • Self-managed VPS without a GPU: Useful as a gateway. It runs the reverse proxy and API keys in front of a GPU box somewhere else. On its own it is only realistic for the 1B to 3B class.
  • Managed personal cloud: On an option such as Yundera, Ollama installs from an app store in one click instead of a hand-written compose file. It is reachable on a public HTTPS subdomain through NSL.SH mesh routing, with no static IP, port forwarding or manual certificate setup. Model size limits still depend on the memory of the dedicated server behind it.
  • Hybrid split: Many agencies keep the GPU at home or in a rack and put the authenticated public endpoint on a separate host. This keeps the expensive hardware off the open internet.

The hidden costs: maintenance hours, monitoring and model updates

The cost of a GPU server is easy to see. The hours spent keeping it healthy are not, and for a small agency those hours are billed at the same rate as client work. Multiply the time each task below takes in a typical month by your internal hourly rate, and add the result to the fixed cost before you compare it with an API invoice.

Task On the OpenAI API On self-hosted Ollama
Runtime updates None, handled by the provider Run docker pull ollama/ollama, restart, and check that clients still get correct responses
Model updates Model versions are pinned or retired on a published schedule Run ollama pull for new tags, then re-test prompts, because a new tag under the same name can change output
GPU drivers and CUDA Not your concern Driver upgrades can break the container toolkit. Pin versions and test before rebooting.
Monitoring Usage dashboard and status page Your own health checks on /api/version and /api/ps, plus nvidia-smi for temperature and memory
Security API key rotation OS patches, reverse proxy, authentication, firewall rules and log review
Incident response Wait for the provider to fix it You are on call. A dead fan on Friday night is your weekend.

Two items deserve special attention. First, model updates quietly change behaviour. If a client's extraction pipeline depends on a specific output format, pin the exact tag or digest and keep a regression set of real prompts. Second, someone has to own the pager. Even a modest 4 hours a month of upkeep, priced at a billable rate, can match the rent of an entry-level GPU server. Leave it out of the comparison and the break-even point you calculate is wrong.


Does the OpenAI-compatible endpoint make switching from the API painless?

Mostly yes, and this is a large part of why the cost comparison is worth doing at all. Ollama serves /v1/chat/completions, /v1/completions, /v1/embeddings and /v1/models in the OpenAI format. In most codebases the switch means changing two values: point base_url at http://your-host:11434/v1 and set api_key to any placeholder string, because the official SDKs require one and Ollama ignores it. The remaining friction sits in the details.

  • Model names: gpt-4o-mini becomes qwen2.5:14b or whatever tag you pulled. Keep the model name in configuration rather than in code, so each client project can be routed separately.
  • Context length: The compatible endpoint does not accept a per-request num_ctx. You set it server-wide with OLLAMA_CONTEXT_LENGTH or bake it into a custom model with a Modelfile. Prompts that fit easily in the API can be silently truncated on Ollama.
  • Tool calling and structured output: These work, but only with models trained for them, and reliability varies by model and quantization. Function-calling flows need the same regression testing as extraction pipelines.
  • Missing platform features: The Assistants API, hosted file search, fine-tuning jobs and the Batch API have no Ollama equivalent. Code built on these needs real rework, not a URL change.
  • Embeddings are not interchangeable: Vectors from nomic-embed-text and from OpenAI's embedding models live in different spaces. Switching means re-embedding every document in a client's vector store.
  • Token counts differ: Each model family has its own tokenizer, so token-based quotas and per-client billing reports need recalibrating.

Done carefully, a hybrid setup becomes a routing decision rather than a rewrite.


Which client workloads still belong on the OpenAI API?

A cost comparison only holds when both options can do the job. Some workloads either need capabilities no card in the 24 GB to 48 GB range delivers, or have a usage pattern that a fixed-cost server will never pay back. Route these to the API and stop trying to bend Ollama around them.

  • Frontier reasoning and complex code: Multi-file refactors, long agentic chains and difficult analytical prompts still separate the flagship API models from the open models that fit on one or two cards. If a client is paying for top-tier quality, a cheaper wrong answer is not a saving.
  • Very long context: API models accept contexts of 128,000 tokens and more. On Ollama, context memory grows with every token, so feeding a 300-page contract into a 32B model on a 24 GB card is not realistic. Retrieval can help, but it adds engineering hours.
  • Spiky or seasonal traffic: A product launch that sends 50 times the normal traffic for one week calls for elastic capacity. Sizing a GPU for the peak means paying for idle hardware the other 51 weeks.
  • Features Ollama does not provide: Real-time voice, speech synthesis, image generation and the hosted Assistants tooling have no direct Ollama equivalent. Vision input is covered by models such as Gemma 3 and LLaVA, but image output is not.
  • Prototypes and pitches: A proof of concept that might be abandoned in 3 weeks should not commit you to a server. Build it against the API, measure real token volume, and move it only once the numbers justify a move.
  • Clients with strict SLAs: If the contract promises an uptime figure, check whether one self-managed box can honestly meet it. A second server for failover doubles the fixed cost.

Isolating clients on a shared Ollama server without leaking data

Ollama was built as a single-user tool. It has no accounts, no API keys and no tenant boundaries. Any process that can reach port 11434 can use every loaded model. It can also call the native management endpoints: /api/pull, /api/create and /api/delete. Sharing one GPU across clients is what makes the costs work, so isolation has to be added around Ollama rather than inside it.

Approach Isolation level Cost impact
One shared instance behind an authenticating proxy Logical only: separate keys, shared process and memory Lowest. One GPU serves every client.
Separate Ollama container per client, same GPU Separate processes and model stores, shared card Moderate. Each container loads its own model copy into VRAM.
Dedicated GPU per client using CUDA_VISIBLE_DEVICES Separate hardware inside one machine High. Needs a multi-GPU chassis.
Separate server per client Full physical separation Highest. The fixed cost is multiplied by the number of clients.

For most agencies, the first row is the realistic choice, and the proxy is what makes it safe. A gateway such as LiteLLM can issue a separate virtual key to each client and track spend for each key. Caddy or nginx can simply check a bearer token. Either way, the proxy should forward only /v1/chat/completions, /v1/embeddings and /v1/models, and block the management routes, so that one client cannot delete a model that another depends on.

Ollama does not store prompts or conversations between requests, which helps. Debug logging does not offer the same protection. Leave OLLAMA_DEBUG off in production, and make sure the proxy's access logs record keys and token counts, not request bodies. When a contract requires physical separation, only the last row satisfies it.


Data sovereignty and client contracts: why hosting location changes the maths

For some clients, the cost comparison ends before it starts. A law firm, a clinic or a public body may contractually ban sending data to a third-party processor, or demand to know exactly where each prompt is processed. The OpenAI API does not train on API data by default, and it offers EU data residency and zero-retention options to eligible customers. It still adds a processor to your GDPR Article 28 chain, and standard API traffic can be kept for up to 30 days for abuse monitoring. Self-hosted Ollama removes that link entirely.

Advantages of keeping inference on your own hardware:

  • No sub-processor to disclose: Prompts never leave a machine you control, so the client's data processing agreement stays short.
  • Location you can name: You pick the country and the data centre. You can also run inference on a home server, a NAS, a self-managed VPS or a dedicated server such as Yundera, where the data stays on that server rather than in a shared multi-tenant service.
  • Retention you define: Ollama keeps no prompt history, so the only logs are the ones you configure.
  • Contracts you can win: Some tenders are only open to bidders who can prove that inference happens on premises or in a named jurisdiction.

Checklist before you promise sovereignty to a client:

  • Disk encryption: The model store and any RAG documents sit on encrypted volumes.
  • Proxy logging: Access logs record metadata only, never request bodies.
  • Backups: Backup destinations are in the same jurisdiction as the server.
  • Embeddings: Embeddings are also generated locally, not through a cloud endpoint.
  • Hosting provider: The provider's own access rights to the hardware are written down.

Once a contract requires these guarantees, the API's lower cost at low volume no longer counts, because the API cannot meet the requirement.


What does the bill look like over 3 years?

A one-month snapshot flatters whichever option you happen to be looking at. Over 36 months, the cost curves of the API and of self-hosted Ollama take different shapes. You need to model the shape, not only the starting point.

  • Owned hardware front-loads the cost: When you buy a GPU for a home or office server, most of the 3-year cost lands in month 1. Years 2 and 3 cost only electricity and your time. Spread the purchase over 36 months, then subtract the card's likely resale value at the end, because used workstation GPUs keep a share of their value.
  • Rented servers stay flat: Rent is the same in month 1 and month 36. You can upgrade mid-contract when a client needs a bigger model, but each step up resets the monthly cost to a higher level for the rest of the period.
  • API spend tracks your growth: If your client roster doubles, your token bill roughly doubles with it. The API is the only option where success directly raises costs, and it is also the only one where losing a client lowers them.
  • Per-token prices tend to fall: Over the past few years, OpenAI has repeatedly cut the price for a given level of capability, and cheaper "mini" tiers keep appearing. If your model assumes today's API prices for 36 months, it probably overstates the API's cost.
  • Open models improve on the same card: The reverse also holds. Each generation of open models has delivered better quality at the same parameter count. A 24 GB card bought in year 1 runs noticeably stronger models in year 3, without any further spending.
  • Maintenance hours accumulate: Multiply your monthly upkeep by 36. Over three years, it can rival what you pay for the hardware.

Run the three curves side by side in one spreadsheet before you sign a 3-year commitment.


Which setup fits your agency?

The right answer depends less on the size of your agency than on how steady your volume is, how sensitive your clients' data is, and how much quality they need. Find the row closest to your situation.

Profile Recommendation Main reason
Freelancer building occasional AI features OpenAI API only Volume never reaches break-even, and idle hours cost nothing
Studio running prototypes and pitches OpenAI API, then measure Real token logs decide later moves better than estimates do
Agency with steady batch jobs such as tagging and summaries Ollama on a 16 GB card An 8B to 14B model handles the work at a fixed cost
Agency hosting chat assistants for 5 or more clients Shared Ollama behind a key-issuing proxy One shared model spreads the fixed cost across clients
Agency serving legal, health or public-sector clients Ollama on dedicated hardware in a named jurisdiction The contract rules out third-party processors
Agency selling top-tier coding or reasoning OpenAI API for those tasks Open models that fit on 24 GB still trail on the hardest prompts
Agency with mixed workloads Hybrid routing through the /v1 endpoint Each task runs on the cheaper option that meets its quality bar

Next steps:

API first:

  1. Export 3 months of usage from the OpenAI dashboard.
  2. Tag each request by client and task.
  3. Recalculate break-even every quarter.

Self-hosted Ollama:

  1. Pull your candidate model and test it on 100 real prompts.
  2. Set OLLAMA_NUM_PARALLEL and OLLAMA_KEEP_ALIVE.
  3. Put an authenticating proxy in front before onboarding any client.

Hybrid:

  1. Move one high-volume routine task to Ollama.
  2. Compare output quality and cost for 30 days.
  3. Expand only if both hold.

Key points

Self-hosted Ollama only beats the OpenAI API on cost when a fixed-price GPU stays busy with work a smaller open model can do, or when a contract makes cost a secondary concern.

Point Details
Break-even Divide the monthly server cost, including your maintenance hours, by the blended API price per million tokens. Below that volume, the API is cheaper.
Hardware tier VRAM decides the model. 16 GB covers 14B models and 24 GB covers 27B to 32B at Q4, so rent or buy for the model you need.
Utilisation A GPU busy only during office hours costs about three times as much per token as one running all day.
Isolation Ollama has no API keys. Put a proxy in front that issues a key per client and blocks /api/delete and /api/pull.
Sovereignty Self-hosting removes a processor from the client's data chain, which can matter more than any per-token saving.
Hybrid The /v1 endpoint lets you send each task to whichever option is cheapest at the quality it needs.

What hands-on experience actually shows

In our experience, agencies tend to overestimate their token volume and underestimate their own hours. The first month on a GPU server feels like a bargain. By the third month, someone has spent an afternoon on a driver upgrade and another re-testing prompts after a model tag changed.

The API deserves real credit. It costs nothing when idle, it scales without warning, and its best models still produce answers that open models on a 24 GB card cannot match on hard prompts. For a small agency without a dedicated ops person, that convenience is worth paying for.

Where Ollama clearly wins is narrower but solid: repetitive, high-volume work such as tagging, extraction and summaries on a mid-sized model, and clients whose contracts rule out third-party processing. On those workloads the fixed cost really does spread thin, and the privacy argument sells itself.

Our recommendation is to stay on the API until your own logs prove a steady workload. Then move that one workload to Ollama, measure it for 30 days, and let the numbers, not the enthusiasm, decide what moves next.

Top comments (0)