Gemini API quickstart

This quickstart shows you how to install your SDK of choice and then make your first Gemini API request.

Install the Gemini API library

Using Go 1.20+, install the generative-ai-go package in your module directory using the go get command:

go get github.com/google/generative-ai-go

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.

model := client.GenerativeModel("gemini-1.5-flash")
resp, err := model.GenerateContent(ctx, genai.Text("Write a story about a magic backpack."))
if err != nil {
	log.Fatal(err)
}

printResponse(resp)

What's next

Now that you made your first API request, you might want to explore the following guides which showcase Gemini in action: