Enterprise FinOps & AI governance SDK — monitor costs, enforce budgets, and prevent runaway AI loops across every cloud provider.
Project description
ComputeCapX Python SDK
The official Python SDK for ComputeCapX — enterprise FinOps and AI governance. Monitor AI API costs, enforce budget policies, detect runaway agent loops, and stream real-time infrastructure telemetry across every major cloud provider — with zero code changes to your existing AI calls.
Features
- Universal AI Instrumentation — Automatically intercepts OpenAI, Anthropic, Google Gemini, Groq, Mistral, Cohere, and any HTTP-based LLM API. No code changes required.
- Real-time Budget Enforcement — Blocks API calls the moment a project exceeds its budget limit. The block is synchronous and cannot be bypassed.
- Runaway Loop Circuit Breaker — Detects and throttles AI agent feedback loops with three escalation tiers before they cause financial damage.
- Multi-Cloud Infrastructure Telemetry — Auto-detects AWS, GCP, Azure, Oracle Cloud, DigitalOcean, Vercel, and Netlify via metadata APIs with no configuration.
- Distributed Tracing — Captures network calls (urllib3), database queries (SQLite, PostgreSQL), and AI call chains for full cost attribution per trace.
- Crash Handler — Hooks
sys.excepthookto emit a final trace on fatal errors so every execution has a complete record. - Zero-Code CLI Mode — Use
computecapx-runto instrument any existing script or server without touching its source. - Non-Blocking — All telemetry is batched and sent asynchronously. Zero impact on your application latency.
Installation
pip install computecapx
Requirements: Python 3.8+
Quick Start
Option 1: Zero-code CLI wrapper (Recommended)
No code changes required. Save your credentials once and run any script with full telemetry.
# 1. Install the SDK
pip install computecapx
# 2. Save credentials once
computecapx login --key YOUR_API_KEY --project YOUR_PROJECT_ID
# 3. Run any script or server with full monitoring
computecapx-run python my_agent.py
computecapx-run uvicorn app:main
computecapx-run --no-cloud python my_local_script.py
That's it. No imports, no code changes, no .env files.
Option 2: Environment Variables
Set your credentials in your shell or deployment platform and the SDK picks them up automatically.
export COMPUTECAPX_API_KEY=your_api_key_here
export COMPUTECAPX_PROJECT_ID=your_project_id_here
import computecapx
computecapx.instrument() # reads from env vars automatically
import openai
client = openai.OpenAI(api_key="sk-...")
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello!"}]
)
Option 3: Pass credentials directly (Testing only)
You can pass credentials directly in code. This is useful for quick testing, or if you are dynamically loading keys from a secret manager (like AWS Secrets Manager).
Warning: Do not hardcode credentials in production or commit them to version control.
import computecapx
computecapx.instrument(
api_key="YOUR_API_KEY",
project_id="YOUR_PROJECT_ID",
)
Environment Variables
| Variable | Description |
|---|---|
COMPUTECAPX_API_KEY |
Your SDK API key |
COMPUTECAPX_PROJECT_ID |
Your project ID |
COMPUTECAPX_DISABLE_LOOP_CHECK |
Set to true to disable the AI loop circuit breaker |
instrument() Reference
computecapx.instrument(
api_key=None, # SDK API key (or set COMPUTECAPX_API_KEY)
project_id=None, # Project ID (or set COMPUTECAPX_PROJECT_ID)
claim_infrastructure=True, # Send cloud heartbeats — set False for local dev
instrument_ai=True, # Intercept AI calls and enforce policies
backend_url=None, # Override backend (self-hosted only)
)
Credential resolution order:
- Direct argument
- Environment variable (
COMPUTECAPX_API_KEY/COMPUTECAPX_PROJECT_ID) - CLI config file (
~/.computecapx/config.jsonwritten bycomputecapx login)
CLI Commands
# Authenticate and save credentials to ~/.computecapx/config.json
computecapx login --key YOUR_API_KEY --project YOUR_PROJECT_ID
# Update the default project
computecapx set-project YOUR_PROJECT_ID
# Run diagnostics and test backend connectivity
computecapx status
computecapx-run Flags
computecapx-run [flags] <script.py or module> [script args...]
--no-cloud Disable infrastructure heartbeats (auto-enabled on local)
--no-ai Disable AI call interception
--no-loop Disable the runaway loop circuit breaker
Runaway Loop Circuit Breaker
The circuit breaker automatically detects repetitive AI agent patterns:
| Tier | Trigger | Action |
|---|---|---|
| Warning | 5 similar requests in 10 seconds | 2-second throttle applied |
| Throttle | 10 similar requests in 20 seconds | 5-second throttle applied |
| Block | 20 requests in 60 seconds | ComputeCapAILoopBlocker raised, task permanently blocked |
Supported AI Providers
| Provider | Detection Method |
|---|---|
| OpenAI | HTTP intercept (httpx + requests) |
| Anthropic | HTTP intercept (httpx + requests) |
| Google Gemini | HTTP intercept + gRPC (sys.meta_path hook) |
| Groq | HTTP intercept |
| Mistral | HTTP intercept |
| Cohere | HTTP intercept |
| Any OpenAI-compatible API | HTTP intercept |
Supported Cloud Providers
| Provider | Detection Method |
|---|---|
| AWS EC2 | IMDSv2 token + metadata endpoint |
| Google Cloud (GCP) | Compute Metadata Server |
| Microsoft Azure | Instance Metadata Service |
| DigitalOcean | Droplet Metadata API |
| Oracle Cloud (OCI) | OPCv2 metadata endpoint |
| Vercel | VERCEL environment variable |
| Netlify | NETLIFY environment variable |
| Local / Container | Hostname fallback |
Error Classes
Both errors inherit from BaseException so they cannot be accidentally swallowed by a bare except Exception in user code.
from computecapx import ComputeCapBudgetExceededError, ComputeCapAILoopBlocker
try:
response = openai_client.chat.completions.create(...)
except ComputeCapBudgetExceededError:
print("Monthly budget limit reached — request blocked by ComputeCapX.")
except ComputeCapAILoopBlocker:
print("Runaway agent loop detected — task permanently halted.")
License
MIT License — see LICENSE for details.
© 2026 ComputeCapX
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file computecapx-0.1.0.tar.gz.
File metadata
- Download URL: computecapx-0.1.0.tar.gz
- Upload date:
- Size: 33.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c811627cce9189f6593479c408ced41b4855c9490780dd7b761110f85c26aba8
|
|
| MD5 |
b06506b8601feffd1b4ff02b729e78b4
|
|
| BLAKE2b-256 |
afcc1d5ca0beca08062f20a5c3c3612d36addf82adea2132357b310ee8509f58
|
Provenance
The following attestation bundles were made for computecapx-0.1.0.tar.gz:
Publisher:
publish.yml on computecapx/computecapx-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
computecapx-0.1.0.tar.gz -
Subject digest:
c811627cce9189f6593479c408ced41b4855c9490780dd7b761110f85c26aba8 - Sigstore transparency entry: 2071229921
- Sigstore integration time:
-
Permalink:
computecapx/computecapx-python@bed55fd0e1f69c77163644eb74e7f1202e36f486 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/computecapx
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@bed55fd0e1f69c77163644eb74e7f1202e36f486 -
Trigger Event:
push
-
Statement type:
File details
Details for the file computecapx-0.1.0-py3-none-any.whl.
File metadata
- Download URL: computecapx-0.1.0-py3-none-any.whl
- Upload date:
- Size: 29.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0a9f105912cefcac127309c2f4bd28939a5e9d237e2fdd3f8efb2bff2a5db8e
|
|
| MD5 |
e667cf859e097e9cc389316da805f162
|
|
| BLAKE2b-256 |
047f419bd09320cd417bc8e1d441fe1cea501c0b51669c9c33bb1010382f9f2f
|
Provenance
The following attestation bundles were made for computecapx-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on computecapx/computecapx-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
computecapx-0.1.0-py3-none-any.whl -
Subject digest:
d0a9f105912cefcac127309c2f4bd28939a5e9d237e2fdd3f8efb2bff2a5db8e - Sigstore transparency entry: 2071229939
- Sigstore integration time:
-
Permalink:
computecapx/computecapx-python@bed55fd0e1f69c77163644eb74e7f1202e36f486 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/computecapx
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@bed55fd0e1f69c77163644eb74e7f1202e36f486 -
Trigger Event:
push
-
Statement type: