AI and LLM integration · Decision guide
Gemini Python code fails with an unexpected keyword argument 'model'
Short answer
TypeError: GenerativeModel.generate_content() got an unexpected keyword argument 'model' means code written for the new google-genai SDK runs against a GenerativeModel object from the legacy google-generativeai package (or Vertex AI's generative_models). Those set the model in the constructor. Switch to from google import genai and client.models.generate_content(model=..., contents=...). google-genai 3.6.1.
Two different Python families expose a class called GenerativeModel: the legacy google-generativeai package and the vertexai.generative_models module of google-cloud-aiplatform. In both, the model name is fixed when the object is created, and generate_content accepts the prompt and options but has no model parameter. The current Google GenAI SDK works the other way round: you create one client and name the model on every call. Paste a current example into code that still builds a GenerativeModel and Python raises this TypeError.
The cure is to use one style consistently. Which style depends on which import your file has, so start by finding it.
Find your case
- If the file imports
google.generativeaiYou are on the legacy Gemini Developer API package. Migrate, or patch the one call. - If the file imports
vertexai.generative_modelsYou are on the Vertex AI module that Google has scheduled for removal. - If the file already has
from google import genaiand the error still showsSomething else in the call chain is still aGenerativeModel. - If you cannot migrate this weekMove the model name into the constructor as a stopgap.
Find which object is the model
Check which Google AI packages are installed where the failing process runs, and grep the project for the import lines. Several can be present at once, which is how a project ends up calling a new-style example on an old object.
Packages and imports
python -m pip list 2>/dev/null | grep -i -E "google-genai|google-generativeai|google-cloud-aiplatform"
grep -rn -E "import google.generativeai|from vertexai.generative_models|from google import genai" --include='*.py' .| Import in the failing file | Package | How the model is chosen |
|---|---|---|
| `import google.generativeai` | `google-generativeai` (legacy) | `GenerativeModel("name")` constructor |
| `from vertexai.generative_models import ...` | `google-cloud-aiplatform` | `GenerativeModel("name")` constructor |
| `from google import genai` | `google-genai` (current) | `model=` argument on each `client.models.generate_content` call |
Legacy google-generativeai package
In the legacy repository the signature is generate_content(self, contents, *, generation_config=None, safety_settings=None, stream=False, tools=None, tool_config=None, request_options=None). No model there, which is exactly what the error says. Google's libraries page lists google-generativeai as not actively maintained and says the legacy libraries were deprecated as of 30 November 2025, with google-genai as the replacement.
The migration is small for a plain text call: remove the old package, install the new one, build a client, and move the model name into the call. The client reads GEMINI_API_KEY (or GOOGLE_API_KEY, which wins if both are set) from the environment.
The new call style
pip uninstall -y google-generativeai
pip install -U google-genai
from google import genai
client = genai.Client()
response = client.models.generate_content(
model="gemini-3.8-flash",
contents="Summarise this ticket in two lines.",
)
print(response.text)The google-genai release I checked, 3.6.1, requires Python 3.11 or later. On an older interpreter, upgrade Python before the package.
Vertex AI GenerativeModel
Google's migration guide says the generative AI module of the Vertex AI SDK is deprecated and will no longer be available after 24 June 2026, and lists vertexai.generative_models among the removed modules of google-cloud-aiplatform, with google-genai as the replacement. That date has passed, so a release of google-cloud-aiplatform newer than that may not have the import at all, and the real fix is the migration rather than a patched keyword.
The new SDK serves both backends. For a Google Cloud project, create the client with enterprise=True plus project and location, or set the three environment variables from the README and call genai.Client() with no arguments.
Same call against a Google Cloud project
from google import genai
client = genai.Client(enterprise=True, project="your-project-id", location="global")
response = client.models.generate_content(
model="gemini-3.8-flash",
contents="Classify this review as positive or negative.",
)
print(response.text)- Environment-variable form:
GOOGLE_GENAI_USE_ENTERPRISE=true,GOOGLE_CLOUD_PROJECT,GOOGLE_CLOUD_LOCATION. - Check that no
vertexai.generative_modelsimport is left anywhere withgrep -rn vertexai.generative_models --include='*.py' .
Stopgap on the legacy package
If other code depends on google-generativeai objects and the swap is a bigger job than this one call, make the call match the old shape: model in the constructor, prompt as the first argument. It works, but the package is no longer actively maintained, so treat it as a bridge.
Old style, kept consistent
import google.generativeai as genai
model = genai.GenerativeModel("gemini-3.8-flash")
response = model.generate_content("Tell me a story in 300 words")
print(response.text)Run one ping call with the new client
Run the smallest possible call and read the output. A reply with no TypeError means the call style is right. If you now get a 404 or a model-not-found error, the call style is fine and the model name is the problem, so compare it with the current list on the Gemini models page.
One-line check with the new SDK
python -c "from google import genai; print(genai.Client().models.generate_content(model='gemini-3.8-flash', contents='ping').text)"- Keep one Google AI SDK in
requirements.txt, and fail CI ifgoogle-generativeaishows up inpip freeze. - Put model calls behind one small module of your own, so the next SDK change touches one file.
In short
- Legacy
GenerativeModelobjects take the model in the constructor;client.models.generate_contenttakes it per call. - Do not mix the two: match the import in the file to the style of the call.
- Google lists both legacy routes as deprecated, so migrate when you can.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.