LangChain callback handler for NeBeso AI cost tracking
Project description
langchain-nebeso
LangChain callback handler for NeBeso — open source AI cost tracking.
Track every LLM call across your LangChain app: tokens, cost, latency, and custom tags — all visible in your NeBeso dashboard in real time.
Installation
pip install langchain-nebeso
Quick start
from langchain_nebeso import NeBesoCallbackHandler
from langchain_openai import ChatOpenAI
handler = NeBesoCallbackHandler(
api_key="nb_ak_...", # or set NEBESO_API_KEY env var
tags={"feature": "support-chat", "env": "production"},
)
llm = ChatOpenAI(model="gpt-4o", callbacks=[handler])
response = llm.invoke("Summarise our refund policy.")
# Cost is now visible in your NeBeso dashboard.
Supported providers
Works with any LangChain-supported model: OpenAI, Anthropic, Google Gemini, Mistral, Meta Llama, xAI Grok, Cohere, AWS Bedrock, and more.
Features
- Zero prompt access — only token counts, cost, and latency are recorded. Your prompts and completions are never sent to NeBeso.
- Automatic cost calculation — pricing table covers 60+ models across all major providers.
- Custom tags — tag by feature, user, environment, or anything else.
- Batched async delivery — events are queued and flushed in a background thread. Zero latency impact on your app.
- Works with chains and agents — attach the handler at the LLM level or pass it via
RunnableConfig.
Usage with chains
from langchain_nebeso import NeBesoCallbackHandler
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
handler = NeBesoCallbackHandler(api_key="nb_ak_...")
llm = ChatOpenAI(model="gpt-4o-mini", callbacks=[handler])
prompt = ChatPromptTemplate.from_template("Answer in one sentence: {question}")
chain = prompt | llm
chain.invoke({"question": "What is the capital of France?"})
Usage with agents
from langchain_nebeso import NeBesoCallbackHandler
from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain_core.prompts import ChatPromptTemplate
handler = NeBesoCallbackHandler(
api_key="nb_ak_...",
tags={"agent": "research", "user_id": "u_123"},
)
llm = ChatOpenAI(model="gpt-4o", callbacks=[handler])
# ... build your agent normally
Environment variables
| Variable | Description |
|---|---|
NEBESO_API_KEY |
Your NeBeso API key (alternative to passing api_key=) |
NEBESO_ENDPOINT |
Override API endpoint (default: https://api.nebeso.com) |
Get your API key
Sign up at nebeso.com → API Keys → Create Key.
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_nebeso-0.1.0-py3-none-any.whl.
File metadata
- Download URL: langchain_nebeso-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed8c274b24fb6c9add2b374e51dfbe6dc26d807e55a483c2a57a80f97bb6b210
|
|
| MD5 |
70221d5dddf50fa3847281f04d66bdd2
|
|
| BLAKE2b-256 |
3414bd985baaf417c58e743e00530919e370bfd972b918470d7f1749376f1582
|