Gemini Messages
檔案分析
使用 Gemini Interactions API 分析圖像、影片、音訊與文件。
Gemini Interactions API 透過 input 陣列中的內容區塊支援多模態輸入。請先透過 Files API 上傳檔案,再於請求中引用傳回的 uri。
端點與驗證方式同文字生成。
路由前提
本頁為 Interactions 協定範例。目前本地網關程式只註冊 Gemini generateContent 路由,沒有註冊 /v1beta/interactions;只有部署環境另外提供此路由時才能執行本頁範例。一般 Gemini 客戶端請見 Gemini CLI,圖像生成請見 Nano Banana。若收到 404,不要只替換 URL:兩種協定的請求與回包不同。
內容區塊類型
| 類型 | 說明 |
|---|---|
text | 隨媒體輸入附上的文字提示 |
image | 包含 uri 與 mime_type 的圖像(如 image/jpeg、image/png) |
document | PDF 文件,使用 uri 與 mime_type: "application/pdf" |
video | 包含 uri 與 mime_type 的影片(如 video/mp4) |
audio | 包含 uri 與 mime_type 的音訊(如 audio/wav、audio/mp3) |
取得可用的檔案 URI
先使用 Tokatlas 已確認支援的上傳流程取得 uri,再替換下方 YOUR_FILE_URI。本頁未定義上傳端點或上傳請求格式,請先向服務管理者確認;其他供應商或帳戶的 URI 不一定可讀取。若檔案需要處理,請等到可用後再送出互動請求。
圖像分析
json
{
"model": "gemini-3.7-flash",
"input": [
{"type": "text", "text": "Tell me about this instrument"},
{
"type": "image",
"uri": "YOUR_FILE_URI",
"mime_type": "image/jpeg"
}
]
}影片分析
json
{
"model": "gemini-3.7-flash",
"input": [
{"type": "text", "text": "Summarize what happens in this video."},
{
"type": "video",
"uri": "YOUR_FILE_URI",
"mime_type": "video/mp4"
}
]
}音訊分析
json
{
"model": "gemini-3.7-flash",
"input": [
{"type": "text", "text": "Transcribe and summarize this audio."},
{
"type": "audio",
"uri": "YOUR_FILE_URI",
"mime_type": "audio/wav"
}
]
}文件分析
PDF 與其他文件請先透過 Files API 上傳,再引用其 URI:
json
{
"model": "gemini-3.7-flash",
"input": [
{"type": "text", "text": "Summarize the key points in this document."},
{
"type": "document",
"uri": "YOUR_FILE_URI",
"mime_type": "application/pdf"
}
]
}請求範例
執行方式見多語言範例說明。先設定 API_KEY,並替換模型、檔案網址及 ID 占位值;四種方式會顯示相同請求的原始回應。
bash
curl --fail-with-body --silent --show-error --max-time 180 \
--request POST \
--url "https://api.tokatlas.ai/v1beta/interactions" \
--header "x-goog-api-key: $API_KEY" \
--header "Content-Type: application/json" \
--data '{
"model": "gemini-3.7-flash",
"input": [
{
"type": "text",
"text": "Describe this image in detail."
},
{
"type": "image",
"uri": "YOUR_FILE_URI",
"mime_type": "image/jpeg"
}
]
}'python
import os
import requests
headers = {
'x-goog-api-key': os.environ["API_KEY"],
'Content-Type': 'application/json',
}
payload = {'model': 'gemini-3.7-flash',
'input': [{'type': 'text', 'text': 'Describe this image in detail.'},
{'type': 'image', 'uri': 'YOUR_FILE_URI', 'mime_type': 'image/jpeg'}]}
response = requests.request(
'POST', 'https://api.tokatlas.ai/v1beta/interactions', headers=headers,
json=payload,
timeout=180,
)
response.raise_for_status()
print(response.text)js
if (!process.env.API_KEY) throw new Error("Set API_KEY first.");
const response = await fetch("https://api.tokatlas.ai/v1beta/interactions", {
method: "POST",
headers: {
"x-goog-api-key": process.env.API_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify({
"model": "gemini-3.7-flash",
"input": [
{
"type": "text",
"text": "Describe this image in detail."
},
{
"type": "image",
"uri": "YOUR_FILE_URI",
"mime_type": "image/jpeg"
}
]
}),
signal: AbortSignal.timeout(180_000),
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${await response.text()}`);
}
console.log(await response.text());java
import java.net.URI;
import java.net.http.*;
import java.time.Duration;
public class Example {
public static void main(String[] args) throws Exception {
String apiKey = System.getenv("API_KEY");
if (apiKey == null || apiKey.isBlank()) {
throw new IllegalArgumentException("Set API_KEY first.");
}
String payload = String.join("\n",
"{",
" \"model\": \"gemini-3.7-flash\",",
" \"input\": [",
" {",
" \"type\": \"text\",",
" \"text\": \"Describe this image in detail.\"",
" },",
" {",
" \"type\": \"image\",",
" \"uri\": \"YOUR_FILE_URI\",",
" \"mime_type\": \"image/jpeg\"",
" }",
" ]",
"}"
);
HttpClient client = HttpClient.newBuilder()
.connectTimeout(Duration.ofSeconds(30)).build();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.tokatlas.ai/v1beta/interactions"))
.timeout(Duration.ofSeconds(180))
.header("x-goog-api-key", apiKey)
.header("Content-Type", "application/json")
.method("POST", HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<String> response = client.send(
request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() < 200 || response.statusCode() >= 300) {
throw new IllegalStateException("HTTP " + response.statusCode() + ": "
+ response.body());
}
System.out.println(response.body());
}
}回應範例
json
{
"id": "interaction_abc123",
"model": "gemini-3.7-flash",
"steps": [
{
"type": "model_output",
"content": [
{
"type": "text",
"text": "The image shows a vintage acoustic guitar with a sunburst finish, positioned against a dark background..."
}
]
}
],
"status": "completed"
}