| title |
CostAnalytics |
| description |
CostAnalytics Schema Reference |
| category |
ai |
| zodFile |
cost |
**Source:** `packages/spec/src/ai/cost.zod.ts`
| Property |
Type |
Required |
Description |
| periodStart |
string |
✅ |
ISO 8601 timestamp |
| periodEnd |
string |
✅ |
ISO 8601 timestamp |
| totalCost |
number |
✅ |
|
| totalRequests |
integer |
✅ |
|
| totalTokens |
integer |
optional |
|
| currency |
string |
optional |
|
| averageCostPerRequest |
number |
✅ |
|
| averageCostPerToken |
number |
optional |
|
| averageRequestsPerDay |
number |
✅ |
|
| costTrend |
Enum<'increasing' | 'decreasing' | 'stable'> |
optional |
|
| trendPercentage |
number |
optional |
% change vs previous period |
| byModel |
object[] |
optional |
|
| byProvider |
object[] |
optional |
|
| byUser |
object[] |
optional |
|
| byAgent |
object[] |
optional |
|
| byOperation |
object[] |
optional |
|
| byDate |
object[] |
optional |
|
| topModels |
object[] |
optional |
|
| topUsers |
object[] |
optional |
|
| topAgents |
object[] |
optional |
|
| tokensPerDollar |
number |
optional |
|
| requestsPerDollar |
number |
optional |
|
import { CostAnalyticsSchema } from '@objectstack/spec/ai';
import type { CostAnalytics } from '@objectstack/spec/ai';
// Validate data
const result = CostAnalyticsSchema.parse(data);
// Type-safe usage
const myCostAnalytics: CostAnalytics = {
periodStart: 'example',
periodEnd: 'example',
totalCost: 0,
// ... other required fields
};