Cost Calculation
When the SDK reports token counts after a model call, the cost is calculated as:cost_usd remains null for that step.
Example
For agpt-4o call with 500 prompt tokens and 100 completion tokens:
| Tokens | Rate | Cost | |
|---|---|---|---|
| Input | 500 | $0.0000025/token | $0.00125 |
| Output | 100 | $0.0000100/token | $0.00100 |
| Total | $0.00225 |
Budget Enforcement
Workspace Daily Budget
Setdaily_budget_usd on your workspace to limit total spend per day. When cumulative spend for the current day (UTC) reaches this limit, all subsequent runs and steps are denied with WORKSPACE_DAILY_BUDGET_EXCEEDED.
null to remove the limit.
User Daily Budget
Setuser_daily_budget_usd to limit spend per SDK user per day. This is a uniform limit — all users share the same daily budget cap. When any user’s spend reaches the limit, their requests are denied with USER_DAILY_BUDGET_EXCEEDED.
Per-user daily budgets require the Pro plan or higher.
How Budgets Reset
Daily budgets reset at midnight UTC. The Redis spend counters are keyed by date (YYYY-MM-DD) and expire automatically after 25 hours.
Enforcement Flow
When a run starts or a step is created, the guardrails engine checks budgets in this order:- Look up workspace daily spend from Redis (or Postgres fallback)
- Compare against
workspace.daily_budget_usd - If exceeded → DENY with
WORKSPACE_DAILY_BUDGET_EXCEEDED - Look up user daily spend from Redis (or Postgres fallback)
- Compare against
workspace.user_daily_budget_usd - If exceeded → DENY with
USER_DAILY_BUDGET_EXCEEDED
- Calculate
cost_usdfrom model pricing - Atomically increment workspace daily spend counter in Redis
- Atomically increment user daily spend counter in Redis
- Store
cost_usdon the step in Postgres