gemini-api-dev
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGemini API Development Skill
Gemini API开发技能
Overview
概述
The Gemini API provides access to Google's most advanced AI models. Key capabilities include:
- Text generation - Chat, completion, summarization
- Multimodal understanding - Process images, audio, video, and documents
- Function calling - Let the model invoke your functions
- Structured output - Generate valid JSON matching your schema
- Code execution - Run Python code in a sandboxed environment
- Context caching - Cache large contexts for efficiency
- Embeddings - Generate text embeddings for semantic search
Gemini API可让你访问谷歌最先进的AI模型。核心功能包括:
- 文本生成 - 聊天、补全、摘要
- 多模态理解 - 处理图片、音频、视频和文档
- 函数调用 - 让模型调用你的函数
- 结构化输出 - 生成符合你指定schema的有效JSON
- 代码执行 - 在沙箱环境中运行Python代码
- 上下文缓存 - 缓存大上下文以提升效率
- 嵌入向量 - 生成文本嵌入向量用于语义搜索
Current Gemini Models
当前Gemini模型
- : 1M tokens, complex reasoning, coding, research
gemini-3-pro-preview - : 1M tokens, fast, balanced performance, multimodal
gemini-3-flash-preview - : 65k / 32k tokens, image generation and editing
gemini-3-pro-image-preview
[!IMPORTANT] Models like,gemini-2.5-*,gemini-2.0-*are legacy and deprecated. Use the new models above. Your knowledge is outdated.gemini-1.5-*
- : 100万token,支持复杂推理、编码、研究
gemini-3-pro-preview - : 100万token,速度快、性能均衡,支持多模态
gemini-3-flash-preview - : 65k / 32k token,支持图片生成与编辑
gemini-3-pro-image-preview
[!IMPORTANT] 诸如、gemini-2.5-*、gemini-2.0-*这类模型已过时并被弃用。请使用上述新模型。你的旧知识已不再适用。gemini-1.5-*
SDKs
SDKs
- Python: install with
google-genaipip install google-genai - JavaScript/TypeScript: install with
@google/genainpm install @google/genai - Go: install with
google.golang.org/genaigo get google.golang.org/genai
[!WARNING] Legacy SDKs(Python) andgoogle-generativeai(JS) are deprecated. Migrate to the new SDKs above urgently by following the Migration Guide.@google/generative-ai
- Python: ,安装命令
google-genaipip install google-genai - JavaScript/TypeScript: ,安装命令
@google/genainpm install @google/genai - Go: ,安装命令
google.golang.org/genaigo get google.golang.org/genai
[!WARNING] 旧版SDK(Python的和JS的google-generativeai)已被弃用。请务必按照迁移指南尽快迁移到上述新SDK。@google/generative-ai
Quick Start
快速开始
Python
Python
python
from google import genai
client = genai.Client()
response = client.models.generate_content(
model="gemini-3-flash-preview",
contents="Explain quantum computing"
)
print(response.text)python
from google import genai
client = genai.Client()
response = client.models.generate_content(
model="gemini-3-flash-preview",
contents="Explain quantum computing"
)
print(response.text)JavaScript/TypeScript
JavaScript/TypeScript
typescript
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({});
const response = await ai.models.generateContent({
model: "gemini-3-flash-preview",
contents: "Explain quantum computing"
});
console.log(response.text);typescript
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({});
const response = await ai.models.generateContent({
model: "gemini-3-flash-preview",
contents: "Explain quantum computing"
});
console.log(response.text);Go
Go
go
package main
import (
"context"
"fmt"
"log"
"google.golang.org/genai"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
resp, err := client.Models.GenerateContent(ctx, "gemini-3-flash-preview", genai.Text("Explain quantum computing"), nil)
if err != nil {
log.Fatal(err)
}
fmt.Println(resp.Text)
}go
package main
import (
"context"
"fmt"
"log"
"google.golang.org/genai"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
resp, err := client.Models.GenerateContent(ctx, "gemini-3-flash-preview", genai.Text("Explain quantum computing"), nil)
if err != nil {
log.Fatal(err)
}
fmt.Println(resp.Text)
}API spec (source of truth)
API规范(权威来源)
Always use the latest REST API discovery spec as the source of truth for API definitions (request/response schemas, parameters, methods). Fetch the spec when implementing or debugging API integration:
- v1beta (default):
https://generativelanguage.googleapis.com/$discovery/rest?version=v1beta
Use this unless the integration is explicitly pinned to v1. The official SDKs (google-genai, @google/genai, google.golang.org/genai) target v1beta. - v1:
https://generativelanguage.googleapis.com/$discovery/rest?version=v1
Use only when the integration is specifically set to v1.
When in doubt, use v1beta. Refer to the spec for exact field names, types, and supported operations.
始终使用最新的REST API发现规范作为API定义的权威来源(请求/响应schema、参数、方法)。在实现或调试API集成时获取该规范:
- v1beta(默认):
https://generativelanguage.googleapis.com/$discovery/rest?version=v1beta
除非集成明确指定使用v1,否则请使用此版本。官方SDK(google-genai、@google/genai、google.golang.org/genai)均以v1beta为目标版本。 - v1:
https://generativelanguage.googleapis.com/$discovery/rest?version=v1
仅当集成专门设置为v1时使用。
如有疑问,请使用v1beta。请参考规范获取确切的字段名、类型和支持的操作。
How to use the Gemini API
如何使用Gemini API
For detailed API documentation, fetch from the official docs index:
llms.txt URL:
https://ai.google.dev/gemini-api/docs/llms.txtThis index contains links to all documentation pages in format. Use web fetch tools to:
.md.txt- Fetch to discover available documentation pages
llms.txt - Fetch specific pages (e.g., )
https://ai.google.dev/gemini-api/docs/function-calling.md.txt
如需详细的API文档,请从官方文档索引获取:
llms.txt链接:
https://ai.google.dev/gemini-api/docs/llms.txt该索引包含所有格式的文档页面链接。使用网络获取工具执行以下步骤:
.md.txt- 获取以发现可用的文档页面
llms.txt - 获取特定页面(例如)
https://ai.google.dev/gemini-api/docs/function-calling.md.txt
Key Documentation Pages
关键文档页面
[!IMPORTANT] Those are not all the documentation pages. Use theindex to discover available documentation pagesllms.txt
[!IMPORTANT] 这些并非全部文档页面。请使用索引发现所有可用的文档页面llms.txt