Usage
Usage protocol schemas
AI Usage Primitives
Platform contract for measuring AI consumption.
Scope (intentionally minimal):
- Token usage per call.
- Per-call cost (computed from a model's unit price).
- Model unit pricing.
NOT in scope (deferred to FinOps / product layer):
- Budget definitions, enforcement, alerts.
- Cost allocation / chargeback / reports.
- Optimization recommendations.
Rationale: the platform must record what was used; deciding what to do about it (block calls, send alerts, allocate to cost centers) is product policy that varies wildly between tenants.
Source: packages/spec/src/ai/usage.zod.ts
TypeScript Usage
import { AIUsageRecordSchema, TokenUsageSchema } from '@objectstack/spec/ai';
import type { AIUsageRecord, TokenUsage } from '@objectstack/spec/ai';
// Validate data
const result = AIUsageRecordSchema.parse(data);AIUsageRecord
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| model | string | ✅ | |
| usage | { promptTokens: integer; completionTokens: integer; totalTokens: integer } | ✅ | |
| costUsd | number | ✅ | Computed cost in USD |
| latencyMs | number | optional | |
| timestamp | string | optional |
TokenUsage
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| promptTokens | integer | ✅ | Tokens consumed by the prompt |
| completionTokens | integer | ✅ | Tokens generated in the completion |
| totalTokens | integer | ✅ | Total tokens (prompt + completion) |