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

# Google Vertex AI

> Python auto-instrumentation for Google Vertex AI

Python auto-instrumentation library for VertexAI SDK and the Google Cloud AI Platform. Traces are fully OpenTelemetry compatible and can be sent to any OpenTelemetry collector for viewing, such as [Arize Phoenix](https://github.com/Arize-ai/phoenix).

## Installation

```bash theme={null}
pip install -Uqqq openinference-instrumentation-vertexai
```

## Quickstart

Install dependencies:

```bash theme={null}
pip install -U \
    openinference-instrumentation-vertexai \
    arize-phoenix \
    opentelemetry-sdk \
    opentelemetry-exporter-otlp \
    "opentelemetry-proto>=1.12.0"
```

### Start Phoenix server

Start the `phoenix` server so that it is ready to receive traces. The `phoenix` server runs entirely on your machine and does not send data over the internet.

```bash theme={null}
python -m phoenix.server.main serve
```

### Setup instrumentation

Instrumenting `vertexai` is simple:

```python theme={null}
from openinference.instrumentation.vertexai import VertexAIInstrumentor
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor

endpoint = "http://127.0.0.1:4317"
tracer_provider = TracerProvider()
tracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint)))

VertexAIInstrumentor().instrument(tracer_provider=tracer_provider)
```

### Use Vertex AI

Now, all calls by `generative_models` are instrumented and can be viewed in the `phoenix` UI:

```python theme={null}
import vertexai
from vertexai.generative_models import GenerativeModel

vertexai.init(location="us-central1")
model = GenerativeModel("gemini-1.5-flash")

print(model.generate_content("Why is sky blue?"))
```

Visit the Phoenix app at `http://localhost:6006` to see your traces.

## More Info

* [OpenInference and Phoenix documentation](https://docs.arize.com/phoenix)
* [How to customize spans to track sessions, metadata, etc.](https://github.com/Arize-ai/openinference/tree/main/python/openinference-instrumentation#customizing-spans)
* [How to account for private information and span payload customization](https://github.com/Arize-ai/openinference/tree/main/python/openinference-instrumentation#tracing-configuration)
* [PyPI package](https://pypi.org/project/openinference-instrumentation-vertexai/)
