BiVelio Savings Layer — Python client
BV-SALA cuts your LLM bill — and proves it on your provider's own meter. Live A/B: 0 % → 95 % hit-rate, −82.76 % per request · recomputed pooled reductions 31.50 % / 75.08 % with bootstrap intervals · paper v2.3-r1, DOI 10.5281/zenodo.24278852.
This package is the Python client of BV-SALA. The full product — the TypeScript SDK, the local gateway, every saving lever and the measured evidence — lives in the GitHub repository at
github.com/BiVelio/bivelio-savings-layer; its README is the canonical documentation (install, levers, paper, benchmarks, pricing). The same README is what npm shows for
@bivelio/savings-layer.
A thin client for the local bvsala gateway. It routes the official OpenAI
and Anthropic Python SDKs through the gateway and hands you, for each request,
the report the gateway recorded for your BiVelio dashboard: the provider's own
token counts, the cost at the model's list price, and where the figure comes
from (cost.basis).
- The gateway does the work. It ships in the npm package
@bivelio/savings-layer(Apache-2.0), forwards each request to your provider and measures it with the provider's usage counter. This package prices nothing itself, so its numbers are exactly the dashboard's. - Open core. The gateway starts with no keys at all (COMMUNITY mode: every
local lever on, zero telemetry). Without a running gateway,
wrap()raises; it never falls back to calling your provider directly. - No dependencies. Standard library only. It does not import the OpenAI or Anthropic SDKs; you bring them.
- Your prompts never reach BiVelio. The client only talks to the gateway on
127.0.0.1, ignoring any HTTP proxy settings, and the gateway forwards your requests to your provider. What a cloud key sends to BiVelio is per-request usage (token counts, cost, the model id and opaque ids), never your content: LICENSE-CLOUD.md, section 5, lists every field.
This package measures. The saving levers of the TypeScript SDK do not run in
Python; the gateway's own levers apply to Anthropic /v1/messages traffic, free
and with no key.
Requirements
- Python 3.10 or newer.
- Node.js 20.19 or newer, for the gateway. No keys required: the gateway starts
in COMMUNITY mode;
BIVELIO_SERVICE_KEY(optional) adds the cloud dashboard.
Install
pip install bivelio-savings-layer
The package is bivelio-savings-layer on PyPI and bvsala in your code
(import bvsala). From a checkout of the repository, to try unreleased changes:
pip install ./packages/python
Start a gateway
One gateway per provider:
export BIVELIO_SERVICE_KEY=…
npx -p @bivelio/savings-layer bvsala gateway # Anthropic, on 8402
npx -p @bivelio/savings-layer bvsala gateway --upstream openai --port 8403 # OpenAI, on 8403
python -m bvsala --url http://127.0.0.1:8403 status # version, upstream, license
Use it
import bvsala
from openai import OpenAI
gw = bvsala.Gateway("http://127.0.0.1:8403")
client = gw.wrap(OpenAI()) # a copy that goes through the gateway; OpenAI() is untouched
resp = client.chat.completions.create(
model="gpt-4o-mini", messages=[{"role": "user", "content": "Hi"}],
)
report = gw.report(resp)
print(report.summary()) # gpt-4o-mini · measured · $0.000024 (in 100, cached 40, out 20)
print(report.cost.actual, report.cost.basis, report.tokens.actual_output)
Streaming works the same way. For OpenAI Chat Completions, ask for usage in the request, or the provider sends no counter and the report says so:
stream = client.chat.completions.create(
model="gpt-4o-mini", messages=[{"role": "user", "content": "Hi"}],
stream=True, stream_options={"include_usage": True},
)
for chunk in stream:
if chunk.choices:
print(chunk.choices[0].delta.content or "", end="")
print(gw.report(stream).summary())
Anthropic:
from anthropic import Anthropic
gw = bvsala.Gateway() # $BVSALA_GATEWAY_URL or http://127.0.0.1:8402
claude = gw.wrap(Anthropic())
msg = claude.messages.create(model="claude-haiku-4-5", max_tokens=256,
messages=[{"role": "user", "content": "Hi"}])
print(gw.report(msg).summary())
gw.report() accepts a response, a stream you have read, any chunk or event of
it, a raw response from with_raw_response, or an id string. It also reads a
LiteLLM response sent with extra_headers=bvsala.REPORT_HEADERS, from the
provider headers LiteLLM keeps in _hidden_params (checked against LiteLLM's
source, not yet end to end).
gw.report() waits up to wait seconds (5 by default) for a request still in
flight; after that the report comes back with status == "pending". In async
code use await gw.areport(resp); wrap() also takes AsyncOpenAI,
AzureOpenAI and AsyncAnthropic.
gw.totals() adds up the reports this process fetched. Savings stay split by
basis (measured, reference, estimated), never added into one figure.
Any other client
The gateway side works with any HTTP client: send x-bvsala-report: 1, read
the x-bvsala-request-id response header, then
GET /_bvsala/v1/reports/<id> on the gateway. bvsala.REPORT_HEADERS is that
header as a dict, for extra_headers= or default_headers=.
Errors
| Exception | When |
|---|---|
GatewayUnavailable |
nothing answers at the URL, or it is not a bvsala gateway with local reports (0.4.26 or later is needed) |
LicenseInactive |
the gateway's license does not serve new requests; .state says why |
GatewayMismatch |
the client points at a different provider than the one the gateway forwards to |
ReportNotFound |
the gateway holds no report for that id (only requests sent with x-bvsala-report: 1 have one, kept for at most an hour) |
License
Apache-2.0, © 2026 BiVelio Inc. This client is open source; the gateway it talks to is open core (Apache-2.0, no keys required, COMMUNITY mode runs with zero telemetry). The optional BiVelio cloud is a separate commercial service: see LICENSE and savings.bivelio.com.
Metadata
Release files for bivelio-savings-layer 1.2.3
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 |
|---|---|---|---|---|
| bivelio_savings_layer-1.2.3.tar.gz | 38.6 kB | With provenance | Details for bivelio_savings_layer-1.2.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bivelio_savings_layer-1.2.3-py3-none-any.whl | Python 3 | none | any | Details for bivelio_savings_layer-1.2.3-py3-none-any.whl |
Total release size: 69.5 kB
Release files / bivelio_savings_layer-1.2.3.tar.gz
| Download URL | bivelio_savings_layer-1.2.3.tar.gz |
|---|---|
| Size | 38.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fdf9db78a3db9360b556a5d0fb83678a48d3d674a383101ea1ea40e626fa35ca
|
|
BLAKE2b-256 checksum How to use checksums |
0c359fd605145eca90372e070030bf7949cdbc8a9a492ac4cfd4f7fe4e12d0b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logRelease files / bivelio_savings_layer-1.2.3-py3-none-any.whl
| Download URL | bivelio_savings_layer-1.2.3-py3-none-any.whl |
|---|---|
| Size | 30.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a9b7207d482f13bc9cb0730d86710c8f4f84fea7ee1ef0c81da06811d101f6ed
|
|
BLAKE2b-256 checksum How to use checksums |
7dc0dcb6d01b36d3b97cc3f2beaa25dbe4f625986b710c4bf91741fd80a6e802
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logSecurity for bivelio-savings-layer 1.2.3
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for bivelio_savings_layer-1.2.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logA 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.