/** * Cost Calculator Types * * TypeScript interfaces for trace parsing, pricing configuration, and cost reports. * * Costs are sourced from the trace events themselves (the as-charged "original" * cost), with `costs.yml` applied as an optional override layer (the "adjusted" * cost). Both figures are surfaced per model and per host. */ export interface TokenUsage { inputTokens?: number; outputTokens?: number; cachedInputTokens?: number; reasoningTokens?: number; } import type { LLMGenerationCost, LLMGenerationUsage, LLMUsageEvent } from '@outputai/llm'; export type LLMUsageLine = LLMUsageEvent['usage'][number]; export interface HTTPCostEvent { type: 'http:request:cost'; url: string; requestId: string; total: number; } export interface HTTPCountEvent { type: 'http:request:count'; url: string; requestId: string; } export interface NodeAttributes { 'llm:usage'?: LLMUsageEvent; 'llm:generation:usage'?: LLMGenerationUsage; 'llm:generation:cost'?: LLMGenerationCost; 'http:request:cost'?: HTTPCostEvent; 'http:request:count'?: HTTPCountEvent; } export interface TraceNode { id?: string; kind: string; name?: string; startedAt?: number; endedAt?: number; children?: TraceNode[]; input?: Record; output?: Record; attributes?: NodeAttributes; } export interface LLMCall { stepName: string; llmName: string; model: string; usage: TokenUsage; originalCost: number; lines: LLMUsageLine[]; incomplete: boolean; } export interface HTTPCall { stepName: string; url: string; method: string; input: Record; output: Record; status?: number; host: string; originalCost?: number; } export interface ModelPricing { provider: string; input: number; output: number; cached_input?: number; reasoning?: number; } export interface EndpointConfig { pattern: string; units_per_request?: number; units_per_line?: number; price?: number; price_per_item?: number; items_path?: string; } export interface ServiceConfig { type: 'token' | 'unit' | 'request' | 'response_cost'; url_pattern: string; usage_path?: string; per_million?: number; input_field?: string; output_field?: string; input_per_million?: number; output_per_million?: number; price_per_unit?: number; endpoints?: Record; model_path?: string; models?: Record; default_price?: number; cost_path?: string; billable_method?: string; fallback_models?: Record; default_fallback?: number; } export interface PricingConfig { models: Record; services: Record; } export interface LLMCostResult { step: string; model: string; input: number; output: number; cached: number; reasoning: number; originalCost: number; adjustedCost: number; incomplete: boolean; } export interface ServiceCostResult { step: string; cost: number; usage: string; kind: 'computed' | 'estimated' | 'failed'; model?: string; endpoint?: string; warning?: string; details?: Record; } export interface HTTPCostResult { step: string; host: string; usage: string; originalCost: number; adjustedCost: number; } export interface HostCostSummary { host: string; calls: HTTPCostResult[]; originalTotalCost: number; adjustedTotalCost: number; } export interface CostReport { traceFile: string; workflowName: string; durationMs: number | null; llmCalls: LLMCostResult[]; llmOriginalCost: number; llmAdjustedCost: number; totalInputTokens: number; totalOutputTokens: number; totalCachedTokens: number; totalReasoningTokens: number; httpCosts: HostCostSummary[]; httpOriginalCost: number; httpAdjustedCost: number; originalTotalCost: number; totalCost: number; } export interface LLMModelSummary { model: string; count: number; originalCost: number; adjustedCost: number; incomplete: boolean; } export interface HostSummary { host: string; callCount: number; originalCost: number; adjustedCost: number; } export interface VerboseFlags { hasReasoning: boolean; hasCached: boolean; } export interface ParsedCostData { traceFile: string; workflowName: string; duration: string; llmModels: LLMModelSummary[]; llmTotalCalls: number; llmOriginalCost: number; llmAdjustedCost: number; hosts: HostSummary[]; httpTotalCalls: number; httpOriginalCost: number; httpAdjustedCost: number; verbose: VerboseFlags; llmCalls: LLMCostResult[]; httpDetails: HostCostSummary[]; totalInputTokens: number; totalOutputTokens: number; totalCachedTokens: number; totalReasoningTokens: number; originalTotalCost: number; totalCost: number; isEmpty: boolean; }