Skip to main content
Strait includes a built-in cost tracking and budgeting system, primarily designed for managing expenses related to AI model usage (e.g., OpenAI, Anthropic).

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,000 micro-USD.

Usage Model

The RunUsage struct (defined in apps/strait/internal/domain/types.go) tracks individual usage events:

Budget Limits

Budgets are defined in the project_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}/usage endpoint.
  • 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

The project_quotas table stores the limits for each project:

Budget Enforcement

Usage reports are always recorded, and budget checks are performed at trigger time and during execution.