Admin Console

Budget Management

Set spending limits and track costs across agents and AI providers.

Overview

Budget management helps you control AI costs by setting limits at the agent, team, or organization level with automatic enforcement and alerts.

Spending Limits

Set daily, weekly, or monthly caps

Alerts

Get notified at 50%, 80%, 100%

Analytics

Track spend by agent and model

Creating Budgets

Budgets are enforced by Tork, so they are managed over the REST API. There is no Python cloud SDK — @torknetwork/sdk is npm-only, and tork-governance on PyPI decides on-device and does not track spend. The cost APIs require an organization-scoped API key:

python
import os
import requests

# There is no Python cloud SDK — use the REST API.
TORK_API_KEY = os.environ["TORK_API_KEY"]

response = requests.post(
    "https://tork.network/api/v1/costs/budgets",
    headers={
        "Authorization": f"Bearer {TORK_API_KEY}",
        "Content-Type": "application/json",
    },
    json={
        "budgetName": "Customer Support Agent Budget",
        "budgetType": "monthly",   # daily | weekly | monthly | total
        "budgetAmount": 500.00,
        "currency": "USD",
        "agentId": "agent-123",
        "alertThresholdPercent": 80,
        "hardLimit": True,         # block once the limit is reached
    },
)
response.raise_for_status()

budget = response.json()["budget"]
print(f"Budget created: {budget['id']}")

Checking Budget Status

Monitor budget usage in real-time:

python
headers = {
    "Authorization": f"Bearer {TORK_API_KEY}",
    "Content-Type": "application/json",
}

# List budgets and their current utilisation
budgets = requests.get(
    "https://tork.network/api/v1/costs/budgets",
    headers=headers,
).json()

for budget in budgets["budgets"]:
    print(f"{budget['budgetName']}: {budget['budgetAmount']} {budget['currency']}")

# Check whether a proposed spend would be allowed
check = requests.post(
    "https://tork.network/api/v1/costs/check",
    headers=headers,
    json={
        "agentId": "agent-123",
        "proposedCost": 25.00,
        "proposedTokens": 12000,
    },
).json()

if not check["allowed"]:
    print("Blocked: this spend would breach a hard limit")

for alert in check["alerts"]:
    print(f"[{alert['severity']}] {alert['budgetName']}: {alert['percentUsed']}% used")

Budget Alerts

Configure webhooks for budget alerts:

json
{
  "event": "budget.threshold_reached",
  "budget_id": "budget-123",
  "timestamp": "2024-01-15T10:30:00Z",
  "data": {
    "threshold_percent": 80,
    "used_amount": 400.00,
    "limit_amount": 500.00,
    "remaining_amount": 100.00,
    "period": "monthly",
    "period_end": "2024-01-31T23:59:59Z"
  }
}

Cost Breakdown

Get detailed cost analytics:

python
# Get cost breakdown
breakdown = client.budgets.get_breakdown(
    budget_id="budget-123",
    group_by="model"  # or "agent", "action_type", "day"
)

for item in breakdown.items:
    print(f"{item.group}: ${item.amount} ({item.percent}%)")
# Output:
# gpt-4: $250.00 (62.5%)
# gpt-3.5-turbo: $120.00 (30%)
# claude-3: $30.00 (7.5%)

Tip: Set conservative initial budgets and increase them based on actual usage patterns.

Documentation

Learn to integrate TORK

Upgrade Plan

Current: free

Support

Get help from our team