Week 1–2
APIs & Ollama
One interface, many providers. Commercial APIs, free tiers, and local Ollama — all with the same patterns.
Pause & reflect
Before you read on, answer this in your head — or on paper:
You've run Ollama locally. Now you want to call GPT-4 or Claude from your app.
What do you think would change in your code? Same prompt, same response format — but the request goes somewhere else. What stays the same? What must change?
Most LLM APIs follow the same shape: messages (system, user, assistant), model name, temperature, and max_tokens. Ollama exposes the same pattern locally. Once you can call one, you can call any. Use LiteLLM for a unified interface. OpenRouter provides one API for many providers, including free tiers.
Provider comparison
| Provider | Best for | Cheapest model |
|---|---|---|
| Ollama | Local, free, no keys | Free (Llama 3.2, Mistral, etc.) |
| OpenAI | GPT-4, frontier quality | gpt-4.1-nano |
| Anthropic | Claude, long context | claude-3-haiku |
| OpenRouter | One API, many models | Free tiers (Llama, Mistral) |
| Google Gemini | Multimodal, free tier | gemini-1.5-flash |
| DeepSeek | Low cost, strong coding | deepseek-chat |
Test your understanding
Don't reveal yet. Think for ~30 seconds first — what would you try?
You want to switch from Ollama (local) to OpenAI (cloud) without rewriting your app. What's the simplest approach?
Check your understanding
How can you minimise API cost during the LLM course?
What is OpenRouter useful for?