Skip to main content

BiVelio Savings Layer for Python

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 with a PRO license.

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

Commercial software, © 2026 BiVelio Inc. Free to install, paid to run: see LICENSE and savings.bivelio.com.

Metadata

Release files for bivelio-savings-layer 1.0.0

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

Source distribution (sdist)

Source distribution for bivelio-savings-layer 1.0.0
File Size Uploaded Provenance Actions
bivelio_savings_layer-1.0.0.tar.gz 37.7 kB With provenance Details for bivelio_savings_layer-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bivelio-savings-layer 1.0.0
File Interpreter ABI Platform Actions
bivelio_savings_layer-1.0.0-py3-none-any.whl Python 3 none any Details for bivelio_savings_layer-1.0.0-py3-none-any.whl

Total release size: 68.1 kB

Release files / bivelio_savings_layer-1.0.0.tar.gz

Download URL bivelio_savings_layer-1.0.0.tar.gz
Size 37.7 kB
Tags Source
SHA-256 checksum
How to use checksums
9c77aede6d0d7bdd10eefc6ad7900615ba759ddd90fc862a9d6939e1be349ed3
BLAKE2b-256 checksum
How to use checksums
35451c2aa2b7c9ed62cf17fb939d91d10ba0c947c857eaaf3cc946153dcdab15
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 3, 2026.

Transparency log

Release files / bivelio_savings_layer-1.0.0-py3-none-any.whl

Download URL bivelio_savings_layer-1.0.0-py3-none-any.whl
Size 30.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f3cf3365419e0405c56d99b9ee8f54c2226cba378154fd67f869b88bb62eca1c
BLAKE2b-256 checksum
How to use checksums
d91f1cea135b9da2674f24e12ed2da0dfab8e745cad9f19e708b4ef8a113d6cf
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 3, 2026.

Transparency log

Security for bivelio-savings-layer 1.0.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for bivelio_savings_layer-1.0.0.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 3, 2026.

Transparency log

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.

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