Strait includes a built-in cost tracking and budgeting system, primarily designed for managing expenses related to AI model usage (e.g., OpenAI, Anthropic).Documentation Index
Fetch the complete documentation index at: https://docs.strait.dev/llms.txt
Use this file to discover all available pages before exploring further.
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:
| Field | Type | Description |
|---|---|---|
id | string | Unique identifier (UUIDv7). |
run_id | string | Reference to the Job Run. |
provider | string | AI provider (e.g., openai, anthropic). |
model | string | Model name (e.g., gpt-4o). |
prompt_tokens | int | Number of input tokens. |
completion_tokens | int | Number of output tokens. |
total_tokens | int | Sum of prompt and completion tokens. |
cost_microusd | int64 | Calculated cost in micro-USD. |
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: