Skip to main content

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

Metadata

Release files for langchain-nebeso 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for langchain-nebeso 0.1.0
File Interpreter ABI Platform
langchain_nebeso-0.1.0-py3-none-any.whl Python 3 none any Details

Release files / langchain_nebeso-0.1.0-py3-none-any.whl

Download URL langchain_nebeso-0.1.0-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ed8c274b24fb6c9add2b374e51dfbe6dc26d807e55a483c2a57a80f97bb6b210
BLAKE2b-256 checksum
How to use checksums
3414bd985baaf417c58e743e00530919e370bfd972b918470d7f1749376f1582
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page