Recommended resources
The freely available resources this lesson will direct you to.
Hello! Welcome to the final module of our course, focusing on LLM Operations and Security.
In the last lesson, you successfully built and ran an MCP server locally. That stdio transport mechanism is perfect for development and testing, but for a real-world application, you need a more robust and scalable deployment strategy. This brings us to a fundamental decision in building any LLM-powered system.
This lesson addresses the learning outcome: Describe common LLM deployment options: API-based vs. self-hosted. We will explore these two primary models, analyzing the crucial trade-offs in terms of cost, performance, privacy, and operational complexity. By the end, you'll have a clear framework for deciding which approach is right for a given project.
1. The Two Main Deployment Models
At a high level, deploying an LLM means choosing between "renting" access to a model or "owning" the entire stack.
-
API-based (or Cloud) Deployment: Your application makes a network request to an endpoint managed by a provider like OpenAI, Anthropic, or Google. You send a prompt and receive a completion, paying for what you use. The provider manages the model, hardware, and infrastructure.
-
Self-hosted Deployment: You download an open-weight model (like Llama 3 or Mistral) and run it on infrastructure you control. This could be a server in your own data center or, more commonly, virtual machines with GPUs that you manage in a cloud environment like AWS, GCP, or Azure.
To get a formal definition of these approaches and see examples of the services and models in each category, the following resource is a great starting point.
Self-Hosted vs Cloud LLMs: Complete Comparison Guide 2025
This article, 'Self-Hosted vs Cloud LLMs: Complete Comparison Guide 2025', provides clear definitions and architectural overviews for both deployment models.
Please read the sections 'What is a Self-Hosted LLM?' and 'What is a Cloud LLM?'. Pay attention to the descriptions of the technical architecture for each.
2. A Practical Decision Framework
Choosing between these two options involves weighing several factors. There is no single "best" answer; the right choice is highly context-dependent.
The following video presents an excellent decision tree that walks through the key questions you should ask when making this choice.
Local vs. Cloud LLMs/RAG - Let's FINALLY End this Debate
In 'Local vs. Cloud LLMs/RAG - Let's FINALLY End this Debate', the presenter offers a clear, step-by-step decision tree to guide your choice. This provides a great mental model for evaluating your project's needs.
Watch the segment from 03:06 to 09:14. Focus on the four main questions in the decision tree and the reasoning behind each suggested path.
As the video outlines, your decision process can be guided by these four critical questions:
- Is this a Proof of Concept (POC)? If you're experimenting or validating an idea, the speed and low setup cost of an API-based model are almost always preferable.
- Is your data sensitive? If you're handling confidential information, proprietary code, or data subject to regulations like HIPAA or GDPR, self-hosting is often the only viable option to ensure complete data privacy.
- Do you need the latest, most powerful model? The absolute state-of-the-art models (like GPT-4o or Claude 3.5 Sonnet) are typically only available via API. If your application's success depends on their cutting-edge reasoning capabilities, you'll need to use an API.
- Are you scaling to thousands of users? At low to medium scale, APIs are often cheaper due to generous free tiers and no hardware overhead. At very high scale, the per-token costs of an API can exceed the cost of running your own infrastructure, making self-hosting more economical.
3. A Deeper Dive into the Trade-offs
The decision tree gives us a high-level guide. Now, let's explore the trade-offs in more detail, which is essential for making an informed engineering and business decision.
This image provides a concise visual summary of the core pros and cons.

To understand the nuances behind these points, especially the "hidden costs" and operational complexities that you as a software engineer will face, the next resource is invaluable.
LLM Deployment Timeline: API Speed vs Self-Hosted Delays
The article 'LLM Deployment Timeline: API Speed vs Self-Hosted Delays' offers a professional perspective on the real-world challenges of self-hosting, such as GPU provisioning, framework selection, and integration delays.
Read the first three sections: 'Why API-Based LLM Deployment Delivers Immediate Value', 'Why Open Weight Models Look Simple But Deployment Isn't', and 'GPU Provisioning Delays'. This will give you a clear picture of the operational friction involved in self-hosting.
Let's synthesize these points into a direct comparison:
| Factor | API-Based (Cloud) | Self-Hosted |
|---|---|---|
| Cost | Low initial cost. Pay-per-use can become expensive at scale. Cost is predictable and easy to track per token. | High upfront hardware/infrastructure cost. Can be more cost-effective at high volume, but includes hidden costs (power, staff). |
| Performance & Quality | Access to state-of-the-art models. High throughput and low latency due to massive, optimized infrastructure. | Performance depends on your hardware. Models are powerful but often one step behind the frontier. Slower inference speed. |
| Privacy & Security | Major Con: Data is sent to a third-party provider. Risky for sensitive or regulated data. | Major Pro: Data never leaves your infrastructure. Full control and compliance. |
| Maintenance & Ops | Major Pro: Zero maintenance. The provider handles uptime, scaling, and model updates. | Major Con: Significant operational burden. You are responsible for provisioning, monitoring, scaling, and security. |
| Customization | Limited to what the API exposes (e.g., system prompts, temperature). Fine-tuning is often a separate, costly service. | Full control. You can fine-tune the model on your own data, modify its architecture, and control all parameters. |
| Development Velocity | Extremely fast. An engineer can integrate an API call in an afternoon. | Slow. Can be stalled by infrastructure procurement, framework decisions, and performance optimization cycles. |
4. Making Self-Hosting Concrete: The Role of Ollama
The idea of "self-hosting" can seem daunting. However, tools have emerged to drastically simplify the process. One of the most popular is Ollama. It packages open-weight models with an inference server into a single, easy-to-use tool.
The following video gives a great overview of what Ollama is and how it works.
What is Ollama? Running Local LLMs Made Simple
To understand how self-hosting works in practice, let's watch 'What is Ollama? Running Local LLMs Made Simple' from IBM Technology. It explains how tools like Ollama abstract away much of the underlying complexity.
Watch the segments from 00:44 to 02:43 and 05:02 to 06:01. Focus on how Ollama simplifies downloading and running models, and how it exposes the model as a local REST API.
In short, with a simple command like ollama run llama3, the tool downloads the model and starts a local web server. Your application can then interact with the LLM by making standard HTTP requests to http://localhost:11434, just like any other REST API. This pattern elegantly bridges the gap between running a model locally and the familiar API-based development experience.
5. The Best of Both Worlds: The Hybrid Approach
The choice is not always a strict binary. Many production systems adopt a hybrid approach, strategically using both API-based and self-hosted models.
For example, a system might:
- Route high-volume, low-sensitivity queries to a cost-effective self-hosted model.
- Route complex queries requiring advanced reasoning to a powerful API-based model like GPT-4o.
- Use a self-hosted model for processing all internal, confidential data.
This is often managed by an AI Gateway, an intermediary service that directs requests to the appropriate LLM provider based on a set of rules. This architecture provides flexibility and optimizes for cost, performance, and privacy simultaneously.

This hybrid strategy allows an organization to start fast with APIs and gradually transition workloads to self-hosted systems as the business case becomes clear, mitigating the risk of a large, all-or-nothing deployment effort.
Conclusion
You now have a comprehensive overview of the two primary LLM deployment options and a framework for choosing between them.
Key Takeaways:
- API-based deployment offers speed, simplicity, and access to frontier models, making it ideal for prototyping and applications without strict privacy needs. Its main drawbacks are data privacy concerns and potentially high costs at scale.
- Self-hosted deployment provides complete data privacy, control, and long-term cost savings at high volume. However, it requires significant upfront investment and operational expertise to manage the infrastructure.
- The decision hinges on a trade-off analysis of data sensitivity, scale, performance requirements, and development velocity.
- Tools like Ollama greatly simplify the process of running models locally by abstracting them behind a standard REST API.
- Hybrid models, often managed by an AI Gateway, offer a pragmatic solution that combines the strengths of both approaches.
Now that you understand the trade-offs of self-hosting, you might wonder how it's feasible to run these massive models on reasonable hardware. In our next lesson, we will dive into quantization, a critical technique for reducing model size and inference costs, making self-hosting a more practical reality.