本指南說明如何在 Google AI Studio 資訊主頁查看 Gemini API 使用記錄,進一步瞭解模型行為,以及使用者與應用程式的互動方式。使用記錄功能觀察、偵錯,並視需要與 Google 分享使用意見回饋,協助改善 Gemini 在各種開發人員用途的表現。*
支援所有 GenerateContent、BatchGenerateContent、StreamGenerateContent API 呼叫,以及不含代管代理的 Interactions API 呼叫。包括透過 OpenAI 相容性端點發出的呼叫。
設定專案記錄
根據預設,Interactions API 和 Generate Content API 都會儲存要求 (store=true)。如果是 Interactions API,這也會啟用伺服器端狀態管理功能。
在 Google AI Studio 中,您可以啟用或停用個別專案的儲存功能,並隨時透過 Gemini API 記錄資訊主頁的「設定」面板變更這些偏好設定。您可以分別開啟或關閉 generateContent API 和 Interactions API 的記錄功能,變更專案的預設儲存行為。
要求層級記錄
兩個 API 預設都會儲存要求 (store=true):
- Interactions API:預設會儲存要求,簡化伺服器端狀態管理。
- Generate Content API (
generateContent、streamGenerateContent和batchGenerateContent):根據預設,系統會儲存 2026 年 10 月 26 日當天或之後建立的專案要求。在該日期前建立的專案,預設不會儲存要求 (store=false),除非在 AI Studio 啟用記錄功能。
要求層級的 store 屬性優先順序高於專案層級設定。如要在 Generate Content API 要求中設定 store,必須使用 google-genai 2.33.0 以上版本的 Python、@google/genai 2.31.0 以上版本的 JavaScript、google-genai 1.79.0 以上版本的 Java,以及 google.golang.org/genai 1.76.0 以上版本的 Go。設定 store 屬性的方法如下:
GenerateContent API
Python
from google import genai
client = genai.Client()
response = client.models.generate_content(
model='gemini-3.8-flash',
contents='Explain quantum entanglement in simple terms.',
config={'store': True} # Set to False to disable logging of this request
)
print(response.text)
JavaScript
import { GoogleGenAI } from '@google/genai';
const client = new GoogleGenAI({});
const response = await client.models.generateContent({
model: 'gemini-3.8-flash',
contents: 'Explain quantum entanglement in simple terms.',
config: {
store: true // Set to false to disable logging of this request
}
});
console.log(response.text);
Java
import com.google.genai.Client;
import com.google.genai.types.GenerateContentConfig;
import com.google.genai.types.GenerateContentResponse;
Client client = new Client();
GenerateContentResponse response =
client.models.generateContent(
"gemini-3.8-flash",
"Explain quantum entanglement in simple terms.",
GenerateContentConfig.builder()
.store(true) // Set to false to disable logging of this request
.build());
System.out.println(response.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)
}
response, err := client.Models.GenerateContent(
ctx,
"gemini-3.8-flash",
genai.Text("Explain quantum entanglement in simple terms."),
&genai.GenerateContentConfig{
Store: genai.Ptr(true), // Set to false to disable logging of this request
},
)
if err != nil {
log.Fatal(err)
}
fmt.Println(response.Text())
}
Interactions API
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3.8-flash",
input="Explain quantum entanglement in simple terms.",
store=True # Set to False to disable logging of this request
)
print(interaction.outputs[-1].text)
JavaScript
import { GoogleGenAI } from '@google/genai';
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
model: 'gemini-3.8-flash',
input: 'Explain quantum entanglement in simple terms.',
store: true // Set to false to disable logging of this request
});
console.log(interaction.outputs[interaction.outputs.length - 1].text);
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
Client client = new Client();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("gemini-3.8-flash"))
.input(InteractionsInput.of("Explain quantum entanglement in simple terms."))
.store(true) // Set to false to disable logging of this request
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println(interaction.outputText().orElse(""));
Go
package main
import (
"context"
"fmt"
"log"
"google.golang.org/genai"
"google.golang.org/genai/interactions/models/interactions"
"google.golang.org/genai/interactions/models/operations"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
Model: interactions.Model("gemini-3.8-flash"),
Input: interactions.NewInteractionsInput("Explain quantum entanglement in simple terms."),
Store: genai.Ptr(true), // Set to false to disable logging of this request
}),
})
if err != nil {
log.Fatal(err)
}
if res.Interaction.OutputText != nil {
fmt.Println(*res.Interaction.OutputText)
}
}
在 AI Studio 查看專案記錄
- 前往 AI Studio 的「記錄」頁面。
- 從下拉式選單中選取專案。
- 記錄會按照時間順序由新至舊顯示在表格中 (如有)。
- 如果是 2026 年 10 月 26 日前建立的專案,請先在設定面板啟用 Generate Content API 記錄功能,才能查看 Generate Content API 的專案記錄。
按一下項目即可預覽酬載。您可以查看 Gemini 的完整提示和回覆,以及先前對話的背景資訊。如果是 Interactions API 要求,記錄也會包含 previous_interaction_id 的直接連結。
設定專案儲存空間保留
記錄會在預設的 55 天保留期限後到期,並標示為刪除 (除非儲存至資料集,則不會到期)。您可以將專案記錄的保留期限設為 7、14、28 或最多 55 天。
建立及共用資料集
您可以將記錄儲存至資料集,更有效地整理及匯出記錄。
- 在「Logs」(記錄) 頁面,找出頂端的篩選列,選取要篩選的屬性。
- 在篩選檢視畫面中,使用核取方塊選取所有或個別記錄。
- 點選清單頂端的「建立資料集」按鈕。
- 為新資料集命名,並視需要新增說明。
- 您會看到剛才建立的資料集,其中包含精選記錄。
- 將資料集匯出為 CSV、JSONL 檔案或 Google 試算表,以便進一步分析。
資料集在許多不同用途中都能派上用場。
- 建立挑戰集:針對您希望 AI 改進的領域,推動未來改善。
- 精選樣本集:例如,從實際使用情況中挑選樣本,用於生成其他模型的回覆,或收集極端案例,在部署前進行例行檢查。
- 評估集:代表重要功能實際使用情形的資料集,用於比較其他模型或系統指令疊代。
您可以選擇將資料集做為示範範例提供給 Google,協助 Gemini 的研究與開發。
限制
目前不支援記錄下列項目:
- Imagen 和 Veo 模型
- Gemini 嵌入模型
- Gemini Robotics 模型
- 輸入內容包含影片、GIF 或 PDF
- Gemini API 中的公開預先發布版代理
後續步驟
- 使用工作階段記錄設計原型:透過 AI Studio Build 直覺式程式開發應用程式,並新增 API 金鑰,啟用 AI 功能的 Gemini API 記錄。
- 使用 Gemini Batch API 重新執行記錄:使用 Gemini Batch API 重新執行記錄,即可使用資料集進行回覆取樣,以及評估模型或應用程式邏輯。