google-genai · PyPI
To install Google Gen AI Python SDK using pip, run the following command:
pip install google-genai
Released on:
Google Gen AI Python SDK provides developers with an interface to integrate Google's generative models into their Python applications. It supports the Gemini Developer API and Vertex AI APIs.
Usage
To create a client for different services, such as the Gemini Developer API or Vertex AI, you can use one of the following code blocks:
- For Gemini Developer API: Set
GOOGLE_API_KEY
- For Gemini API on Vertex AI: Set
GOOGLE_GENAI_USE_VERTEXAI
,GOOGLE_CLOUD_PROJECT
, andGOOGLE_CLOUD_LOCATION
By default, the SDK uses beta API endpoints provided by Google to support preview features in the APIs. You can select stable API endpoints by setting the API version to v1
.
The SDK allows for different parameter types, specified as dictionaries (TypedDict
) or Pydantic Models. It also provides model inferencing and model getters.
The behavior of the model and response can be customized using optional settings such as max_output_tokens
and temperature
. Detailed capabilities and parameter defaults are available in the Vertex AI and Gemini API documentation.
Setting API Version and Providing Inputs
You can set the API version using http_options
and specify parameter types accordingly. The SDK handles various types of content inputs and conversions for model inference.
The behavior of the model and response can be customized using optional settings such as max_output_tokens
and temperature
. Detailed capabilities and parameter defaults are available in the Vertex AI and Gemini API documentation.
Function Calling and Responses
The SDK supports automatic function calling but also allows for manual function declaration and invocation. It provides flexibility in handling function calls and responses from the model.
For error handling, the SDK includes the APIError class.
For more details and updates on Google Gen AI Python SDK, refer to the PyPI page.