Spanlens is a free, open source machine learning infrastructure project written in TypeScript and released under MIT. It has 13 GitHub stars, 0 forks and 1 open issues, and was last pushed 4 days ago. On this registry it ranks #56 of 57 tracked projects in Machine Learning Infrastructure, with 5 head-to-head comparisons available.

What is Spanlens?

Spanlens is an MIT-licensed, open-source LLM observability and monitoring layer that sits as a drop-in proxy in front of OpenAI, Anthropic, and Gemini clients to log every call's cost, tokens, latency, and agent traces, built for developers running LLM applications in production who need more than a provider dashboard's total spend.

What it is

Spanlens is a TypeScript project that turns on in one line: point an existing OpenAI, Anthropic, or Gemini client at Spanlens and every call is logged with cost, tokens, latency, and full agent traces. It requires no SDK rewrite and no platform migration. It supports eleven providers, ships native Vercel AI SDK, LangChain, and LlamaIndex integrations, and exposes a bundled MCP server so the data can be queried from Cursor or Claude Desktop. It is MIT-licensed, self-hostable in one Docker command, and also offered as a hosted service at spanlens.io. The repository topics place it in the LLM observability and LLMOps space, with ClickHouse and Next.js in the stack.

The concrete problem is spend visibility. Provider dashboards show total spend and little else, so it is not possible to tell which feature burned the most tokens, which model was cheapest per task, or what each endpoint actually cost. Spanlens replaces that total-spend view with a per-request log that can be filtered and drilled into for the full prompt, response, cost, latency, and token counts. It also positions itself as a lighter substitute for Helicone, whose roadmap is uncertain after acquisition, and for Langfuse Pro, which the README describes as powerful but complex to set up and expensive to scale.

Key capabilities

  • Drop-in proxy for OpenAI, Anthropic, and Gemini clients that logs requests without an SDK rewrite or platform migration.
  • Eleven supported providers, plus native Vercel AI SDK, LangChain, and LlamaIndex integrations.
  • Per-call request logging with cost, tokens, and latency, drillable into full prompt and response.
  • Agent tracing, with a dashboard covering anomaly alerts and spend forecasting.
  • Bundled MCP server, published as @spanlens/mcp-server, for querying from Cursor or Claude Desktop.
  • PII scanning and prompt injection scanning, prompt versioning, prompt A/B experiments, and LLM-as-judge evaluations.
  • Model recommendations and CLI tooling through @spanlens/cli.

Who uses it and how

  • Teams shipping LLM applications on OpenAI and Gemini that need to attribute token burn to individual features and endpoints rather than a single monthly total.
  • Agent builders who need full traces across multi-step calls rather than aggregate counters.
  • Development teams that want the free tier's hard 429 at 50K requests per month as a guard against a runaway loop in dev costing money.
  • Growing products at the 1M request per month mark, where the Team plan covers 10 seats and unlimited projects.
  • Self-hosters who want to run the exact code the hosted service runs, and engineers already working inside the Vercel AI SDK, LangChain, or LlamaIndex ecosystems.

Getting started

Install the SDK from npm as @spanlens/sdk or from PyPI as spanlens, or point an existing OpenAI, Anthropic, or Gemini client at a Spanlens endpoint. Self-hosting is one Docker command, and a hosted option is available at spanlens.io with a no-signup demo.

How it compares

Helicone, Langfuse Pro, and Spanlens are all MIT-licensed and all self-hostable, so the difference is cost model and feature coverage rather than licence or data ownership. At 1M requests per month the Team plan is listed at $149/mo against $271/mo for Langfuse Pro and roughly $200/mo for Helicone, and the free tiers differ at 50K requests per month, 50K events per month, and 10K requests per month respectively. Spanlens claims PII and injection scanning and model recommendations that neither comparison product lists, and prompt A/B experiments and LLM-as-judge evals that Helicone does not list, while Helicone's agent tracing is marked limited.

When to use it — and when not to

A self-hoster takes on operating the Docker deployment and the ClickHouse datastore and Next.js application the stack depends on, and the free tier stops hard at 50K requests per month rather than degrading. The project is young, with 13 stars, 0 forks, and 1 open issue, so teams that need a large community, long release history, or extensive third-party documentation should weigh that before standardising on it. Teams that only need a managed, established platform and have no self-hosting requirement may find the hosted tier the only sensible path here.

project readme (upstream, from github) — read inline

Spanlens

GitHub stars License: MIT npm version PyPI version npm downloads

Open-source LLM observability you can turn on in one line. Point your OpenAI, Anthropic, or Gemini client at Spanlens and every call is logged with cost, tokens, latency, and full agent traces. No SDK rewrite, no platform migration. Eleven providers supported, plus native Vercel AI SDK, LangChain, and LlamaIndex integrations, and you can query it all from Cursor or Claude Desktop through the bundled MCP server. Self-hostable in one Docker command. MIT.

Why it exists. I shipped an LLM app on OpenAI and Gemini and hit a wall. The provider dashboards showed total spend and nothing else. I could not tell which feature burned the most tokens, which model was cheapest per task, or what each endpoint actually cost. Spanlens is the layer I wanted. It turns on in one line, stays off the critical path, and is open source so you can self-host the exact code we run.

If Spanlens is useful to you, please star the repo. It takes a second, and it is the single biggest thing that helps other developers find the project.

Hosted: spanlens.io · npm: @spanlens/sdk · PyPI: spanlens · CLI: @spanlens/cli · MCP: @spanlens/mcp-server · Status: status.spanlens.io · Changelog: spanlens.io/changelog


Spanlens request log: filter every LLM call, then drill into the full prompt, response, cost, latency, and tokens

Live demo (no signup): spanlens.io/demo/requests

One key swap. Every LLM call, observed.

Spanlens dashboard showing anomaly alerts, spend forecast and traffic chart


Why Spanlens?

  • Helicone was acquired and its roadmap is uncertain.
  • Langfuse is powerful but complex to set up and expensive to scale.
  • Spanlens ships the 20% of features that cover 80% of real production needs. You get request log, cost tracking, agent tracing, anomaly detection, PII scanning, and prompt versioning with a clean UI, a two-minute setup, and pricing that doesn't punish growth.
Spanlens Langfuse Pro Helicone
Open source ✅ MIT ✅ MIT ✅ MIT
Self-hostable ✅ Docker one-liner
Free tier 50K req/mo 50K events/mo 10K req/mo
Team plan (1M req/mo) $149/mo $271/mo ~$200/mo
Agent tracing ⚠️ limited
LLM-as-judge evals
PII + injection scan
Model recommendations
Prompt A/B experiments

Spanlens Team $149/mo vs Langfuse Pro $271/mo at 1M requests per month

Predictable bills, no quota cliff. Free hits a hard 429 at 50K requests so a runaway loop in dev can't cost you money. Paid plans use a soft limit with authorized overage (Pro: +$8 / 100K, Team: +$5 / 100K) up to a hard cap you control, so a traffic spike charges you fairly instead of dropping requests.

Seats: Free 1 · Pro 3 · Team 10 · Enterprise unlimited. Unlimited projects on every paid tier.

⭐ Like where this is going? A star helps more developers find a lightweight, open alternative in a space full of heavy, acquired tools.


⚡ Quick start in 30 seconds

TypeScript / JavaScript (Next.js)

npx @spanlens/cli init

The wizard:

  1. Installs @spanlens/sdk with your package manager (npm / pnpm / yarn / bun)
  2. Writes SPANLENS_API_KEY to .env.local
  3. Rewrites every new OpenAI({ apiKey, baseURL }) into createOpenAI()

Paste your Spanlens API key once, confirm two prompts, done. Your LLM calls are now flowing through the Spanlens proxy and visible in www.spanlens.io/requests.

Manual TypeScript setup
import { createOpenAI } from '@spanlens/sdk/openai'
const openai = createOpenAI()  // reads SPANLENS_API_KEY, uses Spanlens proxy baseURL

Python

pip install "spanlens[openai]"
from spanlens.integrations.openai import create_openai

client = create_openai()  # reads SPANLENS_API_KEY from env
res = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Hello"}],
)

For agent tracing in Python (multi-step, async, tool calls) see the Python SDK README.

Framework integrations

Already using an orchestration framework? Plug Spanlens in as a callback. No code rewrites.

Vercel AI SDK (Next.js / edge friendly)

import { SpanlensClient } from '@spanlens/sdk'
import { createSpanlensTracker } from '@spanlens/sdk/vercel-ai'

const tracker = createSpanlensTracker({
  client: new SpanlensClient({ apiKey: process.env.SPANLENS_API_KEY! }),
  modelName: 'gpt-4o',
})

await generateText({
  model: openai('gpt-4o'),
  messages,
  onStepFinish: tracker.onStepFinish,
  onFinish: tracker.onFinish,
})

LangChain JS / LangGraph

import { createSpanlensCallbackHandler } from '@spanlens/sdk/langchain'

const handler = createSpanlensCallbackHandler({ client })
await chain.invoke({ input }, { callbacks: [handler] })   // LangChain
await graph.invoke({ input }, { callbacks: [handler] })   // LangGraph

LlamaIndex TS

import { Settings } from 'llamaindex'
import { registerSpanlensCallbacks } from '@spanlens/sdk/llamaindex'

const unregister = registerSpanlensCallbacks(Settings, { client })
// ... run queries ... unregister() on shutdown

Python: LangChain: from spanlens.integrations.langchain import SpanlensCallbackHandler. Same BaseCallbackHandler contract, works with chains, LCEL, and LangGraph.

More integrations: AWS Bedrock, CrewAI, Flowise, Instructor, LlamaIndex, OpenAI Assistants, MCP server. Full setup walkthroughs at spanlens.io/docs/integrations.

Ollama (local LLMs): Ollama runs on your machine, so it does not go through the hosted proxy. Get a ready client with createOllama() and wrap each call with observeOllama() so the span is logged and tagged as Ollama.

import { SpanlensClient } from '@spanlens/sdk'
import { createOllama, observeOllama } from '@spanlens/sdk/ollama'

const spanlens = new SpanlensClient({ apiKey: process.env.SPANLENS_API_KEY! })
const ollama = createOllama() // points at http://localhost:11434/v1

const trace = spanlens.startTrace({ name: 'chat' })
const res = await observeOllama(trace, 'chat', (headers) =>
  ollama.chat.completions.create(
    { model: 'llama3.1', messages: [{ role: 'user', content: 'Hello' }] },
    { headers },
  ),
)
await trace.end({ status: 'completed' })

What you see

Spanlens request log showing every LLM call with latency, cost, tokens and status

Every request logged with model, provider, latency, tokens, cost, and full prompt + response body. Filter, search, export. Streaming responses reconstructed automatically.


What you get

Feature Description
Request log Every LLM call logged with model, tokens, cost, latency, and full request/response body (streaming reconstructed too)
Agent tracing Multi-step workflows as Gantt waterfall span trees with Critical Path highlighted (the longest dependency chain across a fan-out, not just the slowest single span), plus a node-and-edge graph topology view for LangChain / LangGraph callback traces
Cost tracking Per-request cost breakdown with daily rollups and budget alerts. Prompt-cache tokens (cache_read / cache_creation on Anthropic, prompt_tokens_details.cached_tokens on OpenAI) are parsed separately and billed at the discounted rate so you can see actual cache savings, not just sticker price
Per-end-user analytics Tag calls with x-spanlens-user (SDK: withUser() / with_user()) and the /users page shows per-user cost, tokens, errors, models, last seen
Anomaly detection 3σ deviations in latency, cost, or error rate vs. your 7-day bas

readme truncated — read the full docs on github

Frequently asked questions

Is Spanlens free to use?

Spanlens is open source under the MIT licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does Spanlens do?

LLM observability: cost, latency, and traces in one place

What is Spanlens written in?

Spanlens is primarily written in TypeScript. Its source is publicly available at https://github.com/spanlens/Spanlens, and it has 13 GitHub stars.