Gemini API
一個用於建立和擴展基於谷歌最新人工智慧模型的開發者平台。幾分鐘內即可開始。
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.0-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 2.5 Pro
Google 最強大的推理模型,擅長程式設計和複雜的推理工作
雙子座 2.5 閃光燈
我們最均衡的模型,擁有 100 萬個代幣的上下文視窗等等。
Gemini 2.5 手電筒
我們速度最快、成本效益最高的多模態模型,在高頻任務中表現出色。
Veo 3.1
我們採用最先進的視訊生成模型,並配備原生音訊。
Gemini 2.5 閃光燈影像(Nano Banana)
最先進的圖像生成及編輯模型
Gemini Embeddings
我們第一個 Gemini 嵌入模型,專為生產 RAG 工作流程設計
探索功能
原生圖像生成 (Nano Banana)
使用 Gemini 2.5 Flash Image 原生生成及編輯高度情境化的圖片。
長篇背景
將數百萬個令牌輸入到 Gemini 模型中,並從非結構化圖像、視訊和文件中獲得理解。
結構化輸出
限制 Gemini 只能以 JSON 回覆,這是一種適合自動處理的結構化資料格式。
函式呼叫
將 Gemini 連結至外部 API 和工具,建構代理工作流程。
使用 Veo 3.1 生成影片
利用我們最先進的模型,根據文字或圖像提示創建高品質的影片內容。
使用 Live API 的語音代理程式
使用 Live API 建構即時語音應用程式和代理程式。
工具
透過 Google 搜尋、網址內容、Google 地圖、程式碼執行和電腦使用等內建工具,讓 Gemini 連結至全球。
文件理解
最多可處理 1000 頁 PDF 檔案。
思維
探索思考能力如何提升對複雜任務和智能體的推理能力。