LangChain
LangChain and LangGraph need one install step — a Python extra, or the Node companion package plus two static imports.
LangChain and LangGraph work with TokenPolice after one install step. Init as usual — see init parameters — there is nothing LangChain-specific to call. The provider calls underneath (OpenAI, Anthropic, Gemini, …) are metered through LangChain, and tool calls get their own steps in the trace automatically.
Python
Install the langchain extra:
pip install "token-police[langchain]"Then tp.init(...) before you import the module that imports LangChain:
import token_police as tp
tp.init(api_key=..., base_url=..., firewall="enforce")
import agent # imports LangChain — must come after initNode
Add the companion package alongside the SDK. There is no API to call and nothing to import from it — the base SDK detects it at startup and enables LangChain instrumentation:
npm i token-police token-police-langchainOn native ESM you also need two static imports before init(), so the SDK can patch the ESM
copies of @langchain/core that LangGraph actually calls:
import * as tp from "token-police";
import * as lcChatModels from "@langchain/core/language_models/chat_models";
import * as lcCallbacks from "@langchain/core/callbacks/manager";
tp.init({
/* … see init parameters … */
instrumentModules: {
langChain: { chatModelsModule: lcChatModels, callbackManagerModule: lcCallbacks },
},
});
// Static ESM imports all run before this file's code, so keep every other
// @langchain/* import out of the entry module and load it after init instead.
const { runTurn } = await import("./agent.js");The companion is a separate package so apps that don't use LangChain don't pay for its dependency tree. Install it only if you use LangChain — and never import from it directly.
Reroute does not switch the model on LangChain
A Reroute rule does not switch the model on LangChain or LangGraph — those calls still run on the original model. Metering and blocking work normally. See Actions.
Supported: @langchain/core 0.3.x and 1.x (tested with langchain 0.3 and @langchain/langgraph 1.x).
On @langchain/core 0.3, pnpm reports an unmet peer from the companion's bundled instrumentor
(it wants >=1.0.0); this is expected and safe — the SDK wires LangChain's callback manager itself.
On native ESM, import order still matters for the provider clients LangChain calls under the hood. See Node & ESM.
Next
Supported providers & frameworks
The canonical list: every provider and framework TokenPolice meters, what it costs to install, and the caveats worth knowing.
Vercel AI SDK
The Vercel AI SDK is metered out of the box in Node; community providers and bundled runtimes need one wrapper, and tool calls are always manual.

