Skip to main content
PromptLayer can auto-instrument the Google GenAI SDK in both Gemini Developer API and Vertex AI modes. Supported calls become OpenTelemetry spans and linked PromptLayer request logs without replacing the native provider client.

Supported APIs

Not documented means the surface is outside the verified coverage for that language. Other Google GenAI SDK calls continue to work normally, but unsupported surfaces do not automatically create PromptLayer traces or request logs.

Prerequisites

  • A PromptLayer API key for the workspace that should receive the traces
  • A Gemini API key, or standard Google Cloud credentials, project, and location for Vertex AI
  • Python 3.10 or later for Python, or Node.js 20 or later for JavaScript
For Gemini Developer API calls, export:
PromptLayer captures supported message content by default. Review the content-capture behavior and opt-out values before sending provider requests.

Python

1. Install the SDKs

2. Configure Google GenAI instrumentation

The same google selector instruments a client created with vertexai=True:
If your application already creates a PromptLayer client, select Google when enabling tracing:
Omit tracing_providers to instrument every supported provider SDK that is installed.

JavaScript

1. Install the SDKs

2. Preload PromptLayer instrumentation

The preload must run before the application imports @google/genai:

3. Use the Google GenAI SDK normally

The same instrumentation supports a client created in Vertex AI mode:
The preload instruments every supported provider. To instrument only Google, call configureTracing({ providers: ["google"] }) in a bootstrap module and dynamically import the application afterward. See Select Providers.

Verify the Integration

Run one supported Google GenAI request, flush or shut down tracing, and open Traces in PromptLayer. The provider span should have an associated request log and identify Gemini Developer API or Vertex AI mode. If no span appears:
  • Confirm instrumentation is configured before the first Google GenAI request.
  • In JavaScript, confirm the preload or bootstrap runs before @google/genai loads.
  • Confirm the call uses an API surface listed in Supported APIs.
  • Confirm PROMPTLAYER_API_KEY belongs to the workspace you are checking.
  • Flush or shut down tracing before a short-lived process exits.