Skip to main content

kazenai-finops

Stop your AI agents from burning your budget. Catch loops before they catch you.

PyPI Python 3.10+ License

Install: PyPI · kazenai-finops · Docs: docs.kazenai.com · Products: kazenai.com

Source: github.com/kazenai-ai/kazenai-finops-sdk


What is this?

kazenai-finops is the customer-facing Agent FinOps SDK. Install it, wrap your OpenAI or Anthropic client with monitor(), and get:

  1. Pre-call budget deny — hard BudgetExceeded before a provider call
  2. Soft trajectory pause — KazenCircuitBreaker when projected spend trips (alias: KazenBudgetExceeded)
  3. Loop detection — stop repeated high-risk patterns before another LLM call
  4. Optional FinOps / Lens evidence — canonical KazenEvent batches when ingest is configured

It depends on kazenai (the core engine) and kazen-event-schema. Most teams should install this package, not core directly.

Traditional tools:  LLM call → response → log cost → dashboard shows overspend
KazenAI:            Pre-flight check → BLOCKED → LLM call never made

Install

python -m pip install "kazenai-finops[openai]==1.1.1"
# Optional Anthropic path:
# python -m pip install "kazenai-finops[anthropic]==1.1.1"
# Both providers:
# python -m pip install "kazenai-finops[providers]==1.1.1"

Requires Python 3.10–3.12.

Provider extras pin the certified SDK ranges so a first-run install cannot silently resolve OpenAI 3.x or Anthropic 1.x. The Control 1.1.x certification covers those ranges. Later major versions are unverified until they are added to the supported matrix. Release 1.1.1 is a compatibility/distribution patch, not a new runtime capability line.


Quick start

from kazenai_finops import monitor, BudgetExceeded, KazenCircuitBreaker
import openai

client = openai.OpenAI()
monitored = monitor(
    client,
    agent_id="customer-support",
    # Optional ingest: set KAZENAI_FINOPS_API_KEY / KAZENAI_FINOPS_URL in the environment
    max_budget_usd=5.00,
    debug=True,
)

try:
    for i in range(100):
        monitored.chat.completions.create(
            model="gpt-4o-mini",
            messages=[{"role": "user", "content": f"Step {i}"}],
        )
except BudgetExceeded as e:
    print(f"Hard cap (before provider): {e}")
except KazenCircuitBreaker as e:
    print(f"Soft pause (after a completed call): {e}")

Call sites stay the same — monitor() wraps the client.


Supported today

Path Status
Sync OpenAI chat.completions.create (non-streaming and stream=True) / chat.completions.stream Supported via monitor()
Sync Anthropic messages.create / messages.stream Supported via monitor()
OpenAI Responses / async / Realtime Unsupported on the Control path
LangChain / LangGraph / CrewAI / AutoGen adapters Optional extras for evaluation — prefer wrapping the underlying client with monitor()

Optional framework extras

pip install 'kazenai-finops[langgraph]'   # similarly: langchain, crewai, etc. — see pyproject.toml
from kazenai_finops.adapters.langchain import wrap_langchain_runnable
from kazenai_finops.adapters.langgraph import wrap_graph_invoke
from kazenai_finops.adapters.crewai import wrap_crew_kickoff

These helpers are for evaluation. For the supported control path, wrap the OpenAI/Anthropic client with monitor().


Streaming (Control-certified)

Streaming uses the same pre-dispatch reservation. At provider dispatch the reservation becomes provider_started. Settlement happens when the stream ends with authoritative usage; early close(), a provider error, or missing final usage becomes outcome_unknown and leaves shared reconciliation pending rather than recording an exact zero or releasing an already-started call.

from kazenai_finops import monitor, StreamCutoffError
import openai

monitored = monitor(
    openai.OpenAI(),
    agent_id="streaming-agent",
    max_budget_usd=1.00,
    stream_cutoff_usd=0.50,  # optional local cutoff (does not use /v1/budget/stream-tick)
)

try:
    stream = monitored.chat.completions.create(
        model="gpt-4o-mini",
        messages=[{"role": "user", "content": "Long answer please"}],
        stream=True,
    )
    with stream:
        for chunk in stream:
            ...
except StreamCutoffError as e:
    print(f"Stream cut at ${e.blocked_usd:.6f}")

The official lazy OpenAI helper is supported too. Dispatch occurs when its context manager is entered, and the nested SDK call is accounted for exactly once:

with monitored.chat.completions.stream(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Long answer please"}],
) as stream:
    for event in stream:
        ...

stream_enforcement=True is deprecated; prefer stream_cutoff_usd. The cutoff uses output observable at the client. It cannot see hidden reasoning or guarantee that the provider stopped generating or billing immediately after the close.


Local and shared enforcement

  • Local hard cap works offline — no FinOps round-trip is required for the in-process client limit
  • Low overhead — checks stay on the hot path
  • Shared policies can fail closed — production/staging modes deny when a required shared reservation cannot be obtained

The local cap is not an account-wide provider billing limit. Multiple workers or services need the shared FinOps authority for a cross-process budget. An explicit development fail-open path retains only local safeguards.


How it relates to kazenai

Package Role
kazenai-finops Customer SDK (this package) — recommended install
kazenai Core monitor() engine
kazen-event-schema Shared event contract

from kazenai_finops import monitor re-exports the core engine so existing integrations keep working.

Maintainers: follow RELEASING.md. Core 1.1.1 must be available on public PyPI before this package's 1.1.1 CI, clean build and publication.


License

Apache License 2.0. See LICENSE and NOTICE.

Issues: https://github.com/kazenai-ai/kazenai-finops-sdk/issues · Products: kazenai.com · founder@kazenai.com

Metadata

Release files for kazenai-finops 1.1.1

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

Source distribution (sdist)

Source distribution for kazenai-finops 1.1.1
File Size Uploaded
kazenai_finops-1.1.1.tar.gz 23.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kazenai-finops 1.1.1
File Interpreter ABI Platform
kazenai_finops-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 44.3 kB

Release files / kazenai_finops-1.1.1.tar.gz

Download URL kazenai_finops-1.1.1.tar.gz
Size 23.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5282fb77317167c63d7bfe0479c4c02fa2f231f240cb9a5b20346a81dfaf7bbf
BLAKE2b-256 checksum
How to use checksums
0df9d8e0085cce9e8a6f4e79e31fc34aa8691dfb63bf38ebeb8390253984ad66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 4, 2026.

Transparency log

Release files / kazenai_finops-1.1.1-py3-none-any.whl

Download URL kazenai_finops-1.1.1-py3-none-any.whl
Size 20.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d46e305d6af3541d18cd8088fa321109b3bc7ccebdd2ea3d7e5fe80ab5262e0f
BLAKE2b-256 checksum
How to use checksums
495dabedb9a78453b52495c14e26b6cdfd6f511752dcf4aaddc64c5a1d4b234a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 4, 2026.

Transparency log

Release history Release notifications | RSS feed

1.1.3

2 release files

This release

1.1.1 This release

2 release files

1.1.0

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

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