← Docs

Gemini observability with Spanlens

Drop-in proxy for the Google Gemini API. One line of code, every call captured.

Spanlens captures every Google Gemini request your app makes — Gemini Pro, Flash, and Flash-Lite, plus multimodal (image, audio, video), grounding, and function calling — without changing your business logic. Works with both AI Studio API keys and Vertex AI service accounts.

What Spanlens captures for Gemini

Integration steps

  1. 1

    Get a Spanlens API key

    Sign up at spanlens.io and create a project. Copy the sl_live_* API key from the project dashboard.

  2. 2

    Install the SDK (TypeScript or Python)

    The drop-in SDK preserves the Google AI surface.

    # TypeScript
    npm install @spanlens/sdk @google/generative-ai
    
    # Python
    pip install spanlens google-generativeai
  3. 3

    Swap your import

    Replace the GoogleGenerativeAI client with the Spanlens drop-in. No other code changes needed.

    // Before
    import { GoogleGenerativeAI } from '@google/generative-ai'
    const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY)
    
    // After
    import { createGemini } from '@spanlens/sdk/gemini'
    const genAI = createGemini() // reads SPANLENS_API_KEY from env
  4. 4

    Or use the proxy (any language)

    For languages without an SDK, point the Gemini base URL at the Spanlens proxy and put your Spanlens key in the Authorization header.

    curl "https://api.spanlens.io/proxy/gemini/v1beta/models/gemini-2.5-flash:generateContent" \
      -H "Authorization: Bearer sl_live_..." \
      -H "Content-Type: application/json" \
      -d '{"contents":[{"parts":[{"text":"hello"}]}]}'
  5. 5

    Watch the dashboard

    Every Gemini call lands in /requests within ~1 second with token counts, model variant, and cost. Multimodal parts are inspected in the request detail view.

Gemini integration FAQ

Does Spanlens support Gemini streaming?

Yes. Gemini streams chunks via the streamGenerateContent endpoint, and Spanlens captures the full stream including usageMetadata from the final candidate. The original stream passes through to your client unmodified.

Does Spanlens support Gemini function calling?

Yes. Function declarations, function calls, and function responses are captured per turn. For multi-turn function-calling flows, Spanlens renders the conversation tree so you can see which call triggered which response.

Does Spanlens work with Vertex AI?

Yes. Vertex AI endpoints are supported alongside AI Studio. Specify the project ID and region in your Spanlens project settings, and authentication (service account JSON or ADC) is handled at proxy time without exposing the credential to logs.

How does Spanlens handle Gemini multimodal inputs?

Inline parts (image, audio, video, PDF) are captured by reference — Spanlens records the mime type and size but does not store the binary payload by default to keep logs lean. Set X-Spanlens-Log-Body: full to capture the full base64 payload.

How is Gemini cost calculated?

Cost is calculated from the candidatesTokenCount + promptTokenCount returned in usageMetadata against the Gemini price table. Free tier (AI Studio) requests are tracked with zero cost but still count toward your Spanlens quota.

Is my Gemini API key stored securely?

Yes. The Gemini API key (or Vertex service account JSON) is encrypted at rest with AES-256-GCM and never logged. It is decrypted only at proxy time and immediately discarded after the upstream call.

See every Gemini call in your dashboard within 60 seconds.