ログとデータセット

このガイドでは、Google AI Studio ダッシュボードで Gemini API の使用状況のログを表示して、モデルの動作とユーザーがアプリケーションを操作する方法を把握する方法について説明します。ロギングを使用して、デバッグを行い、必要に応じて使用状況に関する フィードバックを Google と共有して、デベロッパーのユースケース全体で Gemini の改善に役立てます*

Managed Agents を除く、GenerateContentBatchGenerateContentStreamGenerateContent API 呼び出しとInteractions API 呼び出しはすべてサポートされています。これには、 OpenAI 互換エンドポイントを介して行われた呼び出しも含まれます。

プロジェクトのロギングを構成する

デフォルトでは、サーバーサイドの状態管理機能の使用を簡素化するために、API はすべてのインタラクション オブジェクト(store=true)を保存します。一方、Generate Content API はデフォルトでリクエストを保存しません。保存するには、AI Studio からリクエストごとまたはプロジェクト レベルで保存を有効にする必要があります。

Google AI Studio では、すべてのプロジェクトまたは特定のプロジェクトのロギングを有効または 無効にできます。これらの設定は、 [ログとデータセット] ページの [**設定**] パネルでいつでも変更できます。generateContent API と Interactions API のロギングは個別にオンまたはオフに切り替えることができ、プロジェクトのデフォルトの保存動作を変更できます。

リクエストレベルのロギング

ストレージとロギングの動作は API によって異なります。

  • Interactions API: サーバーサイドの状態管理を簡素化するために、デフォルトでリクエストを保存します(store=true)。
  • Generate Content API(generateContent): デフォルトではリクエストを保存しません(store=false)。

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': False} # Set to True to enable 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: false // Set to true to enable logging of this request
    }
});

console.log(response.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("Tell me a fact about space."))
        .store(true)
        .build();

Interaction interaction =
    client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();

System.out.println(interaction.outputText().orElse(""));

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("Tell me a fact about space."))
        .store(true)
        .build();

Interaction interaction =
    client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();

System.out.println(interaction.outputText().orElse(""));

AI Studio でプロジェクト ログを表示する

  1. [AI Studio] の [ログ] ページに移動します。
  2. プルダウンからプロジェクトを選択します。
  3. ログが存在する場合は、Interactions API のテーブルに日付の新しい順に表示されます。
  4. Generate Content API のプロジェクト ログを確認するには、まず設定パネルでこの機能を有効にします。

エントリをクリックすると、ペイロードのプレビューが表示されます。Gemini からのプロンプトとレスポンスの全体、および前のターンのコンテキストを確認できます。Interactions API リクエストの場合、ログには previous_interaction_id への直接リンクも含まれます。

プロジェクト ストレージの保持期間を構成する

ログは、デフォルトの保持期間である 55 日後に期限切れとなり、削除対象としてマークされます(データセットに保存されている場合は期限切れになりません)。 プロジェクトのログの保持期間は、最大 7 日、14 日、28 日、55 日に構成できます。

データセットを作成して共有する

ログをデータセットに保存すると、より効率的に整理してエクスポートできます。

  • [ログ] ページの上部にあるフィルタバー で、フィルタするプロパティを選択します。
  • フィルタされたビューで、チェックボックスを使用してすべてのログまたは個々のログを選択します。
  • リストの上部に表示される [データセットを作成] ボタンをクリックします。
  • 新しいデータセットに名前と説明(省略可)を付けます。
  • 作成したデータセットが、キュレートされたログのセットとともに表示されます。
  • データセットを 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 を使用してログを再実行して、モデルまたはアプリケーション ロジックを評価します。