kazenai
Stop your AI agents from burning your budget. Catch loops before they catch you.
Install: PyPI · kazenai · Customer SDK: kazenai-finops · Products: kazenai.com
What is this?
kazenai is the core Python SDK behind KazenAI’s economic control layer for AI agents. One call — monitor() — wraps your OpenAI or Anthropic client and:
- Blocks overspend before the provider call (
BudgetExceeded) - Detects runaway loops before another LLM request
- Optionally ships evidence to Agent FinOps / Agent Lens as canonical
KazenEvents
Most observability tools tell you what went wrong after the bill. KazenAI can stop the call that would cause it.
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 openai
# Most teams install the customer package instead:
python -m pip install kazenai-finops openai
kazenai-finops re-exports this SDK and is the recommended install for product integrations.
Requires Python 3.10+.
Quick start
import os
from openai import OpenAI
from kazenai import monitor, BudgetExceeded
# Optional FinOps ingest (env only — not monitor kwargs):
# export KAZENAI_FINOPS_API_KEY=kz_...
# export KAZENAI_FINOPS_INGEST_URL=https://finops.example.com
client = monitor(
OpenAI(),
agent_id="support-agent",
max_budget_usd=5.00,
debug=True,
)
try:
client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "hello"}],
)
except BudgetExceeded as e:
print("hard budget cap:", e)
Your call sites stay the same — monitor() wraps the client.
With debug=True you’ll see spend as the run progresses:
[KazenAI] step=1 gpt-4o-mini cost=$0.0043 total=$0.0043 proj=$0.21/$5.00 OK
[KazenAI] step=8 gpt-4o-mini cost=$0.0039 total=$0.43 proj=$4.91/$5.00 WARN:budget_87pct
[KazenAI] step=9 gpt-4o-mini BLOCKED:budget spent=$5.00 limit=$5.00
Illustrative debug output — not a customer bill or savings claim.
What you get
| Capability | Behavior |
|---|---|
| Hard budget cap | BudgetExceeded before the provider call |
| Soft trajectory pause | KazenCircuitBreaker after a completed call when projection trips |
| Loop detection | Blocks high-risk repeat patterns before another provider call |
| Event ingest | Optional HttpSink batches to Agent FinOps when URL + API key are set |
| Shared schema | Canonical KazenEvent via kazen-event-schema |
Supported today
| Path | Status |
|---|---|
Sync OpenAI chat.completions.create (non-streaming) |
Supported via monitor() |
Sync Anthropic messages.create (non-streaming) |
Supported via monitor() |
| Streaming / Responses API / async clients | Not on the supported control path |
| LangChain / CrewAI / LangGraph / AutoGen helpers | Available for evaluation — wrap the underlying client with monitor() for the supported path |
Why local enforcement matters
- Hard cap works without FinOps network — deny even when ingest is offline
- Low overhead — budget and loop checks stay on the hot path
- Backend outage ≠ unprotected spend on the local hard-cap path
Optional FinOps environment variables
| Variable | Purpose |
|---|---|
KAZENAI_FINOPS_INGEST_URL / KAZENAI_FINOPS_URL |
Base URL for event ingest |
KAZENAI_FINOPS_API_KEY |
API key for POST /v1/events |
KAZENAI_BUDGET_USD |
Soft per-run budget for the circuit breaker |
KAZENAI_ORG_ID / KAZENAI_PROJECT_ID |
Tenant labels on events |
Packages in the stack
| Package | Role |
|---|---|
kazenai |
Core monitor() engine (this repo) |
kazenai-finops |
Customer-facing SDK (recommended install) |
kazen-event-schema |
Shared event contract across FinOps / Lens / SDKs |
Contributing
Issues and PRs that improve budget/loop reliability are welcome. Keep claims aligned with the supported paths above.
Products and design-partner enquiries: kazenai.com · founder@kazenai.com
License
Apache License 2.0. See LICENSE and NOTICE.
Metadata
Release files for kazenai 1.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| kazenai-1.0.5.tar.gz | 114.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| kazenai-1.0.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 200.9 kB
Release files / kazenai-1.0.5.tar.gz
| Download URL | kazenai-1.0.5.tar.gz |
|---|---|
| Size | 114.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e6e6990b34d1da85f70730d023401224af53432853d2b081837609651f8f610e
|
|
BLAKE2b-256 checksum How to use checksums |
dfdc9cebf8f1a4508e2268ed0eda93419d7092edf3e79c384a5f6779341f65b5
|
| 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 1, 2026.
Transparency logRelease files / kazenai-1.0.5-py3-none-any.whl
| Download URL | kazenai-1.0.5-py3-none-any.whl |
|---|---|
| Size | 86.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dc757959358f6866b8f0d0865dcf6a4d8a5ef2d71ffbfa7088ee8bdc87a2c788
|
|
BLAKE2b-256 checksum How to use checksums |
7586e518951195076402be6c9c68fc624a1143b48dae9c80992550b3d9595c8d
|
| 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 1, 2026.
Transparency log