This quickstart shows you how to install your SDK of choice and then make your first Gemini API request.
Install the Gemini API library
Install google.golang.org/genai in your module directory using the go get command:
go get google.golang.org/genai
Make your first request
Get a Gemini API key in Google AI Studio
Use the
generateContent
method
to send a request to the Gemini API.
package main
import (
"context"
"fmt"
"log"
"google.golang.org/genai"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, &genai.ClientConfig{
APIKey: "YOUR_API_KEY",
Backend: genai.BackendGeminiAPI,
})
if err != nil {
log.Fatal(err)
}
result, err := client.Models.GenerateContent(
ctx,
"gemini-2.0-flash",
genai.Text("Explain how AI works in a few words"),
nil,
)
if err != nil {
log.Fatal(err)
}
fmt.Println(result.Text())
}
What's next
Now that you made your first API request, you might want to explore the following guides that show Gemini in action: