How to use different LLM models (Gemini, OpenAI, Anthropic, Ollama) in Google ADK?
#google-adk#models#gemini#openai#anthropic#ollama#vllm#litellm
Answer
Using Different LLM Models in Google ADK
Google ADK is model-agnostic - while optimized for Gemini, it supports 100+ LLMs through multiple connectors.
Model Support Overview
1. Gemini Models (Direct)
pythonfrom google.adk.agents import Agent # Google AI Studio agent = Agent( name="gemini_agent", model="gemini-2.5-flash", instruction="You are a helpful assistant.", ) # Available Gemini models # gemini-2.5-flash - Fast, cost-effective # gemini-2.5-pro - Most capable # gemini-2.0-flash - Previous generation
Environment:
bash# .env GOOGLE_API_KEY=your-google-api-key
2. OpenAI Models (via LiteLLM)
pythonfrom google.adk.agents import Agent from google.adk.models.lite_llm import LiteLlm agent = Agent( name="openai_agent", model=LiteLlm(model="openai/gpt-4o"), instruction="You are a helpful assistant.", ) # Other OpenAI models # openai/gpt-4o - Latest GPT-4o # openai/gpt-4-turbo - GPT-4 Turbo # openai/gpt-3.5-turbo - Fast, affordable
Environment:
bashOPENAI_API_KEY=sk-your-openai-key
3. Anthropic Claude (via Vertex AI)
pythonfrom google.adk.agents import Agent from google.adk.models.anthropic_llm import Claude from google.adk.models.registry import LLMRegistry # Register Claude model provider LLMRegistry.register(Claude) agent = Agent( name="claude_agent", model="claude-sonnet-4-6", instruction="You are a helpful assistant.", )
Via LiteLLM (alternative)
pythonfrom google.adk.models.lite_llm import LiteLlm agent = Agent( name="claude_agent", model=LiteLlm(model="anthropic/claude-3-haiku-20240307"), instruction="You are a helpful assistant.", )
Environment:
bashANTHROPIC_API_KEY=your-anthropic-key
4. Ollama (Local Models)
pythonimport os from google.adk.agents import Agent from google.adk.models.lite_llm import LiteLlm os.environ["OLLAMA_API_BASE"] = "http://localhost:11434" agent = Agent( name="local_agent", model=LiteLlm(model="ollama_chat/gemma3:latest"), instruction="You are a helpful assistant.", ) # Other Ollama models # ollama_chat/llama3:latest # ollama_chat/mistral:latest # ollama_chat/phi3:latest
bash# Start Ollama first ollama serve ollama pull gemma3
5. vLLM (Self-Hosted)
pythonfrom google.adk.agents import Agent from google.adk.models.lite_llm import LiteLlm agent = Agent( name="vllm_agent", model=LiteLlm(model="hosted_vllm/google/gemma-3-4b-it"), instruction="You are a helpful assistant.", )
bash# Start vLLM server vllm serve google/gemma-3-4b-it --port 8000
Environment:
bashHOSTED_VLLM_API_BASE=http://localhost:8000/v1
6. Vertex AI Model Garden
pythonfrom google.adk.agents import Agent # Llama 3 via Vertex AI agent = Agent( name="llama_agent", model="vertex_ai/meta/llama-4-scout-17b-16e-instruct-maas", instruction="You are a helpful assistant.", )
Model Comparison in ADK
| Provider | Connection | Latency | Cost | Best For |
|---|---|---|---|---|
| Gemini | Direct | Low | Low | Default, full ADK features |
| OpenAI | LiteLLM | Medium | Medium | GPT-4o quality |
| Anthropic | Vertex/LiteLLM | Medium | Medium | Long context tasks |
| Ollama | LiteLLM | Local | Free | Privacy, offline |
| vLLM | LiteLLM | Self-hosted | Compute | Custom models |
Pro tip: Gemini models get the deepest ADK integration (streaming, code execution, grounding). Third-party models may have limited feature support.
Learn more at Models Overview and LiteLLM.