Module 6: The AI API Ecosystem
3. Open-Source vs Proprietary: Trade-Offs and When to Use Each One
Description
One of the most important decisions as an AI Engineer: Use proprietary models (GPT-4, Claude via API) or open-source ones (Llama 3, Mistral self-hosted)?
What you'll learn:
- The differences between proprietary and open-source.
- The trade-offs (control vs convenience, cost vs capability).
- When to use each one.
Proprietary (GPT-4, Claude, Gemini)
Characteristics:
- Access via API: You pay per use (per token).
- The weights are NOT public: You can't download the model.
- Controlled by the provider: OpenAI, Anthropic, Google.
Advantages:
- ✅ State-of-the-art: The most capable models (GPT-4 > Llama 3 at reasoning).
- ✅ No infrastructure: You don't need GPUs.
- ✅ Updates: The model improves without you doing anything.
- ✅ Automatic scaling: 1 request or 1M requests → the API handles scaling.
Disadvantages:
- ❌ Cost per use: High volume → expensive.
- ❌ Dependence: If the API goes down, your app goes down.
- ❌ Privacy: You send data to external servers.
- ❌ No control: You can't modify the model, fine-tuning is limited.
Open-Source (Llama 3, Mistral)
Characteristics:
- Public weights: You can download the model.
- Self-hosted: You run it on your own servers/GPUs.
- A permissive license: Commercial use is allowed.
Advantages:
- ✅ Free per request: You only pay for hosting (a fixed cost).
- ✅ Privacy: Data doesn't leave your infrastructure.
- ✅ Total control: You can fine-tune without restrictions.
- ✅ No dependence: If you want to change provider, you only change the model (not the API).
Disadvantages:
- ❌ It requires infrastructure: Expensive GPUs (A100: $1-3/hour, H100: $3-5/hour).
- ❌ Maintenance: You handle updates, scaling, monitoring.
- ❌ Less capable: Llama 3 (70B) < GPT-4 at reasoning (but 400B is competitive).
Comparison: Cloud API vs Self-Hosted
| Aspect | Cloud API (GPT-4) | Self-Hosted (Llama 3) |
|---|---|---|
| Cost (low volume) | Low ($10-100/month) | High ($500-2,000/month for a GPU) |
| Cost (high volume) | High ($5K-50K/month) | Medium ($500-2,000/month, a fixed GPU cost) |
| Setup | 5 minutes | 1-3 days |
| Maintenance | None | High (updates, monitoring) |
| Privacy | Low (data goes to the provider) | High (data stays in your infrastructure) |
| Capability | Very high (GPT-4) | High (Llama 400B) |
| Latency | Medium (an API call) | Low (local) or high (if the GPU is saturated) |
When to Use Each One
Use a Cloud API (OpenAI, Anthropic) if:
- Low volume: <100K requests/month → APIs are cheaper.
- A prototype/MVP: You need to launch fast.
- No infrastructure team: You don't have DevOps to maintain GPUs.
- You need state-of-the-art: GPT-4 is better than Llama 3 (70B).
Use Open-Source (Llama 3, Mistral self-hosted) if:
- High volume: >1M requests/month → self-hosted is cheaper.
- Critical privacy: Sensitive data (HIPAA, GDPR) can't leave your infrastructure.
- Total control: You want to fine-tune without restrictions.
- A predictable cost: You prefer a fixed cost (GPU hosting) vs a variable one (an API per token).
Real Use Cases
A startup (MVP)
Context: A startup with a $1K/month budget, a support chatbot.
Decision: A cloud API (GPT-3.5 or Claude Haiku).
Why:
- Low volume at the start → APIs are cheaper than GPU hosting.
- Fast setup → launch in days, not weeks.
A company (production, high volume)
Context: A company with 10M requests/month, an internal chatbot.
Decision: Self-hosted (Llama 3 70B).
Why:
- High volume → APIs cost $50K-150K/month. Self-hosted: $2K-5K/month (GPU hosting) → a massive saving.
- Internal data → privacy.
A health startup (HIPAA compliance)
Context: A health startup with patient data.
Decision: Self-hosted (Llama 3).
Why:
- HIPAA compliance → data can't be sent to external APIs.
- Self-hosted → total control, privacy.
A Hybrid Strategy (the Best of Both Worlds)
Many companies use both:
- A cloud API (GPT-4): Complex tasks, low volume.
- Self-hosted (Llama 3): Simple tasks, high volume, sensitive data.
Example:
- A support chatbot: Llama 3 (self-hosted) for simple FAQs.
- Escalation to an expert: GPT-4 (API) for complex cases.
Advantage: Optimizing cost (90% of requests use Llama 3, only 10% use GPT-4).
Open-Source Model Licenses
Llama 3
License: The Llama 3 Community License.
It allows:
- ✅ Commercial use.
- ✅ Fine-tuning.
- ✅ Redistribution (with restrictions).
Restriction: If your app has >700M users/month, you need a special license from Meta.
Mistral
License: Apache 2.0.
It allows:
- ✅ Commercial use without restrictions.
- ✅ Modification.
- ✅ Redistribution.
Why this matters for an AI Engineer
1. Evaluating costs at scale
Low volume (a startup): APIs are better.
High volume (a company): Self-hosted is better (a 10-50× saving).
2. Compliance
HIPAA, GDPR, sensitive data: Self-hosted is the only viable option.
Summary
Proprietary (GPT-4, Claude):
- More capable, no infrastructure, but expensive at scale and without privacy.
Open-source (Llama 3, Mistral):
- Free per request, privacy, control, but it requires infrastructure.
When to use each one:
- API: Low volume, an MVP, when you need state-of-the-art.
- Self-hosted: High volume, privacy, total control.
A hybrid strategy: The best of both (an API for complex, self-hosted for simple).
Next step: Lesson 04: Pricing and Token Economics — How you're charged, cost optimization.