Closed
Description
Description
Using Google Gemini models with CrewAI via crewai.LLM or langchain_google_genai.ChatGoogleGenerativeAI fails due to litellm.BadRequestError, even with a valid API key from Google AI Studio and a supported model like models/gemini-pro.
Root Cause
crewai.LLM routes Gemini calls through litellm, but:
litellm expects GEMINI_API_KEY, not GOOGLE_API_KEY.
It fails to map models/gemini-pro to a valid provider because it doesn’t match provider/model format.
Even using ChatGoogleGenerativeAI from LangChain directly still fails inside CrewAI because Crew's execution layer tries to route through litellm.
Steps to Reproduce
from crewai import Agent, Task, Crew, LLM
import os
# Set API key from Google AI Studio
os.environ["GOOGLE_API_KEY"] = "AIzaSy..."
llm = LLM(model="gemini/gemini-pro", temperature=0.7)
agent = Agent(role="AI Expert", goal="Explain things", backstory="Expert", llm=llm)
task = Task(
description="Explain tokenization",
expected_output="Simple explanation",
agent=agent
)
crew = Crew(agents=[agent], tasks=[task], verbose=True)
crew.kickoff()
Expected behavior
Error Output
BadRequestError: LLM Provider NOT provided. Pass in the LLM provider you are trying to call. You passed model=models/gemini-pro
or
litellm.AuthenticationError: geminiException - {
"error": {
"code": 400,
"message": "API key not valid. Please pass a valid API key."
}
}
Screenshots/Code snippets
Operating System
Ubuntu 20.04
Python Version
3.11
crewAI Version
0.119.0
crewAI Tools Version
N/A
Virtual Environment
Venv
Evidence
Error Output
BadRequestError: LLM Provider NOT provided. Pass in the LLM provider you are trying to call. You passed model=models/gemini-pro
or
litellm.AuthenticationError: geminiException - {
"error": {
"code": 400,
"message": "API key not valid. Please pass a valid API key."
}
}
Possible Solution
CrewAI+Gemini is currently broken, but LangChain+Gemini is stable and works perfectly — just use it outside CrewAI for now.
Additional context
langchain_google_genai.ChatGoogleGenerativeAI is fully supported and works — but only outside CrewAI (as of now).