🌐
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.
🌐
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. ...
🌐
Google AI
ai.google.dev › gemini api › migrate to the google genai sdk
Migrate to the Google GenAI SDK | Gemini API | Google AI for Developers
April 28, 2026 - npm install @google/genai · go get google.golang.org/genai · The old SDK implicitly handled the API client behind the scenes using a variety of ad hoc methods. This made it hard to manage the client and credentials. Now, you interact through a central Client object.
🌐
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.
Find elsewhere
🌐
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]) }
🌐
Medium
sraynitjsr.medium.com › golang-genai-integration-961687be314d
GoLang GenAI Integration. Using… | by Subhradeep Ray | Medium
April 21, 2025 - Using “https://pkg.go.dev/github.com/google/generative-ai-go” package in GoLang, we can integrate GenAI models in Go Application.
🌐
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?

🌐
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
🌐
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) }
🌐
Medium
tomelin-tech.medium.com › unveiling-ai-with-golang-and-google-gemini-dd185318b7ac
🚀 Unveiling AI with Golang and Google Gemini! ✨ | by Rafael Tomelin | Medium
May 23, 2025 - import ( "context" "errors" "fmt" "log" "github.com/google/generative-ai-go/genai" "google.golang.org/api/option" )
🌐
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.