https://github.com/googleapis/go-genai
Google Gen AI Go SDK provides an interface for developers to integrate Google's generative models into their Go applications.
https://github.com/googleapis/go-genai
Last synced: 4 months ago
JSON representation
Google Gen AI Go SDK provides an interface for developers to integrate Google's generative models into their Go applications.
- Host: GitHub
- URL: https://github.com/googleapis/go-genai
- Owner: googleapis
- License: apache-2.0
- Created: 2024-12-06T23:16:53.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-06-23T18:36:52.000Z (5 months ago)
- Last Synced: 2025-06-23T19:31:47.821Z (5 months ago)
- Language: Go
- Homepage: https://pkg.go.dev/google.golang.org/genai
- Size: 697 KB
- Stars: 544
- Watchers: 37
- Forks: 62
- Open Issues: 28
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ai - googleapis/go-genai
- awesome-ai - googleapis/go-genai
README

[](https://pkg.go.dev/google.golang.org/genai)
## ✨ NEW ✨
### Google Gemini Multimodal Live support
Introducing support for the Gemini Multimodal Live feature. Here's an example
Multimodal Live server showing realtime conversation and video streaming:
[code](./examples/live/live_streaming_server.go)
# Google Gen AI Go SDK
The Google Gen AI Go SDK provides an interface for developers to integrate
Google's generative models into their Go applications. It supports the
[Gemini Developer API](https://ai.google.dev/gemini-api/docs) and
[Vertex AI](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/overview)
APIs.
The Google Gen AI Go SDK enables developers to use Google's state-of-the-art
generative AI models (like Gemini) to build AI-powered features and applications.
This SDK supports use cases like:
- Generate text from text-only input
- Generate text from text-and-images input (multimodal)
- ...
For example, with just a few lines of code, you can access Gemini's multimodal
capabilities to generate text from text-and-image input.
```go
parts := []*genai.Part{
{Text: "What's this image about?"},
{InlineData: &genai.Blob{Data: imageBytes, MIMEType: "image/jpeg"}},
}
result, err := client.Models.GenerateContent(ctx, "gemini-2.0-flash", []*genai.Content{{Parts: parts}}, nil)
```
## Installation and usage
Add the SDK to your module with `go get google.golang.org/genai`.
## Create Clients
### Imports
```go
import "google.golang.org/genai"
```
### Gemini API Client:
```go
client, err := genai.NewClient(ctx, &genai.ClientConfig{
APIKey: apiKey,
Backend: genai.BackendGeminiAPI,
})
```
### Vertex AI Client:
```go
client, err := genai.NewClient(ctx, &genai.ClientConfig{
Project: project,
Location: location,
Backend: genai.BackendVertexAI,
})
```
### (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 Vertex AI.
**Gemini Developer API:** Set `GOOGLE_API_KEY` as shown below:
```bash
export GOOGLE_API_KEY='your-api-key'
```
**Gemini API on Vertex AI:** Set `GOOGLE_GENAI_USE_VERTEXAI`,
`GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION`, as shown below:
```bash
export GOOGLE_GENAI_USE_VERTEXAI=true
export GOOGLE_CLOUD_PROJECT='your-project-id'
export GOOGLE_CLOUD_LOCATION='us-central1'
```
```go
client, err := genai.NewClient(ctx, &genai.ClientConfig{})
```
## License
The contents of this repository are licensed under the
[Apache License, version 2.0](http://www.apache.org/licenses/LICENSE-2.0).