SPB Git

Repository Public

logs-datasets.md 8.2 KB 199 lines markdown

1In this guide you'll learn how to2view logs from Gemini API usage in the Google AI Studio dashboard3to better understand model behavior and how users may be interacting with your4applications. Use logging to observe, debug, and *optionally share usage5feedback with Google to help improve Gemini across developer use cases* .^[\*](https://ai.google.dev/gemini-api/docs/logs-policy)^67All `GenerateContent`, `BatchGenerateContent`, `StreamGenerateContent` API8calls, and [Interactions](https://ai.google.dev/gemini-api/docs/interactions) API calls excluding9Managed Agents are supported. This includes calls made through10[OpenAI compatibility](https://ai.google.dev/gemini-api/docs/openai) endpoints.1112> [!NOTE]13> **Note:** Storage for Gemini API logs are only available for projects on the Gemini API paid tier.1415## Configure project logging1617By default, the API stores all interaction objects (`store=true`) in order to18simplify use of server-side state management features. In contrast, the19Generate Content API does not store requests by default, and requires storage20to be enabled per-request or at the project-level from AI Studio.2122In Google [AI Studio](https://aistudio.google.com/logs) you can enable or23disable logging for all projects or for specific projects and change these24preferences at any time through the **Settings** panel in the25[Logs and Datasets](https://aistudio.google.com/logs) page. Logging can be toggled on or off26independently for the `generateContent` API and the27[Interactions](https://ai.google.dev/gemini-api/docs/interactions) API28to change the default storage behavior for a project.2930> [!WARNING]31> **Warning:** Toggling Interactions API logging *off* in the AI Studio **Settings** panel will prevent the API from automatically storing and retrieving conversation history unless explicitly overridden per-request.3233### Request-level logging3435Storage and logging behavior differs by API:3637- **[Interactions API](https://ai.google.dev/gemini-api/docs/interactions):** Stores requests by default (`store=true`) to simplify server-side state management.38- **Generate Content API (`generateContent`):** Does not store requests by default (`store=false`).3940Here is how you can set the `store` property:4142**GenerateContent API**4344### Python4546    from google import genai4748    client = genai.Client()4950    response = client.models.generate_content(51        model='gemini-3.8-flash',52        contents='Explain quantum entanglement in simple terms.',53        config={'store': False} # Set to True to enable logging of this request54    )5556    print(response.text)5758### JavaScript5960    import { GoogleGenAI } from '@google/genai';6162    const client = new GoogleGenAI({});6364    const response = await client.models.generateContent({65        model: 'gemini-3.8-flash',66        contents: 'Explain quantum entanglement in simple terms.',67        config: {68            store: false // Set to true to enable logging of this request69        }70    });7172    console.log(response.text);7374### Java7576    import com.google.genai.Client;77    import com.google.genai.types.GenerateContentConfig;78    import com.google.genai.types.GenerateContentResponse;7980    Client client = new Client();8182    // The GenerateContent API does not store requests by default83    GenerateContentResponse response =84        client.models.generateContent(85            "gemini-3.8-flash",86            "Explain quantum entanglement in simple terms.",87            GenerateContentConfig.builder().build());8889    System.out.println(response.text());9091**Interactions API**9293### Python9495    from google import genai9697    client = genai.Client()9899    interaction = client.interactions.create(100        model="gemini-3.8-flash",101        input="Explain quantum entanglement in simple terms.",102        store=True # Set to False to disable logging of this request103    )104105    print(interaction.outputs[-1].text)106107### JavaScript108109    import { GoogleGenAI } from '@google/genai';110111    const client = new GoogleGenAI({});112113    const interaction = await client.interactions.create({114        model: 'gemini-3.8-flash',115        input: 'Explain quantum entanglement in simple terms.',116        store: true // Set to false to disable logging of this request117    });118119    console.log(interaction.outputs[interaction.outputs.length - 1].text);120121### Java122123    import com.google.genai.Client;124    import com.google.genai.gaos.models.interactions.CreateModelInteraction;125    import com.google.genai.gaos.models.interactions.Interaction;126    import com.google.genai.gaos.models.interactions.InteractionsInput;127    import com.google.genai.gaos.models.interactions.Model;128    import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;129130    Client client = new Client();131132    CreateModelInteraction params =133        CreateModelInteraction.builder()134            .model(Model.of("gemini-3.8-flash"))135            .input(InteractionsInput.of("Explain quantum entanglement in simple terms."))136            .store(true) // Set to false to disable logging of this request137            .build();138139    Interaction interaction =140        client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();141142    System.out.println(interaction.outputText().orElse(""));143144## View project logs in AI Studio1451461. Go to the Logs page in [AI Studio](https://aistudio.google.com/logs).1472. Select a project from the drop-down.1483. Logs will appear in the table in reverse chronological order for the Interactions API, if they exist.1494. To observe project logs for the Generate Content API, first enable this in the [settings panel](https://ai.google.dev/gemini-api/docs/logs-datasets#configure-logging).150151> [!NOTE]152> **Note:** A project requires at least one active API key for logs to be displayed. If all API keys in a project are deleted (for example, if a leaked key was deleted), you will lose visibility of the project's logs until an API key is available.153154Click an entry for a preview of the payload. You can155inspect the full prompt and response from Gemini, and the context from the156previous turns. For **Interactions API** requests, logs also include a direct157link to the `previous_interaction_id`.158159## Configure project storage retention160161Logs will expire and be marked for deletion after a default retention window of16255 days (unless [saved to a dataset](https://ai.google.dev/gemini-api/docs/logs-datasets#create), which don't expire).163You can configure the retention window of a project's logs to 7, 14, 28, or 55164days max.165166## Create and share datasets167168You can save logs to datasets to organize and export them more effectively.169170- From the [Logs page](https://aistudio.google.com/logs), locate the filter bar at the top to select a property to filter by.171- From your filtered view, use the checkboxes to select all or individual logs.172- Click the **Create dataset** button that appears at the top of the list.173- Give your new dataset a name and optional description.174- You will see the dataset you just created with the curated set of logs.175- Export your dataset for further analysis as CSV, JSONL files or to Google Sheets.176177Datasets can be helpful for a number of different use cases.178179- **Curate challenge sets:** Drive future improvements that target areas where you want your AI to improve.180- **Curate sample sets:** For example, a sample from real usage to generate responses from another model, or a collection of edge cases for routine checks before deployment.181- **Evaluation sets:** Sets that are representative of real usage across important capabilities, for comparison across other models or system instruction iterations.182183You can contribute to Gemini research and development by choosing to share184your datasets with Google as demonstration examples.185186## Limitations187188Logging is not currently supported for the following:189190- Imagen and Veo models191- Gemini embedding models192- Gemini Robotics model193- Inputs containing videos, GIFs or PDFs194- Public Preview Agents in the Gemini API195196## What's next197198- **Prototype with session history:** Use [AI Studio Build](https://aistudio.google.com/apps) to vibe code apps and add your API key to enable a history of Gemini API logs for AI features.199- **Re-run logs with the Gemini Batch API:** Use datasets for response sampling and evaluation of models or application logic by re-running logs with the [Gemini Batch API](https://github.com/google-gemini/cookbook/blob/main/examples/Datasets.ipynb).
Files main
Menu

Theme