Skip to main content
Stop agents when they’ve spent too much money.

Simple API

from splinter import Splinter

s = Splinter(
    openai_key="sk-...",
    max_budget=1.0,  # Stop at $1
)

result = await s.run("helper", "Do something expensive")
print(f"Spent: ${s.cost:.4f}")

Advanced API

from splinter import Gateway, ExecutionLimits

gateway = Gateway(limits=ExecutionLimits(
    max_budget=5.0,  # $5 max
))
gateway.configure_provider("openai", api_key="sk-...")

# Check current spend
metrics = gateway.get_metrics()
print(f"Total cost: ${metrics['total_cost']:.4f}")

Per-Agent Limits

from splinter import ExecutionLimits

limits = ExecutionLimits(
    max_budget=10.0,           # Workflow max
    per_agent_max_budget=2.0,  # Each agent max
)

Error Handling

from splinter.exceptions import BudgetExceededError

try:
    result = await workflow.run()
except BudgetExceededError as e:
    print(f"Budget exceeded: ${e.current:.4f} >= ${e.limit:.4f}")

Cost Tracking

Each provider tracks costs automatically:
ProviderPricing Source
OpenAIPer-model pricing table
AnthropicPer-model pricing table
GeminiPer-model pricing table
GrokPer-model pricing table
# After a call
response = await gateway.call(...)
print(f"This call cost: ${response.cost:.4f}")
print(f"Input tokens: {response.input_tokens}")
print(f"Output tokens: {response.output_tokens}")