Cost Tracking
Track token usage and costs across all agents. Optional and off by default.
Setup
cost.py
from veska import CostTracker
tracker = CostTracker(enabled=True)
# Or enable later
tracker = CostTracker()
tracker.enable()Recording usage
Usage is recorded automatically when using the Orchestrator with tracking enabled. You can also record manually:
record.py
tracker.record(
agent_name="researcher",
model="claude-sonnet-4-6",
input_tokens=1500,
output_tokens=800,
task_id="task_001",
)Querying costs
query.py
# Total tokens
print(tracker.total_tokens)
# {"input": 15000, "output": 8000, "total": 23000}
# Total cost
print(f"Total: ${tracker.total_cost:.4f}")
# Per-agent breakdown
for agent, cost in tracker.get_agent_costs().items():
print(f" {agent}: ${cost:.4f}")Custom pricing
pricing.py
# Override default pricing (per 1M tokens)
tracker.set_pricing("claude-sonnet-4-6", input_price=3.0, output_price=15.0)
tracker.set_pricing("gpt-4o", input_price=2.50, output_price=10.0)With Orchestrator
orch.py
orchestrator = Orchestrator(
model="claude-sonnet-4-6",
agents=[researcher, writer],
tracking={"enabled": True},
)
result = orchestrator.run("Write a report")
# Cost tracking happens automaticallyPersistence
persist.py
# Save cost data to your own storage
def save_costs(record):
db.insert("costs", record)
tracker.set_storage(save_costs)