Skip to main content

TetherAI

CI PyPI Python License

Financial circuit breaker for AI agents. Stop runaway LLM costs before they happen.

AI agents don't crash when they fail — they loop, hallucinate, and retry. A stuck CrewAI crew can silently burn hundreds of dollars in LLM API calls over a weekend. Traditional monitoring tools like Datadog will show you an API cost spike on Monday morning. TetherAI kills the agent before it spends your money.

Install

pip install tetherai-python

With CrewAI support:

pip install tetherai-python[crewai]

Quick Start

The @enforce_budget decorator wraps any function with budget guardrails:

from tetherai import tether, BudgetExceededError
import litellm


@tether.enforce_budget(max_usd=0.05)
def my_workflow():
    for i in range(100):
        response = litellm.completion(
            model="gpt-4o-mini",
            messages=[{"role": "user", "content": f"Count to {i}"}]
        )
        print(f"Call {i+1}: {response.choices[0].message.content[:50]}...")


try:
    my_workflow()
except BudgetExceededError as e:
    print(f"\n🛑 Stopped! Spent ${e.spent_usd:.4f} of ${e.budget_usd:.2f} budget")

Expected output:

Call 1: 0...
Call 2: 0, 1...
Call 3: 0, 1, 2...

🛑 Stopped! Spent $0.0501 of $0.05 budget

CrewAI Integration

For CrewAI crews, use protect_crew() to wrap budget enforcement around the entire crew:

from tetherai import protect_crew, BudgetExceededError
from crewai import Agent, Task, Crew, Process

researcher = Agent(
    role="Research Analyst",
    goal="Find comprehensive information on AI observability tools",
    backstory="You are a thorough research analyst known for detailed analysis.",
    verbose=True,
)

task = Task(
    description="Research the competitive landscape of AI observability tools",
    agent=researcher,
)

crew = Crew(agents=[researcher], tasks=[task], process=Process.sequential)

protected_crew = protect_crew(crew, max_usd=0.10)

try:
    result = protected_crew.kickoff()
except BudgetExceededError as e:
    print(f"Budget exceeded: ${e.spent_usd:.2f} of ${e.budget_usd:.2f}")

What Happens When Budget Is Exceeded

When the budget is exceeded, TetherAI raises BudgetExceededError with details about the run:

{
  "run_id": "run_abc123",
  "budget_usd": 0.10,
  "spent_usd": 0.13,
  "turns": 7,
  "spans": [
    {
      "span_type": "llm_call",
      "model": "gpt-4o-mini",
      "input_tokens": 1250,
      "output_tokens": 340,
      "cost_usd": 0.0019,
      "status": "ok"
    }
  ]
}

How It Works

TetherAI patches litellm.completion at runtime to intercept every LLM call your agent makes. Before each call, it counts input tokens locally using tiktoken and checks the projected cost against your budget. If the budget would be exceeded, the call is blocked and a BudgetExceededError is raised. After each successful call, actual token usage from the LLM response is recorded for accurate cost tracking.

Supported Frameworks

Framework Status Integration
CrewAI ✅ Supported protect_crew()
LiteLLM (direct) ✅ Supported @enforce_budget decorator
LangChain 🔜 Coming soon —
smolagents 🔜 Coming soon —

Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

License

Apache 2.0

Metadata

Release files for tetherai-python 0.1.31

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

Source distribution (sdist)

Source distribution for tetherai-python 0.1.31
File Size Uploaded Provenance
tetherai_python-0.1.31.tar.gz 15.3 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for tetherai-python 0.1.31
File Interpreter ABI Platform
tetherai_python-0.1.31-py3-none-any.whl Python 3 none any Details

Total release size: 31.4 kB

Release files / tetherai_python-0.1.31.tar.gz

Download URL tetherai_python-0.1.31.tar.gz
Size 15.3 kB
Tags Source
SHA-256 checksum
How to use checksums
30c1207c973a64621999c3371fdae1d0d3798be5141b790979a058dee01c3436
BLAKE2b-256 checksum
How to use checksums
c7a67d4b0b470968c79b90a6b89a357b6eeb8841ba9f9be3a8817ae299b423f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Feb 16, 2026.

Transparency log

Release files / tetherai_python-0.1.31-py3-none-any.whl

Download URL tetherai_python-0.1.31-py3-none-any.whl
Size 16.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f89072ec5a18f938f41bf44e1d1f4acb762794dfe959f79f57f793fc57a97859
BLAKE2b-256 checksum
How to use checksums
5bc0a0149596dd13c109048519a2912032f8fca38f987b0826068aa52244075a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Feb 16, 2026.

Transparency log

Security for tetherai-python 0.1.31

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for tetherai_python-0.1.31.tar.gz

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 Feb 16, 2026.

Transparency log

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