Fasttrack· 02· 15 min
Providers: Same Code, Any Model
What you'll learn
- ▸Swap LLM providers without changing application code
- ▸Understand the provider abstraction that LangChain provides
- ▸Know when to use local models with Ollama

Click to zoom
Why provider-independence matters
When you build directly on a provider SDK like the OpenAI Python library, every function call, parameter name, and response format is specific to that provider. Switching to Anthropic or Google means rewriting your entire codebase. LangChain solves this with a single abstraction: all models expose the same .invoke(), .stream(), and .bind_tools() interface. The business case is real — you can test competing models for quality and cost, switch to local models for sensitive data, or mix providers across different features of the same application.
The one-line swap
provider_swap.py
from langchain.chat_models import init_chat_model
# OpenAI
model = init_chat_model('openai:gpt-4o-mini') # ①
# Anthropic
model = init_chat_model('anthropic:claude-3-haiku-20240307') # ②
# Google Gemini
model = init_chat_model('google_genai:gemini-1.5-flash') # ③
# Ollama (local, no API key needed)
model = init_chat_model('ollama:llama3.2') # ④
# Everything below is IDENTICAL regardless of provider
response = model.invoke('Explain recursion in one sentence.')
print(response.content)①① OpenAI — requires OPENAI_API_KEY in your environment
②② Anthropic — requires ANTHROPIC_API_KEY — same invoke() call, different key
③③ Google Gemini — requires GOOGLE_API_KEY — multimodal and very fast
④④ Ollama runs entirely on your local machine — no API key, no cost, full privacy

Click to zoom
OpenAI
cloud · fast · wide ecosystem
- •GPT-4o-mini is very cost-effective
- •Largest third-party tool ecosystem
- •Best function-calling reliability
- •Requires OPENAI_API_KEY
Anthropic
cloud · strong reasoning
- •Claude models excel at long documents
- •Strong instruction-following
- •Very large context windows
- •Requires ANTHROPIC_API_KEY
Gemini
cloud · multimodal
- •Built-in image, audio, video support
- •Gemini Flash is extremely fast
- •Native Google Workspace integration
- •Requires GOOGLE_API_KEY
Ollama
local · free · private
- •Runs on your laptop, no internet needed
- •Zero cost, no rate limits
- •Perfect for sensitive or private data
- •No API key required — just install Ollama
Ollama runs entirely on your machine — no API key, no cost, full privacy. Install it from ollama.ai, run "ollama pull llama3.2", and use init_chat_model("ollama:llama3.2") in your code. Perfect for sensitive company data or offline development.
Knowledge Check
What is the minimum change needed to switch your app from OpenAI to Anthropic?
Recap — what you just learned
- ✓init_chat_model("provider:model") is a universal factory — the string is the only difference
- ✓All providers share the same .invoke(), .stream(), and .bind_tools() interface
- ✓Ollama lets you run models locally with no API key and full data privacy
- ✓Provider-independence protects you from vendor lock-in and enables cost comparison