Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_nebeso-0.1.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file langchain_nebeso-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_nebeso-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ed8c274b24fb6c9add2b374e51dfbe6dc26d807e55a483c2a57a80f97bb6b210
MD5 70221d5dddf50fa3847281f04d66bdd2
BLAKE2b-256 3414bd985baaf417c58e743e00530919e370bfd972b918470d7f1749376f1582

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page