🌐
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 - parts := []*genai.Part{ {Text: ... "gemini-2.5-flash", []*genai.Content{{Parts: parts}}, nil) Add the SDK to your module with go get google.golang.org/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 - parts := []*genai.Part{ {Text: ... client.Models.GenerateContent(ctx, "gemini-2.5-flash", []*genai.Content{{Parts: parts}}, nil) Add the SDK to your module with go get google.golang.org/genai....
Discussions

Using AI to learn Go, am I setting up myself for failure?
Personally for me this is the completely wrong approach. Having the ai write it for you and then understand what it wrote is less than optimal. You should use chatgpt to ask questions, not write code if you don’t understand it. Use it as a mentor who can’t be busy to answer your questions. Not as someone who will complete your homework and then maybe you’ll try and understand it afterwards. If a student actually wants to learn a subject, do they get someone to complete their homework? You get what I mean? If your goal is to just complete a project in anyway. Then maybe might work but most likely won’t. You should understand and come up with the logic behind everything you write before letting ai write it for you. Copilot is good for predictable sequences, but most things logic wise it fails as it does not know implementation. More on reddit.com
🌐 r/golang
36
7
September 7, 2023
Can Go be used for machine learning and AI?
Yes it can and that's what I use it for every day. More on reddit.com
🌐 r/golang
24
28
May 22, 2024
Mocking google/genai library
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. More on reddit.com
🌐 r/golang
4
0
May 2, 2025
Best Library for genAi? Any suggestion?
Using the official SDKs? https://github.com/google/generative-ai-go https://platform.openai.com/docs/libraries/community-libraries More on reddit.com
🌐 r/golang
3
0
July 27, 2024
🌐
GitHub
github.com › google › generative-ai-go
GitHub - google/generative-ai-go: Go SDK for Google Generative AI · GitHub
Go SDK for Google Generative AI. Contribute to google/generative-ai-go development by creating an account on GitHub.
Starred by 856 users
Forked by 101 users
Languages   Go 98.7% | Shell 1.3%
🌐
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.
🌐
CloudZenia Blogs
cloudzenia.com › home › blogs › how to implement gemini ai model in golang: a comprehensive tutorial
Implement Gemini AI Model in Golang: A Complete Guide | CloudZenia
December 4, 2025 - package main import ( "context" "encoding/json" "fmt" "log" "os" "github.com/google/generative-ai-go/genai" "github.com/joho/godotenv" "google.golang.org/api/option" ) type Content struct{ Parts []string `json:Parts` Role string `json:Role` } type Candidates struct { Content *Content `json:Content` } type ContentResponse struct{ Candidates *[]Candidates `json:Candidates` } func main() { //Load .env key err := godotenv.Load() if err != nil { log.Fatal("Error loading .env key") } api_key := os.Getenv("API_KEY") //initializing the gemini ctx := context.Background() client, err := genai.NewClient(
🌐
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 › gemini enterprise agent platform › google gen ai sdk
Google Gen AI SDK | Gemini Enterprise Agent Platform | Google Cloud Documentation
from google import genai from google.genai.types import HttpOptions client = genai.Client(http_options=HttpOptions(api_version="v1")) response = client.models.generate_content( model="gemini-3.5-flash", contents="How does AI work?", ) ...
🌐
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
Find elsewhere
🌐
Medium
medium.com › @sanjayshiradwade › your-first-ai-agent-in-go-from-prompt-to-action-035c2a129af5
Your First AI Agent in Go: From Prompt to Action | by Sanjay shiradwade | Medium
November 12, 2025 - // This reads the GOOGLE_API_KEY from your environment variables. model, err := gemini.NewModel(ctx, "gemini-1.5-flash", &genai.ClientConfig{ APIKey: os.Getenv("GOOGLE_API_KEY"), }) if err != nil { log.Fatalf("Failed to create model: %v", err) } // Create a new LLM-based agent. agent, err := llmagent.New(llmagent.Config{ Name: "hello_time_agent", Model: model, Description: "Tells the current time in a specified city.", Instruction: "You are a helpful assistant that tells the current time in a city.", Tools: []tool.Tool{ geminitool.GoogleSearch{}, }, }) if err != nil { log.Fatalf("Failed to create agent: %v", err) } // Configure the ADK launcher with our agent.
🌐
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 - I’m starting a practical series where I’ll explore the integration of Golang with Google Gemini. I’ll cover everything from initial setup to building a CLI for Kubernetes log and event analysis using the power of Gemini. ... The Go project structure for LLMs. How to configure access to the Gemini API (focusing on the new go-genai repository).
🌐
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/iterator" "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() send := func(msg string) *genai.GenerateContentResponse { fmt.Printf("== Me: %s\n== Model:\n", msg) res, err := cs.SendMessage(ctx, genai.Text(msg)) if err != nil { log.Fatal(err) } return
🌐
Liu Houliang
liuhouliang.com › en › post › go_gemini
Use Google Gemini API in Go - Liu Houliang
February 19, 2024 - import "github.com/google/generative-ai-go/genai" import "google.golang.org/api/option" ctx := context.Background() // Access your API key as an environment variable (see "Set up your API key" above) client, err := genai.NewClient(ctx, option.WithAPIKey(os.Getenv("API_KEY"))) if err != nil { log.Fatal(err) } defer client.Close() model := client.GenerativeModel("MODEL_NAME") When the prompt input includes only text, use the gemini-pro model with the GenerateContent method to generate text output: ctx := context.Background() // Access your API key as an environment variable (see "Set up your API
🌐
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.
🌐
Medium
sraynitjsr.medium.com › golang-genai-integration-961687be314d
GoLang GenAI Integration. Using… | by Subhradeep Ray | Medium
April 21, 2025 - package main import ( "context" "encoding/json" "fmt" "log" "net/http" "os" "strings" "slices" "github.com/google/generative-ai-go/genai" "google.golang.org/api/iterator" "google.golang.org/api/option" ) var ( client *genai.Client ctx context.Context ) func initClient() { apiKey := os.Getenv("API_KEY") if apiKey == "" { log.Fatal("API_KEY not set in environment") } ctx = context.Background() var err error client, err = genai.NewClient(ctx, option.WithAPIKey(apiKey)) if err != nil { log.Fatalf("Failed to create genai client: %v", err) } } func getModels(w http.ResponseWriter, r *http.Request) {
🌐
Go Packages
pkg.go.dev › cloud.google.com › go › vertexai › genai
genai package - cloud.google.com/go/vertexai/genai - Go Packages
April 9, 2026 - package main import ( "context" "fmt" "log" "cloud.google.com/go/vertexai/genai" "google.golang.org/api/iterator" ) // Your GCP project const projectID = "your-project" // A GCP location like "us-central1"; if you're using standard Google-published // models (like untuned Gemini models), you ...
🌐
Google
google.github.io › adk-docs › get-started › go
Go - Agent Development Kit (ADK)
package main import ( "context" "log" "os" "google.golang.org/adk/agent" "google.golang.org/adk/agent/llmagent" "google.golang.org/adk/cmd/launcher" "google.golang.org/adk/cmd/launcher/full" "google.golang.org/adk/model/gemini" "google.golang.org/adk/tool" "google.golang.org/adk/tool/geminitool" "google.golang.org/genai" ) func main() { ctx := context.Background() model, err := gemini.NewModel(ctx, "gemini-flash-latest", &genai.ClientConfig{ APIKey: os.Getenv("GOOGLE_API_KEY"), }) if err != nil { log.Fatalf("Failed to create model: %v", err) } timeAgent, err := llmagent.New(llmagent.Config{ Na
🌐
GitHub
github.com › google › generative-ai-go › blob › main › genai › chat.go
generative-ai-go/genai/chat.go at main · google/generative-ai-go
package genai · · import ( "context" ) · // A ChatSession provides interactive chat. type ChatSession struct { m *GenerativeModel · History []*Content · } · // StartChat starts a chat session. func (m *GenerativeModel) StartChat() *ChatSession { return &ChatSession{m: m} } ·
Author   google
🌐
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. ...