Metadata-Version: 2.4
Name: langchain-nebeso
Version: 0.1.0
Summary: LangChain callback handler for NeBeso AI cost tracking
Project-URL: Homepage, https://nebeso.com
Project-URL: Documentation, https://nebeso.com/docs/langchain
Project-URL: Repository, https://github.com/badBoyDevop/nebeso-platform
Project-URL: Bug Tracker, https://github.com/badBoyDevop/nebeso-platform/issues
Author-email: NeBeso <hello@nebeso.com>
License: Apache-2.0
Keywords: ai,anthropic,callbacks,cost,langchain,llm,observability,openai,tokens,tracking
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.9
Requires-Dist: langchain-core>=0.2
Requires-Dist: nebeso>=0.1.0
Description-Content-Type: text/markdown

# langchain-nebeso

LangChain callback handler for [NeBeso](https://nebeso.com) — 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

```bash
pip install langchain-nebeso
```

## Quick start

```python
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

```python
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

```python
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](https://nebeso.com) → API Keys → Create Key.

## Links

- [Full docs](https://nebeso.com/docs/langchain)
- [NeBeso dashboard](https://nebeso.com)
- [GitHub](https://github.com/badBoyDevop/nebeso-platform)
- [PyPI: nebeso](https://pypi.org/project/nebeso/)
