← Docs

Anthropic observability with Spanlens

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

Spanlens captures every Anthropic API call your app makes — Claude Opus, Sonnet, and Haiku, plus tool use, vision, and prompt caching — without changing your business logic. The Anthropic SDK keeps working unchanged with full observability layered underneath.

What Spanlens captures for Anthropic

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 mirrors the Anthropic surface area exactly.

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

    Swap your import

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

    // Before
    import Anthropic from '@anthropic-ai/sdk'
    const anthropic = new Anthropic()
    
    // After
    import { createAnthropic } from '@spanlens/sdk/anthropic'
    const anthropic = createAnthropic() // reads SPANLENS_API_KEY from env
  4. 4

    Or use the proxy (any language)

    For languages without an SDK, point the Anthropic base URL at the Spanlens proxy and put your Spanlens key in the Authorization header. The x-api-key header for Anthropic auth is still passed through.

    curl https://api.spanlens.io/proxy/anthropic/v1/messages \
      -H "Authorization: Bearer sl_live_..." \
      -H "anthropic-version: 2023-06-01" \
      -H "Content-Type: application/json" \
      -d '{"model":"claude-sonnet-4-5","max_tokens":1024,"messages":[{"role":"user","content":"hi"}]}'
  5. 5

    Watch the dashboard

    Every Claude call lands in /requests within ~1 second with input + output + cache token breakdown, latency, model variant, and cost.

Anthropic integration FAQ

Does Spanlens support Anthropic streaming?

Yes. Anthropic streams differ from OpenAI — usage data arrives in the message_delta event rather than the final chunk. Spanlens has provider-specific parsers that handle this, so token counts and cost are correct for streamed Claude responses.

Does Spanlens capture prompt caching usage?

Yes. cache_creation_input_tokens and cache_read_input_tokens are captured separately so you see the cache hit rate and the cost saved from caching. Cost calculation uses the discounted cache-read rate.

Does Spanlens work with Claude on AWS Bedrock?

Yes. Bedrock Claude calls route through the same proxy with SigV4 auth handled by your SDK. The provider key field stores your AWS credentials encrypted with AES-256-GCM.

How does Spanlens handle Anthropic extended thinking?

Reasoning tokens are captured as a separate field in the request detail view. They are billed by Anthropic as output tokens, and Spanlens reflects that in cost — but the visible split lets you see how much of your spend is reasoning vs final output.

Can I use Spanlens with Claude tool use and agents?

Yes. Tool input, tool result, and parallel tool use are all captured. For multi-step agent flows (e.g. Claude with a chain of tool calls), Spanlens renders a waterfall span tree with critical-path highlighting.

Is my Anthropic API key stored securely?

Yes. The Anthropic key 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 Anthropic call in your dashboard within 60 seconds.