> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pandaprobe.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Gemini

> Auto-trace Google Gemini generate_content API calls

### Installation

<Tabs>
  <Tab title="pip">
    ```bash theme={null}
    pip install "pandaprobe[gemini]"
    ```
  </Tab>

  <Tab title="uv">
    ```bash theme={null}
    uv add "pandaprobe[gemini]"
    ```
  </Tab>

  <Tab title="npm">
    ```bash theme={null}
    npm install pandaprobe @google/genai
    ```
  </Tab>

  <Tab title="yarn">
    ```bash theme={null}
    yarn add pandaprobe @google/genai
    ```
  </Tab>

  <Tab title="pnpm">
    ```bash theme={null}
    pnpm add pandaprobe @google/genai
    ```
  </Tab>
</Tabs>

### Setup

<Tabs>
  <Tab title="Python">
    ```python title="Python" theme={null}
    from pandaprobe.wrappers import wrap_gemini
    from google import genai

    client = wrap_gemini(genai.Client())
    ```
  </Tab>

  <Tab title="TypeScript">
    ```ts title="TypeScript" theme={null}
    import { GoogleGenAI } from "@google/genai";
    import { wrapGemini } from "pandaprobe/wrappers/gemini";

    const client = wrapGemini(new GoogleGenAI({ apiKey: process.env.GOOGLE_API_KEY }));
    ```
  </Tab>
</Tabs>

## Generate content

Span name: `"gemini-generate"`, SpanKind: `LLM`

```python title="Python" theme={null}
response = client.models.generate_content(
    model="gemini-3.1-flash-preview",
    contents="Explain quantum computing.",
    config={"temperature": 0.7},
)
print(response.text)
```

```ts title="TypeScript" theme={null}
const response = await client.models.generateContent({
  model: "gemini-3.8-flash",
  contents: "Explain quantum computing.",
  config: { temperature: 0.7 },
});
console.log(response.text);
```

**What gets traced**

* Input: `contents` plus `system_instruction` normalized to messages format (role `"model"` mapped to `"assistant"`)
* Output: answer text (non-thought parts)
* Model name
* Token usage
* Model parameters: `temperature`, `top_p`, `top_k`, `max_output_tokens`, `stop_sequences`, and related fields
* Thinking or reasoning parts stored in metadata as `reasoning_summary`

### Streaming

```python title="Python" theme={null}
stream = client.models.generate_content_stream(
    model="gemini-3.1-flash-preview",
    contents="Hello!",
)
for chunk in stream:
    print(chunk.text, end="")
```

```ts title="TypeScript streaming" theme={null}
const stream = await client.models.generateContentStream({
  model: "gemini-3.8-flash",
  contents: "Hello!",
});
for await (const chunk of stream) {
  process.stdout.write(chunk.text ?? "");
}
```

<Note>
  PandaProbe traces Python's synchronous and asynchronous APIs and TypeScript's Promise-based APIs with the same span fields.
</Note>

## Thinking mode

When using Gemini's thinking mode, thought parts are automatically separated from answer parts. Thought content is stored in metadata as `reasoning_summary`, while the span output contains only the answer text.

## Token usage mapping

| Gemini Field | PandaProbe Field |
| - | - |
| `prompt_token_count` | `prompt_tokens` |
| `candidates_token_count` | `completion_tokens` |
| `total_token_count` | `total_tokens` |
| `thoughts_token_count` | `reasoning_tokens` |
| `cached_content_token_count` | `cache_read_tokens` |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.