Skip to main content

Aurex SDK Logo

Aurex Python SDK (aurex-sdk)

aurex-sdk is an open-source, in-process LLM cost shield, runtime circuit breaker, and CI regression gate for Python. It runs in memory (<0.1 ms overhead) with zero proxy latency and zero raw prompts leaving your servers.

What Problems Does It Solve?

  • Silent cache & 200k price traps: Putting a changing timestamp or unsorted JSON schema in a system prompt wipes out 50%–90% prompt-cache discounts, and crossing 200,000 input tokens doubles whole-request pricing on Claude and Gemini (anthropics/claude-code#91151).
  • Runaway agent loops & hidden thinking tokens: Reasoning models burn thousands of internal thought tokens billed at output rates (googleapis/python-genai#782), while stuck tool loops drain budgets without a per-session fuse.
  • Paid HTTP 200 soft failures: Models return 200 OK with empty or whitespace-looped replies (openai/codex#60294) that bill full price without completing the user's task.

How It Protects Every Call (3 Stages)

  1. Before the call: Sorts JSON keys deterministically, pinpoints the exact character index breaking your cache, flags >5 min idle cache-expiry gaps, and warns before crossing the 200k 2x cliff.
  2. During the call: Enforces per-session and per-minute USD caps (shared across workers via optional Redis), clamps max_thinking_tokens, tracks aborted streams, suppresses 6x retry storms, and raises AurexBlocked on loops.
  3. After the call + CI: Flags empty or looped HTTP 200 outputs as wasted spend, pairs spend with mark_success() to measure true cost per completed task, and diffs Pull Requests in CI.

Quickstart (60 Seconds)

Step 1: Install

pip install aurex-sdk
# Optional multi-worker Redis & OpenTelemetry extras:
pip install "aurex-sdk[redis,otel]"

Step 2: Initialize Once at App Startup

from aurex_sdk import AurexAuditor, AurexBlocked, AurexConfig, patch_all
import openai

auditor = AurexAuditor(
    AurexConfig(
        budget_guard={
            "max_cost_per_session": 1.50,
            "max_thinking_tokens": 4096,
            "on_budget_exceeded": "throw",
        },
        enable_loop_guard=True,
    )
)
patch_all(auditor)

client = openai.OpenAI()
try:
    resp = client.chat.completions.create(
        model="gpt-4o",
        messages=[{"role": "user", "content": "Draft release notes."}],
        workflow_id="release-job-1",
    )
    auditor.mark_success("release-job-1")
except AurexBlocked as err:
    print(f"Stopped runaway session {err.workflow_id}: {err.reason}")
finally:
    auditor.flush()

Step 3: Audit Locally & Gate Pull Requests in CI

aurex audit
aurex ci --ledger .aurex/ledger.jsonl --baseline main_ledger.jsonl --github-comment --fail-on-regression

(Zero-code option: run aurex install-hook once, then start your app with AUREX_ENABLED=1.)

Tested on Real Open-Source Agent Benchmarks (8.4 – 8.9 / 10)

Verified across terminal-bench (8.9/10, 0.08 ms p50), tau-bench (8.8/10), OpenHands (8.7/10), SWE-agent (8.6/10), BrowserGym (8.4/10), and LangGraph across Claude, GPT, Gemini, NVIDIA NIM, LiteLLM, and local Ollama (Llama)—allowing multi-step file/bash exploration when arguments progress while halting stuck (tool + args) loops, clamping extra_body.reasoning_budget, and blocking >200k context cliffs pre-call.

Production Tips

  • Keep system prompts static: Move changing dates or request IDs to the end of the user message, and set "max_context_tokens": 195000 on long Claude and Gemini threads.
  • Propagate workflow_id in LangGraph / sub-agents: Use aurex_context.set({"workflow_id": run_id}) so multi-agent nodes share one isolated session budget.
  • Do not retry AurexBlocked: In tenacity, pass retry=retry_if_not_exception_type(AurexBlocked) so intentional circuit-breaker stops are not retried.
  • Interactive Docs & AI-agent guide: https://bhav09.github.io/aurex-sdk/ and https://github.com/bhav09/aurex-sdk (see llms.txt and AGENTS.md).

Credits

Author: Bhavishya Pandit and Aakriti Aggarwal

Metadata

Release files for aurex-sdk 0.5.5

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

Source distribution (sdist)

Source distribution for aurex-sdk 0.5.5
File Size Uploaded Provenance Actions
aurex_sdk-0.5.5.tar.gz 90.3 kB Without provenance Details for aurex_sdk-0.5.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for aurex-sdk 0.5.5
File Interpreter ABI Platform Actions
aurex_sdk-0.5.5-py3-none-any.whl Python 3 none any Details for aurex_sdk-0.5.5-py3-none-any.whl

Total release size: 167.1 kB

Release files / aurex_sdk-0.5.5.tar.gz

Download URL aurex_sdk-0.5.5.tar.gz
Size 90.3 kB
Tags Source
SHA-256 checksum
How to use checksums
9b0c27be651476eca147fdc32207ff70e1cea9f3a44314950633efc5e60ce975
BLAKE2b-256 checksum
How to use checksums
8a759aef85674479d759ca02c895431854ae7e63c06e965202cbc240cdebe78b
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.5-py3-none-any.whl

Download URL aurex_sdk-0.5.5-py3-none-any.whl
Size 76.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
32670780ffbcdf2f0e1aab9584e865877ac6bf2b7497cafab3ec155d1badaf58
BLAKE2b-256 checksum
How to use checksums
18caacfeed130ae3f824933af1916f4d952945fe06a0b73ace19caa245408f44
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.5

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.

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