Micro-USD Precision
All costs are tracked in micro-USD (1/1,000,000 of a USD) using integer precision. This avoids floating-point rounding errors while providing the granularity needed for sub-cent token costs.- Example: $0.01 (1 cent) is represented as
10,000micro-USD.
Usage Model
TheRunUsage struct (defined in apps/strait/internal/domain/types.go) tracks individual usage events:
Budget Limits
Budgets are defined in theproject_quotas table and enforced at two levels:
1. Per-Run Budget
- Field:
max_cost_per_run_microusd - Enforcement: Checked every time the SDK reports usage via the
/sdk/v1/runs/{runID}/usageendpoint. - Behavior: If the reported usage would exceed the per-run limit, the request is rejected, and the run is optionally failed.
2. Daily Project Budget
- Field:
max_daily_cost_microusd - Enforcement: Checked at trigger time.
- Behavior: Before a new run is enqueued, the system aggregates the total cost of all runs for the current day (based on the project’s configured timezone). If the limit is reached, the trigger request is rejected.
Budget Checks
Budget validation occurs before recording the usage or enqueuing the run. This ensures that limits are strictly enforced and that violating requests do not inflate the recorded costs.Project Quotas Table
Theproject_quotas table stores the limits for each project: