Aurex Python SDK (aurex-sdk)
Open-source, in-process LLM FinOps shield, runtime circuit breaker, and CI regression gate for Python (<0.1 ms overhead, zero proxy hops, zero-PII local ledger).
1. What Problems Are People Facing?
- Silent cache & cliff traps: Dynamic timestamps or unsorted JSON tool schemas in
system/developerprompts break 50%–90% prompt-cache discounts, and crossing200,000input tokens doubles whole-request pricing on Claude 4+ and Gemini 2.5+. - Unbounded runtime spend: Looping tool calls, hidden reasoning tokens (
o3/o4-mini, Claude Extended Thinking, Geminithoughts_token_count), aborted SSE streams, and multiplied SDK retries drain budgets mid-flight. - Billed HTTP-200 soft failures: Thinking-exhausted empty outputs and
\n\n\nJSON grammar loops return HTTP200 OKand bill full output rates while producing nothing usable.
2. What Does Aurex Solve?
aurex-sdk instruments openai (.create, .parse, .stream, responses.create, plus Groq/Together/Fireworks/OpenRouter/Ollama base_url clients), anthropic (messages.create, .parse, .stream, 1h/5m prompt caching, ThinkingBlock), google-genai (sync & .aio async), litellm, ollama, and huggingface_hub across three stages:
- Before the call (Stage 1): Deterministically sorts tool/schema JSON keys, pinpoints prefix-cache mutations by character offset, flags
>5mAnthropic idle TTL gaps, and warns before the200k2x cliff. - During the call (Stage 2): Isolates workflows via
workflow_id/contextvars/ OpenTelemetrytrace_id, shares spend across workers via optional Redis, clamps thinking budgets, injects stream usage & bills aborted streams, disables duplicate SDK retries, and raisesAurexBlocked. - After the call + CI (Stage 3): Tags HTTP-200 soft failures as
unfulfilled_spend, pairs spend withmark_success()to measure truecost_per_success, and diffs PR ledgers in CI.
3. How to Use It in Any Python Codebase (Step-by-Step)
Step 1: Install
pip install aurex-sdk
# Optional Redis multi-worker state + OpenTelemetry trace correlation:
pip install "aurex-sdk[redis,otel]"
Step 2: Initialize Once at Startup (FastAPI, Django, Celery, LangGraph, Scripts)
from aurex_sdk import AurexAuditor, AurexBlocked, AurexConfig, patch_all
import openai
auditor = AurexAuditor(
AurexConfig(
redis_url="redis://localhost:6379/0", # Optional: omit for in-memory single-process mode
enable_loop_guard=True,
budget_guard={
"max_cost_per_session": 1.50,
"max_thinking_tokens": 4096,
"on_budget_exceeded": "throw",
},
)
)
patch_all(auditor)
client = openai.OpenAI()
try:
# Works identically for sync, AsyncOpenAI, .parse(response_format=Model), .stream(), and client.responses.create()
resp = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "developer", "content": "You are a concise support engineer."},
{"role": "user", "content": "Draft release notes for v0.5.0."},
],
workflow_id="release-job-1", # Stripped cleanly before hitting provider HTTP wire
tags={"tenant_id": "acme"},
)
auditor.mark_success("release-job-1")
except AurexBlocked as err:
print(f"Blocked runaway workflow {err.workflow_id}: {err.reason}")
finally:
auditor.flush() # Call on app shutdown or AWS Lambda / Cloud Run request exit
Step 3: Run Local Audit & CI PR Gate
aurex audit
aurex ci --ledger .aurex/ledger.jsonl --baseline main_ledger.jsonl --github-comment --fail-on-regression
(Zero-code startup hook: run aurex install-hook once in your virtualenv/image, then run with AUREX_ENABLED=1.)
4. How Can You Improve Your Setup?
- Move dynamic values to the tail: Keep
messages[0]/systemstatic and append timestamps or request IDs at the end of the user turn. - Guard the
200kcliff: Set"max_context_tokens": 195000inbudget_guardon Claude 4+ and Gemini 2.5+ workflows. - Enable Redis across workers: Set
AUREX_REDIS_URL=redis://localhost:6379/0so Gunicorn/Uvicorn workers share live session spend. - Fail CI on upstream SDK drift: Set
AUREX_STRICT_DRIFT=1in CI to raiseAurexProviderDriftErrorif a futureopenai/anthropic/google-genaimajor bump renames internal classes (production always fails open and logsauditor.get_health()["drift_warnings"]).
Quick Reference for AI Coding Agents
- Singleton lifecycle: Initialize
AurexAuditor(AurexConfig(...))+patch_all(auditor)once at process startup (e.g., FastAPIlifespan). CallAurexAuditor.reset()between unit tests. - Auto-stripped call kwargs:
workflow_id,tags,tenant_id, andquality_scorecan be passed directly to any patched provider.create(),.parse(), or.stream()call—Aurex removes them before HTTP serialization. - Read-only containers / Lambda: Use
storage_mode="memory"(or let Aurex auto-fallback when the filesystem is read-only) and callauditor.flush()(orauditor.flush_async()) before exit. - Typed exceptions: Catch
AurexBlocked/AurexBudgetExceeded(fromaurex_sdk). Real provider exceptions (openai.APIError,anthropic.APIError) pass through unchanged.
Metadata
Release files for aurex-sdk 0.5.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 |
|---|---|---|---|---|
| aurex_sdk-0.5.0.tar.gz | 87.3 kB | Without provenance | Details for aurex_sdk-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aurex_sdk-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for aurex_sdk-0.5.0-py3-none-any.whl |
Total release size: 162.1 kB
Release files / aurex_sdk-0.5.0.tar.gz
| Download URL | aurex_sdk-0.5.0.tar.gz |
|---|---|
| Size | 87.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
84175a07989723d51656d90ae87bb606b69e0489f75a3af4cf4f348971baaf69
|
|
BLAKE2b-256 checksum How to use checksums |
3c3e178893f5f07efc717dcf8183cf925df908dc3bb65f21508b1b5e46013548
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|
Release files / aurex_sdk-0.5.0-py3-none-any.whl
| Download URL | aurex_sdk-0.5.0-py3-none-any.whl |
|---|---|
| Size | 74.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
824d73ccb89a6fe06057ab97d0f55d2470ae4a12af02af1997479f819ce8c3a4
|
|
BLAKE2b-256 checksum How to use checksums |
2250f5372566e768d47caed1758bad35f7160facedfa30912dd22d3d52987a87
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|
Security for aurex-sdk 0.5.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.