langchain-neuralwatt
LangChain integration for Neuralwatt — energy-aware AI inference. Drop-in replacement for ChatOpenAI that surfaces per-call energy and carbon metrics into LangChain's response_metadata.
Install
pip install langchain-neuralwatt
Quick start
from langchain_neuralwatt import ChatNeuralwatt
llm = ChatNeuralwatt(model="glm-5-fast") # reads NEURALWATT_API_KEY from env
msg = llm.invoke("Summarize the second law of thermodynamics in one sentence.")
print(msg.content)
print(msg.response_metadata["energy"])
# {'energy_joules': 1234.56, 'energy_kwh': 3.43e-07, 'carbon_g_co2eq': 0.00012, ...}
Note: Energy metadata is only present on non-streaming (
invoke) responses.llm.stream()and agent loops that stream internally will not have anenergykey inresponse_metadata.
Tracking energy across a chain
from langchain_neuralwatt import ChatNeuralwatt, NeuralwattEnergyCallback
cb = NeuralwattEnergyCallback()
llm = ChatNeuralwatt(model="glm-5-fast")
llm.invoke("...", config={"callbacks": [cb]})
llm.invoke("...", config={"callbacks": [cb]})
print(cb.summary())
# {'calls': 2, 'energy_joules': 2450.0, 'energy_kwh': 6.8e-07, 'carbon_g_co2eq': 0.00024}
Configuration
| Param | Env var | Default |
|---|---|---|
model |
— | glm-5-fast |
api_key |
NEURALWATT_API_KEY (falls back to OPENAI_API_KEY) |
— |
base_url |
NEURALWATT_API_BASE |
https://api.neuralwatt.com/v1 |
All other ChatOpenAI params (temperature, max_tokens, tools, model_kwargs, …) work as expected — ChatNeuralwatt is a thin subclass of BaseChatOpenAI.
What lands in response_metadata
Neuralwatt attaches two top-level fields to non-streaming chat completion responses:
energy—energy_joules,energy_kwh,avg_power_watts,duration_seconds,attribution_method, optionalcarbon_g_co2eq+ grid metadata.cost—request_cost_usd,cache_savings_usd,allowance_remaining_usd.
Development
pip install -e ".[test,lint,typing]"
pytest tests/unit_tests # offline
NEURALWATT_API_KEY=nw_... pytest tests/integration_tests # live
This package implements the LangChain standard test suite via langchain-tests.
License
MIT
Metadata
Release files for langchain-neuralwatt 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| langchain_neuralwatt-0.1.0.tar.gz | 8.4 kB | Without provenance | Details for langchain_neuralwatt-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| langchain_neuralwatt-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for langchain_neuralwatt-0.1.0-py3-none-any.whl |
Total release size: 14.9 kB
Release files / langchain_neuralwatt-0.1.0.tar.gz
| Download URL | langchain_neuralwatt-0.1.0.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a4a635cf69f830c462a21df9a9190e0218d2f2ada66071770635b9494e1ffc5d
|
|
BLAKE2b-256 checksum How to use checksums |
db11ff88a2662ec0e21842fb8143f12ca0997e34cfd007ac5c9e8755e79810c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / langchain_neuralwatt-0.1.0-py3-none-any.whl
| Download URL | langchain_neuralwatt-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3cc23f3206c387eb9a7c90b418e3d988c2055e83d635f0fe350831424ee1d53e
|
|
BLAKE2b-256 checksum How to use checksums |
7c7a0275c2279768f2acc76b52e373fd80049ebe2d12d085978f25a9b114b63b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for langchain-neuralwatt 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.