Observability for Google Gemini (TypeScript) with Opik
Observability for Google Gemini (TypeScript) with Opik
Observability for Google Gemini (TypeScript) with Opik
Opik provides seamless integration with the Google Generative AI Node.js SDK (@google/genai) through the opik-gemini package, allowing you to trace, monitor, and debug your Gemini API calls.

@google/genai ≥ 1.0.0)Note: The official Google GenAI SDK package is @google/genai (not @google/generative-ai). This is Google Deepmind’s unified SDK for both Gemini Developer API and Vertex AI.
To trace your Gemini API calls, you need to wrap your Gemini client instance with the trackGemini function:
The integration fully supports Gemini’s streaming responses:
The trackGemini function accepts an optional configuration object to customize the integration:
The integration also supports Google’s VertexAI platform. Simply configure your Gemini client for VertexAI and wrap it with trackGemini:
Track multi-turn chat conversations with Gemini:
Missing Traces: Ensure your Gemini and Opik API keys are correct and that you’re calling await trackedGenAI.flush() before your application exits.
Incomplete Data: For streaming responses, make sure you’re consuming the entire stream before ending your application.
Hierarchical Traces: To create proper parent-child relationships, use the parent option in the configuration when you want Gemini calls to be children of another trace.
Performance Impact: The Opik integration adds minimal overhead to your Gemini API calls.
VertexAI Authentication: When using VertexAI, ensure you have properly configured your Google Cloud project credentials.