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

# Vertex AI

> Trace Google Vertex AI model calls with Netra auto-instrumentation. Monitor prompts, completions, token usage, and performance on GCP automatically.

<img src="https://mintcdn.com/netra/IXT7TOAHn4HQhvyF/images/integration-logos/llm-providers/vertex-ai.png?fit=max&auto=format&n=IXT7TOAHn4HQhvyF&q=85&s=da7ccb98f93f8782738baaafed177349" alt="Vertex AI" width="356" height="80" data-path="images/integration-logos/llm-providers/vertex-ai.png" />

## Installation

Install both the Netra SDK and Google Cloud Vertex AI SDK:

<CodeGroup>
  ```bash Python theme={null}
  pip install netra-sdk google-cloud-aiplatform
  ```

  ```bash Typescript theme={null}
  npm install netra-sdk @google-cloud/vertexai
  ```
</CodeGroup>

## Usage

Initialize the Netra SDK with Vertex AI instrumentation enabled. The SDK automatically traces all Vertex AI API calls once initialized.

<CodeGroup>
  ```python Python theme={null}
  from netra import Netra
  from vertexai.preview.generative_models import GenerativeModel
  import vertexai
  import os

  # Initialize Netra with Vertex AI instrumentation
  Netra.init(
      app_name="my-ai-app",
      headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}",
      trace_content=True
  )

  # Use Vertex AI client as usual - all calls are automatically traced
  vertexai.init(project="your-project-id", location="us-central1")

  model = GenerativeModel("gemini-pro")

  response = model.generate_content("What is observability?")
  print(response.text)
  ```

  ```typescript Typescript theme={null}
  import { Netra } from "netra-sdk";
  import { VertexAI } from "@google-cloud/vertexai";

  async function main() {
    // Initialize Netra with Vertex AI instrumentation (must await)
    await Netra.init({
      appName: "my-ai-app",
      headers: `x-api-key=${process.env.NETRA_API_KEY}`,
      traceContent: true
    });

    // Use Vertex AI client as usual - all calls are automatically traced
    const vertexAI = new VertexAI({
      project: "your-project-id",
      location: "us-central1"
    });

    const model = vertexAI.getGenerativeModel({ model: "gemini-pro" });

    const result = await model.generateContent("What is observability?");
    const response = await result.response;

    console.log(response.text());
  }

  main();
  ```
</CodeGroup>

### Streaming Responses

The SDK automatically handles streaming responses and captures the complete output:

<CodeGroup>
  ```python Python theme={null}
  model = GenerativeModel("gemini-pro")

  responses = model.generate_content("Tell me a story", stream=True)

  for response in responses:
      print(response.text, end="")
  ```

  ```typescript Typescript theme={null}
  const model = vertexAI.getGenerativeModel({ model: "gemini-pro" });

  const result = await model.generateContentStream("Tell me a story");

  for await (const chunk of result.stream) {
    const chunkText = chunk.text();
    process.stdout.write(chunkText);
  }
  ```
</CodeGroup>

### Chat Sessions

Chat operations are also automatically instrumented:

<CodeGroup>
  ```python Python theme={null}
  model = GenerativeModel("gemini-pro")

  chat = model.start_chat()

  response1 = chat.send_message("Hello")
  print(response1.text)

  response2 = chat.send_message("What is machine learning?")
  print(response2.text)
  ```

  ```typescript Typescript theme={null}
  const model = vertexAI.getGenerativeModel({ model: "gemini-pro" });

  const chat = model.startChat();

  const result1 = await chat.sendMessage("Hello");
  console.log(result1.response.text());

  const result2 = await chat.sendMessage("What is machine learning?");
  console.log(result2.response.text());
  ```
</CodeGroup>

### Selective Instrumentation

Control which integrations are enabled using the `instruments` or `blockInstruments` configuration:

<CodeGroup>
  ```python Python theme={null}
  from netra import Netra
  from netra.instrumentation.instruments import InstrumentSet

  # Only enable Vertex AI instrumentation
  Netra.init(
      headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}",
      instruments={InstrumentSet.VERTEXAI}
  )

  # Or block specific instrumentations
  Netra.init(
      headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}",
      block_instruments={InstrumentSet.HTTPX}
  )
  ```

  ```typescript Typescript theme={null}
  import { Netra, NetraInstruments } from "netra-sdk";

  // Only enable Vertex AI instrumentation
  await Netra.init({
    headers: `x-api-key=${process.env.NETRA_API_KEY}`,
    instruments: new Set([NetraInstruments.VERTEXAI])
  });

  // Or block specific instrumentations
  await Netra.init({
    headers: `x-api-key=${process.env.NETRA_API_KEY}`,
    blockInstruments: new Set([NetraInstruments.HTTP])
  });
  ```
</CodeGroup>

## Next Steps

* [Quick Start Guide](https://docs.getnetra.ai/quick-start/python) - Complete setup and configuration
* [Auto Instrumentation](https://docs.getnetra.ai/tracing/auto-instrumentation) - Automatic tracing for supported libraries
* [Decorators](https://docs.getnetra.ai/tracing/decorators) - Add custom tracing with `@workflow`, `@agent`, and `@task` decorators
* [Session Tracking](https://docs.getnetra.ai/tracing/session) - Track user sessions and conversations
* [Vertex AI Documentation](https://cloud.google.com/vertex-ai/docs/start/introduction-unified-platform) - Official Google Cloud Vertex AI documentation
