百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
G

go-genai

> 编程语言
开源

Google Gen AI Go SDK 为开发人员提供了一个接口,可将 Google 的生成模型集成到 Go 应用中。

1.2K stars0 点赞0 次浏览
访问官网GitHub

工具介绍

Google Gen AI Go SDK 为开发人员提供了一个接口,可将 Google 的生成模型集成到 Go 应用中。

Google Gen AI Go SDK

The Google Gen AI Go SDK provides an interface for developers to integrate Google's generative models into their Go applications. It supports the Gemini Developer API and Gemini Enterprise Agent Platform APIs.

[!WARNING] Updates to GenerateVideos in upcoming SDK version:

Methods/fields to be removed migration guide
prompt/text/image arguments in Models.GenerateVideos (and async variants) Use source argument instead

To avoid unexpected updates, pin the SDK version to < 2.0.0.

The Google Gen 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. This SDK supports use cases like:

  • Generate text from text-only input
  • Generate text from text-and-images input (multimodal)
  • ...

For example, with just a few lines of code, you can access Gemini's multimodal capabilities to generate text from text-and-image input.

parts := []*genai.Part{
  {Text: "What's this image about?"},
  {InlineData: &genai.Blob{Data: imageBytes, MIMEType: "image/jpeg"}},
}
result, err := client.Models.GenerateContent(ctx, "gemini-flash-latest", []*genai.Content{{Parts: parts}}, nil)

Installation and usage

Add the SDK to your module with go get google.golang.org/genai.

Create Clients

Imports

import "google.golang.org/genai"

Gemini API Client:

client, err := genai.NewClient(ctx, &genai.ClientConfig{
	APIKey:   apiKey,
	Backend:  genai.BackendGeminiAPI,
})

Gemini Enterprise Agent Platform Client:

client, err := genai.NewClient(ctx, &genai.ClientConfig{
	Project:  project,
	Location: location,
	Backend:  genai.BackendEnterprise,
})

(Optional) Using environment variables:

You can create a client by configuring the necessary environment variables. Configuration setup instructions depends on whether you're using the Gemini Developer API or the Gemini API in Gemini Enterprise Agent Platform.

Gemini Developer API: Set GOOGLE_API_KEY as shown below:

export GOOGLE_API_KEY='your-api-key'

Gemini API on Gemini Enterprise Agent Platform: Set GOOGLE_GENAI_USE_ENTERPRISE, GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION, as shown below:

export GOOGLE_GENAI_USE_ENTERPRISE=true
export GOOGLE_CLOUD_PROJECT='your-project-id'
export GOOGLE_CLOUD_LOCATION='us-central1'
client, err := genai.NewClient(ctx, &genai.ClientConfig{})

License

The contents of this repository are licensed under the Apache License, version 2.0.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Go

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言