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
這是我們最強大的模型,也是全球最出色的多模態理解模型,採用最先進的推理技術建構而成。
Gemini 2.5 Pro
Google 強大的推理模型,擅長程式設計和複雜的推理工作。
Gemini 2.5 Flash
這是我們表現最均衡的模型,脈絡窗口達 100 萬個詞元,而且還能執行更多工作。
Gemini 2.5 Flash-Lite
這是我們速度最快、成本效益最高的多模態模型,非常適合用於高頻率工作。
Veo 3.1
Google 最先進的影片生成模型,支援原生音訊。
Gemini 2.5 Flash Image (Nano Banana)
最先進的圖像生成及編輯模型
探索各種功能
原生圖像生成 (Nano Banana)
使用 Gemini 2.5 Flash Image 原生生成及編輯高度情境化的圖片。
長篇脈絡資訊
將數百萬個權杖輸入 Gemini 模型,從非結構化圖片、影片和文件中取得理解。
結構化輸出內容
限制 Gemini 只能以 JSON 回覆,這是一種適合自動處理的結構化資料格式。
函式呼叫
將 Gemini 連結至外部 API 和工具,建構代理工作流程。
使用 Veo 3.1 生成影片
使用最先進的模型,根據文字或圖片提示生成高品質影片內容。
使用 Live API 的語音代理程式
使用 Live API 建構即時語音應用程式和代理程式。
工具
透過 Google 搜尋、網址內容、Google 地圖、程式碼執行和電腦使用等內建工具,讓 Gemini 連結至全球。
文件解讀
處理最多 1000 頁的 PDF 檔案。
思考型
瞭解思考能力如何提升複雜工作和代理程式的推理能力。