Vertex AI
Trace Gemini on Vertex AI with cetra from Python, through the Google Gen AI SDK.
Install
Section titled “Install”pip install "cetra-sdk[google-genai]" google-genaiSet up
Section titled “Set up”import os
import cetrafrom google import genai
cetra.init(instrument=["google-genai"])
client = genai.Client(vertexai=True, project=os.environ["GOOGLE_CLOUD_PROJECT"], location="us-central1")response = client.models.generate_content( model="gemini-2.5-flash", contents="What is the capital of France?",)print(response.text)
cetra.flush()What you get
Section titled “What you get”- Each
generateContentcall is anllmspan with the providergcp.gen_ai. - Input and output token counts come from the response.
- Cost comes from the built-in Gemini or Vertex AI price for the model.
Limits
Section titled “Limits”- The provider is
gcp.gen_ai, the same as for the Gemini API: the spans do not say which Google endpoint served the call. - Through Vertex AI’s OpenAI-compatible endpoint on a regional host (
<REGION>-aiplatform.googleapis.com), the provider shows asopenai; only the globalaiplatform.googleapis.comhost is mapped. - Calling Vertex AI needs a Google Cloud project and credentials. The fixtures were captured against cetra’s mock.
- The fixtures were captured with google-genai 2.34.0 and openinference-instrumentation-google-genai 1.5.0.
- If a field is missing, look at the span’s Attributes tab and compare it with Span attributes.
- Traces: read the trace as a tree and a timeline.
- Cost and tokens: how cost is computed from the token counts.
- Custom model prices: price a model the built-in prices do not cover.