Gemini API
开发者平台,可使用 Google 的最新 AI 模型进行构建和扩缩。几分钟即可开始使用。
Python
from google import genai
client = genai.Client()
response = client.models.generate_content(
model="gemini-2.5-flash",
contents="Explain how AI works in a few words",
)
print(response.text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({});
async function main() {
const response = await ai.models.generateContent({
model: "gemini-2.5-flash",
contents: "Explain how AI works in a few words",
});
console.log(response.text);
}
await main();
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)
}
result, err := client.Models.GenerateContent(
ctx,
"gemini-2.5-flash",
genai.Text("Explain how AI works in a few words"),
nil,
)
if err != nil {
log.Fatal(err)
}
fmt.Println(result.Text())
}
Java
package com.example;
import com.google.genai.Client;
import com.google.genai.types.GenerateContentResponse;
public class GenerateTextFromTextInput {
public static void main(String[] args) {
Client client = new Client();
GenerateContentResponse response =
client.models.generateContent(
"gemini-2.5-flash",
"Explain how AI works in a few words",
null);
System.out.println(response.text());
}
}
C#
using System.Threading.Tasks;
using Google.GenAI;
using Google.GenAI.Types;
public class GenerateContentSimpleText {
public static async Task main() {
var client = new Client();
var response = await client.Models.GenerateContentAsync(
model: "gemini-2.5-flash", contents: "Explain how AI works in a few words"
);
Console.WriteLine(response.Candidates[0].Content.Parts[0].Text);
}
}
REST
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [
{
"parts": [
{
"text": "Explain how AI works in a few words"
}
]
}
]
}'
按照我们的快速入门指南操作,您只需几分钟即可获取 API 密钥并发出第一个 API 调用。
对于大多数模型,您都可以从免费层级开始使用,而无需设置结算账号。
认识这些模型
Gemini 3 Pro
Google 最智能的模型,在多模态理解方面全球领先,全部基于先进的推理技术构建。
Gemini 2.5 Pro
我们强大的推理模型,擅长处理编码和复杂的推理任务。
Gemini 2.5 Flash
我们最均衡的一款模型,具有 100 万个词元的上下文窗口,以及更多功能。
Gemini 2.5 Flash-Lite
Google 旗下速度最快、最具成本效益的多模态模型,在高频任务方面表现出色。
Veo 3.1
我们最先进的视频生成模型,支持原生音频。
Gemini 2.5 Flash Image (Nano Banana)
先进的图片生成和编辑模型
探索功能
原生图片生成 (Nano Banana)
使用 Gemini 2.5 Flash Image 原生生成和编辑高度情境化的图片。
长上下文
向 Gemini 模型输入数百万个 token,并从非结构化图片、视频和文档中获取理解。
结构化输出
限制 Gemini 以 JSON(一种适合自动处理的结构化数据格式)进行回答。
函数调用
通过将 Gemini 连接到外部 API 和工具来构建智能体工作流。
使用 Veo 3.1 生成视频
使用我们最先进的模型,根据文本或图片提示创作高品质视频内容。
使用 Live API 的语音代理
使用 Live API 构建实时语音应用和代理。
工具
通过 Google 搜索、网址上下文、Google 地图、代码执行和电脑使用等内置工具,将 Gemini 与世界连接起来。
文档理解
处理最多 1,000 页的 PDF 文件。
思考
了解思维能力如何改进复杂任务和代理的推理能力。