← Docs

OpenAI observability with Spanlens

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

Spanlens captures every OpenAI request your app makes — chat completions, embeddings, vision, audio, tool use, and structured outputs — without changing your business logic. Swap the SDK import or the baseURL and the existing OpenAI client keeps working with full observability layered underneath.

What Spanlens captures for OpenAI

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 OpenAI surface area — same methods, same types — and routes calls through Spanlens.

    # TypeScript
    npm install @spanlens/sdk
    
    # Python
    pip install spanlens
  3. 3

    Swap your import

    Replace the OpenAI import with the Spanlens drop-in. No other code changes needed.

    // Before
    import OpenAI from 'openai'
    const openai = new OpenAI()
    
    // After
    import { createOpenAI } from '@spanlens/sdk/openai'
    const openai = createOpenAI() // reads SPANLENS_API_KEY from env
  4. 4

    Or use the proxy (any language)

    If you cannot install an SDK (Ruby, Go, Rust, raw HTTP), point the OpenAI baseURL at the Spanlens proxy and put your Spanlens key in the Authorization header.

    curl https://api.spanlens.io/proxy/openai/v1/chat/completions \
      -H "Authorization: Bearer sl_live_..." \
      -H "Content-Type: application/json" \
      -d '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"hello"}]}'
  5. 5

    Watch the dashboard

    Every call lands in /requests within ~1 second with full body, model, tokens, latency, and cost. Filter, group, and replay.

OpenAI integration FAQ

Does Spanlens support OpenAI streaming?

Yes. Streaming chunks pass through to your client in real time via body.tee(), and Spanlens captures the full stream including usage data from the final chunk. Streaming responses count as one request.

Does Spanlens support OpenAI tool use and function calling?

Yes. Tool calls, tool results, parallel tool calls, and required tool use are all captured. The tool name, arguments, and outputs are visible in the request detail view and surface in agent tracing as separate spans.

How does Spanlens calculate OpenAI cost?

Cost is calculated per request from input + output tokens against the model price table. OpenAI returns the dated variant name (gpt-4o-mini-2024-07-18) in the response, and Spanlens matches by exact dated name then falls back to prefix match. Updated model prices ship with each release.

Is the OpenAI API key stored securely?

Yes. Your OpenAI key is encrypted at rest with AES-256-GCM and never logged. It is fetched, decrypted, and immediately discarded on each proxy call. The decryption key is held in environment-only configuration.

Does Spanlens work with Azure OpenAI?

Yes. Azure OpenAI endpoints are supported through the same proxy mechanism. Specify the Azure resource and deployment in your project settings, and the proxy routes to the right endpoint while logging the same shape of data.

Can I use Spanlens with the OpenAI Assistants API?

Yes. Assistant runs are captured per LLM step, and thread + run + step IDs surface as tags so you can filter or pivot on them. Multi-step agent flows render as a span tree.

See every OpenAI call in your dashboard within 60 seconds.