Are you TokenMaxxing hard enough? Find out in less than a minute →

LangChain & LangGraph

Instrument LangChain LLMs and tools, and LangGraph compiled graphs, with a one-line patch.

LangChain and LangGraph both instrument through a patch you call once at startup. The patch wraps the framework’s own abstractions, so every LLM call and tool invocation becomes a TokenJam span with no changes to your chain or graph code.

LangChain

from tokenjam.sdk.integrations.langchain import patch_langchain

patch_langchain()

This wraps BaseLLM and BaseTool. From then on, any LLM call or tool run inside a chain emits a span with token usage and timing.

LangGraph

from tokenjam.sdk.integrations.langgraph import patch_langgraph

patch_langgraph()

This wraps CompiledGraph, so each graph invocation is captured as a span tree.

How spans nest

Spans nest along the framework’s own call structure. A LangGraph node that runs a LangChain tool produces a parent-child tree, with the underlying LLM API call as a leaf. You see the graph, the tools it called, and the cost of each, in one trace.

Call the patch once, before you build or run anything. It is idempotent and framework-agnostic, so it composes with the provider patches (see Frameworks overview) if your chain reaches an API client tj already patches. Inner spans are de-duplicated, so nothing is double-counted.

Get TokenJam updates