Loading…
Loading…
Features · Control · Cost and budgets
Real-time per-call cost tracking with budget enforcement, model-specific pricing and cache savings. Attach a tracker as hooks, or set max_budget_usd on the agent to stop a run between steps.
from shipit_agent import Agentfrom shipit_agent.costs import CostTracker, Budgettracker = CostTracker(budget=Budget(max_dollars=5.00))agent = Agent.with_builtins(llm=llm, hooks=tracker.as_hooks())result = agent.run("Analyze this codebase")print(f"Total cost: ${tracker.total_cost:.4f}")
Model call
tokens in and out
Pricing table
per model, with cache
Tracker
running total
Budget
warn, then stop
The code is a checked example from the docs; the output is an example of what it prints.
from shipit_agent import Agent
from shipit_agent.costs import CostTracker, Budget
tracker = CostTracker(budget=Budget(max_dollars=5.00))
agent = Agent.with_builtins(llm=llm, hooks=tracker.as_hooks())
result = agent.run("Analyze this codebase")
print(f"Total cost: ${tracker.total_cost:.4f}")
tokens = tracker.total_tokens
print(f"Tokens: {tokens['input_tokens']} in, {tokens['output_tokens']} out")6 more ways to use it
Each example is from the docs and checked against the library.
Set a hard spending limit. The tracker raises `BudgetExceededError` when the accumulated cost exceeds the budget, and emits a warning callback when crossing the warning threshold.
from shipit_agent.costs import Budget, BudgetExceededError
budget = Budget(
max_dollars=5.00, # hard limit
warn_at=0.80, # warn at 80% ($4.00)
)
tracker = CostTracker(budget=budget)Pricing built in
Input, output and prompt-cache prices for the models shipit knows.
Budgets
Warn at a threshold, stop at the limit.
Attribution
A breakdown by model and by call.
Custom prices
Add or override a model's prices.
| Parameter | Default | What it does |
|---|---|---|
| max_budget_usd | None | Stop a run, between steps, once its estimated cost reaches this many US dollars. Needs pricing data for the model; without it the run stops rather than spend unchecked. |
| hooks | None | Code run before and after model calls and tools. Hooks. |
| max_task_tokens | None | Stop the run after this many tokens. |