Google Releases Gen AI Python SDK Version 3.2.0
Google released version 3.2.0 of its Gen AI Python SDK, part of the major 3.x line. The update switches the default Gemini Developer API version from v1beta to v1 and replaces the default HTTP client httpx with httpx2, which is no longer installed by default. Developers should note that the latest model aliases exist only on v1beta and can revert via environment variables or HttpOptions.
Related Entities
Full Report
Contents7 sections
Google Gen AI SDK
Documentation: https://googleapis.github.io/python-genai/
Google Gen AI Python SDK provides an interface for developers to integrate Google's generative models into their Python applications. It supports the Gemini Developer API and Gemini platform APIs.
[!WARNING]
Major version 3 changes:
- Default Gemini Developer API version is now
v1(wasv1beta). Gemini platform (formerly Gemini Enterprise Agent Platform and Vertex AI) clients are unaffected and still default tov1beta1.
- The
gemini-flash-latest,gemini-flash-lite-latestandgemini-pro-latestaliases exist only onv1beta. Use a specific model version, or switch back tov1beta.- To restore the previous default, set
GOOGLE_GENAI_API_VERSION=beta(or an explicit version such asv1beta), or passtypes.HttpOptions(api_version='v1beta'), which takes precedence.- Default HTTP client is now
httpx2(washttpx), andhttpxis no longer installed by default.
- To restore
httpxas the default, do both: installgoogle-genai[httpx]and setGOOGLE_GENAI_HTTP_CLIENT=httpx. Alternatively, passhttpx_client/httpx_async_clientinHttpOptions.- To migrate to
httpx2,import httpx2 as httpxis sufficient in most cases.httpx2verifies SSL certificates against the OS trust store instead ofcertifiwhenSSL_CERT_FILEandSSL_CERT_DIRare not set.- Objects passed in
HttpOptions(client_args=..., async_client_args=...)(such asTimeout,Limits, transports,Authsubclasses) and transport exceptions you catch (TimeoutException,ConnectError,HTTPError) must come from the active HTTP client package.- interactions:
CodeExecutionResultStep.resultchanges fromstringto theCodeExecutionResultStepResultunion. Check which variant is present and read the string from it. The JSON for text-only results is unchanged.To avoid unexpected updates, pin the SDK version to
< 3.0.0.
Agent Skills
Large Language Models (LLMs) and generative AI coding assistants are often trained on static datasets. As a result, they may be unaware of recent updates and suggest outdated or legacy libraries.
To ensure your AI coding helper (such as Antigravity, Claude Code, Cursor, or other IDE extensions) generates up-to-date code using the correct SDK syntax and best practices, we recommend equipping your assistant with Gemini API Skills. Loading these skills injects the correct patterns and guidelines directly into your AI assistant's context.
Depending on your target platform, use the corresponding Agent Skill repository:
- Gemini Developer API: Use the google-gemini/gemini-skills repository.
- Gemini platform (formerly Gemini Enterprise Agent Platform and Vertex AI): Use the google/skills repository.
Installation
pip install google-genai<small>With uv:</small>
uv pip install google-genaiImports
from google import genai
from google.genai import typesCreate a client
Please run one of the following code blocks to create a client for different services (Gemini Developer API or Gemini platform).
from google import genai
# Only run this block for Gemini Developer API
client = genai.Client(api_key='GEMINI_API_KEY')from google import genai
# Only run this block for Gemini platform
client = genai.Client(
enterprise=True, project='your-project-id', location='global'
)Using types
All API methods support Pydantic types and dictionaries, which you can access
from google.genai.types. You can import the types module with the following:
from google.genai import typesBelow is an example generate_content() call using Part from the types module:
response = client.models.generate_content(
model='gemini-4-hydrogen',
contents=types.Part.from_text(text='Why is the sky blue?')
)Alternatively, you can accomplish the same request using dictionaries instead of types:
response = client.models.generate_content(
model='gemini-4-hydrogen',
contents={'text': 'Why is the sky blue?'}
)(Optional) Using environment variables:
You can create a client by configuring the necessary environment variables. Configuration setup instructions depends on whether you're using the Gemini Developer API or the Gemini API in Gemini platform.
Gemini Developer API: Set the GEMINI_API_KEY or GOOGLE_API_KEY.
It will automatically be picked up by the client. It's recommended that you
set only one of those variables, but if both are set, GOOGLE_API_KEY takes
precedence.
export GEMINI_API_KEY='your-api-key'Gemini API in Gemini platform: Set GOOGLE_GENAI_USE_ENTERPRISE,
GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION, as shown below:
export GOOGLE_GENAI_USE_ENTERPRISE=true
export GOOGLE_CLOUD_PROJECT='your-project-id'
export GOOGLE_CLOUD_LOCATION='global'from google import genai
client = genai.Client()Close a client
Explicitly close the sync client to ensure that resources, such as the underlying HTTP connections, are properly cleaned up and closed.
from google.genai import Client
client = Client()
response_1 = client.models.generate_content(
model=MODEL_ID,
contents='Hello',
)
response_2 = client.models.generate_content(
model=MODEL_ID,
contents='Ask a question',
)
# Close the sync client to release resources.
client.close()To explicitly close the async client:
from google.genai import Client
aclient = Client(
enterprise=True, project='my-project-id', location='global'
).aio
response_1 = await aclient.models.generate_content(
model=MODEL_ID,
contents='Hello',
)
response_2 = await aclient.models.generate_content(
model=MODEL_ID,
contents='Ask a question',
)
# Close the async client to release resources.
await aclient.aclose()(注:更多技术实现细节与完整 API 文档请查阅原项目 README)