Setup
Install with the LangChain extra (pip install "tokeven[langchain]"), set TOKEVEN_INGEST_TOKEN to your ingest token, then add the handler to your model:
from langchain_anthropic import ChatAnthropic
from tokeven.integrations.langchain import TokevenCallbackHandler
llm = ChatAnthropic(model="claude-haiku-4-5", callbacks=[TokevenCallbackHandler()])The handler works the same way with any LangChain chat model, including OpenAI and Gemini.
What it captures
One event per LLM call. Token counts come from the usage_metadata LangChain standardizes across providers. The handler never touches message text.
Budget guard
When a tokeven.guard budget is active, the handler checks it before each call and raises TokevenBudgetExceeded before the request is made.