The new Google Gen AI SDK provides a unified interface to Gemini 2.0 through both the Gemini Developer API and Vertex AI (the Gemini Enterprise API). With a few exceptions, code that runs on one platform will run on both. The Gen AI SDK also supports the Gemini 1.5 models.
Python
The Google Gen AI SDK for Python is available on PyPI and GitHub.
To learn more, see the Python SDK reference.
Quickstart
1. Install the SDK
pip install google-genai
2. Import the library
from google import genai
3. Create a client
client = genai.Client(api_key='GEMINI_API_KEY')
4. Generate content
response = client.models.generate_content(
model='gemini-2.0-flash', contents='How does RLHF work?'
)
print(response.text)
Go
The Google Gen AI SDK for Go is available on go.dev and GitHub.
Quickstart
1. Import the library
import "google.golang.org/genai"
2. Create a client
client, err := genai.NewClient(ctx, &genai.ClientConfig{
APIKey: apiKey,
Backend: genai.BackendGeminiAPI,
})
3. Generate content
// Call the GenerateContent method
result, err := client.Models.GenerateContent(ctx, "gemini-2.0-flash", genai.Text("How does RLHF work?"), nil)
Java
The Google Gen AI SDK for Java is available through Maven and GitHub.
Quickstart
1. Import the library
If you're using Maven, add the following to your dependencies:
<dependencies>
<dependency>
<groupId>com.google.genai</groupId>
<artifactId>google-genai</artifactId>
<version>0.1.0</version>
</dependency>
</dependencies>
2. Create a client
import com.google.genai.Client;
// The client gets the API key from the environment variable `GOOGLE_API_KEY`
Client client = new Client();
// Use the builder class for instantiation.
Client client = Client.builder().apiKey("your-api-key").build();
3. Generate content
package <your.pack.name>;
import com.google.genai.Client;
import com.google.genai.types.GenerateContentResponse;
import java.io.IOException;
import org.apache.http.HttpException;
public class GenerateContentWithTextInput {
public static void main(String[] args) throws IOException, HttpException {
Client client = new Client();
GenerateContentResponse response =
client.models.generateContent("gemini-2.0-flash-001", "How does RLHF work?", null);
System.out.println("Unary response: " + response.text());
}
}