GitHub
github.com › googleapis › go-genai
GitHub - googleapis/go-genai: Google Gen AI Go SDK provides an interface for developers to integrate Google's generative models into their Go applications. · GitHub
May 22, 2026 - Google Gen AI Go SDK provides an interface for developers to integrate Google's generative models into their Go applications. - googleapis/go-genai
Starred by 1.1K users
Forked by 152 users
Languages Go
Go Packages
pkg.go.dev › google.golang.org › genai
genai package - google.golang.org/genai - Go Packages
3 weeks ago - import "google.golang.org/genai" client, err := genai.NewClient(ctx, &genai.ClientConfig{ APIKey: apiKey, Backend: genai.BackendGeminiAPI, }) client, err := genai.NewClient(ctx, &genai.ClientConfig{ Project: project, Location: location, Backend: genai.BackendEnterprise, }) You can create a client by configuring the necessary environment variables.
Videos
02:00:20
Deploying a GenAI app on Google Cloud | Code walkthrough - YouTube
09:45
Google Gen AI SDK - Step-by-Step Hands-on Tutorial - YouTube
Building Generative AI Applications in Go- Gari Singh, Google ...
05:32
Gemini AI API with Go Golang Tutorial - YouTube
01:20:05
Introduction to Generative AI with Go by Daniel Whitenack - YouTube
GitHub
github.com › google › generative-ai-go
GitHub - google/generative-ai-go: Go SDK for Google Generative AI · GitHub
With Gemini 2.0, we took the chance to create a single unified SDK for all developers who want to use Google's GenAI models (Gemini, Veo, Imagen, etc).
Starred by 856 users
Forked by 101 users
Languages Go 98.7% | Shell 1.3%
Go Packages
pkg.go.dev › cloud.google.com › go › vertexai › genai
genai package - cloud.google.com/go/vertexai/genai - Go Packages
April 9, 2026 - New users are encouraged to use the Google GenAI Go SDK available at google.golang.org/genai
Go Packages
pkg.go.dev › github.com › google › generative-ai-go › genai
genai package - github.com/google/generative-ai-go/genai - Go Packages
May 2, 2025 - package main import ( "context" "fmt" "log" "os" "github.com/google/generative-ai-go/genai" "google.golang.org/api/option" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, option.WithAPIKey(os.Getenv("GEMINI_API_KEY"))) if err != nil { log.Fatal(err) } defer client.Close() model := client.GenerativeModel("gemini-1.5-flash") cs := model.StartChat() cs.History = []*genai.Content{ { Parts: []genai.Part{ genai.Text("Hello, I have 2 dogs in my house."), }, Role: "user", }, { Parts: []genai.Part{ genai.Text("Great to meet you.
Google
docs.cloud.google.com › gemini enterprise agent platform › google gen ai sdk
Google Gen AI SDK | Gemini Enterprise Agent Platform | Google Cloud Documentation
go-genai on GitHub · go get google.golang.org/genai · Set environment variables to use the Gen AI SDK with Vertex AI: # Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values # with appropriate values for your project. export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_ENTERPRISE=True ·
Go Packages
pkg.go.dev › cloud.google.com › go › vertexai
vertexai package - cloud.google.com/go/vertexai - Go Packages
April 9, 2026 - The Vertex 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. ... 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 Packages
pkg.go.dev › github.com › zzxwill › generative-ai-go › genai
genai package - github.com/zzxwill/generative-ai-go/genai - Go Packages
package main import ( "context" "fmt" "log" "os" "github.com/google/generative-ai-go/genai" "google.golang.org/api/option" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, option.WithAPIKey(os.Getenv("GEMINI_API_KEY"))) if err != nil { log.Fatal(err) } defer client.Close() model := client.GenerativeModel("gemini-1.0-pro") cs := model.StartChat() cs.History = []*genai.Content{ &genai.Content{ Parts: []genai.Part{ genai.Text("Hello, I have 2 dogs in my house."), }, Role: "user", }, &genai.Content{ Parts: []genai.Part{ genai.Text("Great to meet you.
Google Cloud
cloud.google.com › client libraries › vertex ai api v1 - package cloud.google.com/go/aiplatform/apiv1 (v1.125.0)
Vertex AI API v1 - Package cloud.google.com/go/aiplatform/apiv1 (v1.125.0) | Go client libraries | Google Cloud Documentation
PageInfo supports pagination. See the [google.golang.org/api/iterator] package for details.
DEV Community
dev.to › pradumnasaraf › building-an-ai-powered-cli-with-golang-and-google-gemini-45a1
Building an AI-Powered CLI with Golang and Google Gemini - DEV Community
August 27, 2024 - package cmd import ( "context" "fmt" "log" "os" "github.com/google/generative-ai-go/genai" "github.com/spf13/cobra" "google.golang.org/api/option" ) // searchCmd represents the search command var searchCmd = &cobra.Command{ Use: "search", Short: "A brief description of your command", // Added the getResponse() function Run: func(cmd *cobra.Command, args []string) { getResponse() }, } func init() { rootCmd.AddCommand(searchCmd) } func getResponse() { ctx := context.Background() client, err := genai.NewClient(ctx, option.WithAPIKey(os.Getenv("GEMINI_API_KEY"))) if err != nil { log.Fatal(err) } defer client.Close() model := client.GenerativeModel("gemini-1.5-flash") resp, err := model.GenerateContent(ctx, genai.Text("Write a story about a AI and magic")) if err != nil { log.Fatal(err) } fmt.Println(resp.Candidates[0].Content.Parts[0]) }
Google
docs.cloud.google.com › client libraries › package cloud.google.com/go/vertexai/genai (v0.18.0)
Package cloud.google.com/go/vertexai/genai (v0.18.0) | Go client libraries | Google Cloud Documentation
New users are encouraged to use the Google GenAI Go SDK available at google.golang.org/genai
Go Packages
pkg.go.dev › google.golang.org › genai › tokenizer
tokenizer package - google.golang.org/genai/tokenizer - Go Packages
func (tok *LocalTokenizer) CountTokens(contents []*genai.Content, config *genai.CountTokensConfig) (*genai.CountTokensResult, error) CountTokens counts tokens in the given contents with optional configuration, similar to the Python LocalLocalTokenizer.count_tokens method. ... package main import ( "fmt" "log" "google.golang.org/genai" "google.golang.org/genai/tokenizer" ) func main() { tok, err := tokenizer.NewLocalTokenizer("gemini-1.5-flash") if err != nil { log.Fatal(err) } contents := []*genai.Content{ genai.NewContentFromText("a prompt", "user"), genai.NewContentFromText("another prompt", "user"), } ntoks, err := tok.CountTokens(contents, nil) if err != nil { log.Fatal(err) } fmt.Println("total token count:", ntoks.TotalTokens) }
Reddit
reddit.com › r/golang › mocking google/genai library
r/golang on Reddit: Mocking google/genai library
May 2, 2025 -
Hello everyone, I'm relatively new to Go development and currently facing challenges with testing.
I'm struggling to mock the libraries in the google/genai SDK. I tried to create a wrapper for abstraction.
package clients
import (
"context"
"google.golang.org/genai"
"io"
"iter"
)
type GenaiClientWrapper struct {
*genai.Client
}
func NewGenaiClientWrapper(client *genai.Client) *GenaiClientWrapper {
return &GenaiClientWrapper{Client: client}
}
func (c GenaiClientWrapper) GenerateContent(ctx context.Context, model string, contents []*genai.Content, config *genai.GenerateContentConfig) (*genai.GenerateContentResponse, error) {
return c.Client.Models.GenerateContent(
ctx,
model,
contents,
config,
)
}
func (c GenaiClientWrapper) GenerateContentStream(ctx context.Context, model string, contents []*genai.Content, config *genai.GenerateContentConfig) iter.Seq2[*genai.GenerateContentResponse, error] {
return c.Client.Models.GenerateContentStream(
ctx,
model,
contents,
config,
)
}
func (c GenaiClientWrapper) Upload(ctx context.Context, r io.Reader, config *genai.UploadFileConfig) (*genai.File, error) {
return c.Client.Files.Upload(
ctx,
r,
config,
)
}But i can't seem to find a way to mock the iter.Seq2 response. Has anyone tried to use the genai sdk in their projects? Is there a better way to implement the abstraction?
Top answer 1 of 4
1
DISCLAIMER: I have never used the google/genai library. If you are creating another type with the GenerateContentStream method to mock the genai lib, and not sure how to return a iter.Seq2, note that iter.Seq2 is just func(yield func(K, V) bool). Here K would be *genai.GenerateContentResponse and V would be error. (They don't have to be a Key and Value pair) c.f. https://pkg.go.dev/iter#hdr-Iterators Another thing I would like to mention is that unless you are using every single method *genai.Client has, use smaller interfaces to mock it. Assuming that you use the three methods, create two small interfaces, e.g. Uploader and ContentGenerator, at the consumer. genai.Client.Models and genai.Client.Files will implicitly satisfy your interface, without having to create a wrapper struct. Now to mock them, you can create a InMemoryUploader, and InMemoryContentGenerator, and all you have to do is define 3 mock methods. i.e. You can cherry pick the methods from external libraries to an interface of your choice, and the external libraries will satisfy them. This allows smaller interfaces and easier mocking.
2 of 4
1
Create an interface with the methods you care about: `GenerateContent`, `GenerateContentStream`, `Upload`. Use your wrapper as the real implementation. Write a new mock implementation that returns hardcoded values or whatever else you need. There are some examples of implementing functions that return `iter.Seq` on https://pkg.go.dev/iter
GitHub
github.com › google › generative-ai-go › blob › main › genai › example_test.go
generative-ai-go/genai/example_test.go at main · google/generative-ai-go
"github.com/google/generative-ai-go/genai/internal/testhelpers" "google.golang.org/api/googleapi" "google.golang.org/api/iterator" "google.golang.org/api/option" ) · var testDataDir = filepath.Join(testhelpers.ModuleRootDir(), "genai", "testdata") ·
Author google
Google AI
ai.google.dev › gemini api › gemini api libraries
Gemini API libraries | Google AI for Developers
April 28, 2026 - The Google GenAI SDK is available for the Python, JavaScript/TypeScript, Go and Java languages.
deps.dev
deps.dev › go › google.golang.org › genai › v1.44.0
google.golang.org/genai | Go | Open Source ...
January 30, 2026 - You need to enable JavaScript to run this app
LinkedIn
linkedin.com › pulse › integrating-googles-gemini-ai-golang-deep-dive-genai-package-pranav-n-jptsc
Integrating Google's Gemini AI with Golang: A Deep Dive ...
We cannot provide a description for this page right now