|
| 1 | +/** |
| 2 | + * Cost Analytics Types |
| 3 | + * |
| 4 | + * Types for the cost attribution dashboard. |
| 5 | + * Combines audit trail metering data with billing export pricing |
| 6 | + * to compute per-org/project/env/model cost breakdowns. |
| 7 | + */ |
| 8 | + |
| 9 | +import { BILLABLE_AUDIT_ACTIONS } from './audit-trail.js'; |
| 10 | + |
| 11 | +export { BILLABLE_AUDIT_ACTIONS }; |
| 12 | + |
| 13 | +// ============================================================================ |
| 14 | +// Query |
| 15 | +// ============================================================================ |
| 16 | + |
| 17 | +export interface CostAnalyticsQuery { |
| 18 | + /** Start time (ISO string or epoch ms) */ |
| 19 | + from?: string | number; |
| 20 | + /** End time (ISO string or epoch ms) */ |
| 21 | + to?: string | number; |
| 22 | + /** Group results by this dimension */ |
| 23 | + group_by?: 'model' | 'environment' | 'account' | 'project' | 'provider' | 'interaction'; |
| 24 | + /** Time series resolution */ |
| 25 | + resolution?: 'hour' | 'day' | 'week' | 'month'; |
| 26 | + /** Filter by model pattern */ |
| 27 | + model?: string; |
| 28 | + /** Filter by environment ID */ |
| 29 | + environment_id?: string; |
| 30 | + /** Filter by provider */ |
| 31 | + provider?: string; |
| 32 | + /** Filter by project ID (optional, for org scope) */ |
| 33 | + project_id?: string; |
| 34 | + /** Filter by account ID (set automatically by server) */ |
| 35 | + account_id?: string; |
| 36 | + /** Scope: 'project' (default, current project) or 'org' (all projects in account) */ |
| 37 | + scope?: 'project' | 'org'; |
| 38 | + /** Pricing source: 'list' (current list prices) or 'historical' (actual prices from billing period). Default: 'list' */ |
| 39 | + pricing_source?: 'list' | 'historical'; |
| 40 | + /** Skip cache and force fresh query */ |
| 41 | + no_cache?: boolean; |
| 42 | +} |
| 43 | + |
| 44 | +// ============================================================================ |
| 45 | +// Response |
| 46 | +// ============================================================================ |
| 47 | + |
| 48 | +export interface CostSummary { |
| 49 | + total_cost: number; |
| 50 | + total_input_tokens: number; |
| 51 | + total_output_tokens: number; |
| 52 | + total_calls: number; |
| 53 | + total_duration_ms: number; |
| 54 | +} |
| 55 | + |
| 56 | +export interface CostByDimension { |
| 57 | + dimension: string; |
| 58 | + cost: number; |
| 59 | + input_tokens: number; |
| 60 | + output_tokens: number; |
| 61 | + calls: number; |
| 62 | +} |
| 63 | + |
| 64 | +export interface CostTimeSeriesPoint { |
| 65 | + timestamp: string; |
| 66 | + cost: number; |
| 67 | + input_tokens: number; |
| 68 | + output_tokens: number; |
| 69 | + calls: number; |
| 70 | +} |
| 71 | + |
| 72 | +export interface ModelPricing { |
| 73 | + model: string; |
| 74 | + input_price_per_m_tokens: number; |
| 75 | + output_price_per_m_tokens: number; |
| 76 | + source: 'billing_export' | 'unavailable'; |
| 77 | +} |
| 78 | + |
| 79 | +export interface CostAnalyticsResponse { |
| 80 | + summary: CostSummary; |
| 81 | + by_dimension: CostByDimension[]; |
| 82 | + time_series: CostTimeSeriesPoint[]; |
| 83 | + pricing: ModelPricing[]; |
| 84 | + query_range: { from: string; to: string }; |
| 85 | + cached: boolean; |
| 86 | +} |
0 commit comments