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.6

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.6
File Size Uploaded
tetherai_python-0.1.6.tar.gz 15.3 kB Details

Built distribution (wheel)

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

Total release size: 31.4 kB

Release files / tetherai_python-0.1.6.tar.gz

Download URL tetherai_python-0.1.6.tar.gz
Size 15.3 kB
Tags Source
SHA-256 checksum
How to use checksums
9da34c8500f9bb9772a4c955837d9b0255a48e0ac62d88726b543c17bd9f0b4f
BLAKE2b-256 checksum
How to use checksums
29db4a8b1870de82f70192ec5c14221b1037cec5b9f9ed7ef55141d6a9ed0489
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

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

Download URL tetherai_python-0.1.6-py3-none-any.whl
Size 16.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
46a3b80d132c82207d628e9cb237dc1dad82f4edebdfdec05a467d2f4b6f25f9
BLAKE2b-256 checksum
How to use checksums
856dca4d0742f6de70052225c69e825d7bdce1e49b5c1b9e703c87b8fd2ceb58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release history Release notifications | RSS feed

0.1.31

2 release files

This release

0.1.6 This release

2 release files

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