google-genai) and Node.js (@google/genai). After you initialize tracing, each call you make inside a conversation is recorded in Agent Lens as an LLM span with its messages, system instructions, tools, media, request settings, response metadata, and token usage, including cached input and thinking tokens. You don’t change how you call the Google Gen AI SDK.
The integration traces content generation (including streaming), chat helpers, and Imagen image generation. Calls through a Vertex AI client are attributed to vertex_ai, and Gemini Developer API calls are attributed to gemini.
To trace agents built with Google’s Agent Development Kit (ADK), see Google ADK.
Prerequisites
- A CoreWeave Forge account and API key set as a
WANDB_API_KEYenvironment variable. - A Gemini API key set as a
GEMINI_API_KEYenvironment variable. - For Python: Python 3.10 or later and
google-genai1.0.0 through 1.23.0. - For TypeScript: Node.js 18.19 or later (or 20.6 or later) and
@google/genai0.2.0 or later.
Install packages
Trace Google Gen AI conversations
Calltracing.init() with your Forge team and project names. In Python, tracing.init() patches the Google Gen AI SDK, whether you import it before or after the call. In TypeScript, start Node with the instrumentation flag shown in the TypeScript tab.
Agent Lens shows only calls that run inside a conversation. A call made outside a conversation has no conversation ID, so it doesn’t appear in Agent Lens. Create one conversation for each agent session, and start a turn for each user message. Every turn shares the conversation’s ID, so Agent Lens groups the turns into one conversation, and each call becomes an LLM span of the turn it runs in.
- Python
- TypeScript
conversation_id (Python) or conversationId (TypeScript) each time you create the conversation.
For more about conversations, turns, and the other span types, see Trace your agents.
Turn off automatic patching
In Python, passautopatch_integrations=False to tracing.init(). You can then patch and unpatch the Google Gen AI SDK yourself with tracing.integrations.patch_google_genai() and tracing.integrations.unpatch_google_genai().
In TypeScript, run without the --import=@coreweave/forge-sdk/instrument flag, and wrap only the clients you want to trace with integrations.wrapGoogleGenAI().