9be8f76bc7
- Lane Queue: per-session FIFO queue in gateway replacing reject-when-busy (9 tests) - Credential Redaction: redactConfig() expanded to cover 18+ secret fields (16 tests) - Web UI Token Dashboard: system.tokenUsage endpoint + Usage page with summary cards - xAI (Grok) Provider: OpenAI-compatible client with model pricing - Voyage AI Embeddings: new embedding provider with configurable dimensions (5 tests) - Update gap analysis: 90→95 match (70%→74%), Tier 3 section marked DONE - Update state.json: test count 1001→1034, add tier3_completion entry Total: 1034 tests passing across 85 files, typecheck clean
45 lines
1.9 KiB
TypeScript
45 lines
1.9 KiB
TypeScript
/** Approximate cost per million tokens for known models. */
|
|
export const MODEL_COSTS_PER_MILLION: Record<string, { input: number; output: number }> = {
|
|
// Anthropic
|
|
'claude-sonnet-4-20250514': { input: 3, output: 15 },
|
|
'claude-3-5-haiku-20241022': { input: 0.80, output: 4 },
|
|
'claude-opus-4-20250514': { input: 15, output: 75 },
|
|
// OpenAI
|
|
'gpt-4o': { input: 2.50, output: 10 },
|
|
'gpt-4o-mini': { input: 0.15, output: 0.60 },
|
|
// Gemini
|
|
'gemini-2.0-flash': { input: 0.10, output: 0.40 },
|
|
'gemini-2.0-flash-lite': { input: 0.025, output: 0.10 },
|
|
'gemini-2.5-pro': { input: 1.25, output: 10 },
|
|
'gemini-2.5-flash': { input: 0.15, output: 0.60 },
|
|
'gemini-1.5-pro': { input: 1.25, output: 5 },
|
|
'gemini-1.5-flash': { input: 0.075, output: 0.30 },
|
|
// GitHub Copilot (included in subscription, tracked at $0)
|
|
'gpt-4.1': { input: 0, output: 0 },
|
|
'gpt-4.1-mini': { input: 0, output: 0 },
|
|
'claude-sonnet-4': { input: 0, output: 0 },
|
|
'claude-haiku-4': { input: 0, output: 0 },
|
|
// Local / unknown models
|
|
'default': { input: 0, output: 0 },
|
|
// xAI (Grok)
|
|
'grok-3': { input: 3, output: 15 },
|
|
'grok-3-mini': { input: 0.30, output: 0.50 },
|
|
'grok-2': { input: 2, output: 10 },
|
|
'grok-2-mini': { input: 0.10, output: 0.25 },
|
|
'grok-3-fast': { input: 5, output: 25 },
|
|
// Bedrock (Meta Llama)
|
|
'meta.llama3-1-70b-instruct-v1:0': { input: 0.72, output: 0.72 },
|
|
'meta.llama3-1-8b-instruct-v1:0': { input: 0.22, output: 0.22 },
|
|
// Bedrock (Amazon Titan)
|
|
'amazon.titan-text-express-v1': { input: 0.20, output: 0.60 },
|
|
};
|
|
|
|
/**
|
|
* Estimate the dollar cost for a given number of input/output tokens.
|
|
* Falls back to zero cost for unknown or local models.
|
|
*/
|
|
export function estimateCost(inputTokens: number, outputTokens: number, modelName?: string): number {
|
|
const costs = MODEL_COSTS_PER_MILLION[modelName ?? ''] ?? MODEL_COSTS_PER_MILLION['default'];
|
|
return (inputTokens * costs.input + outputTokens * costs.output) / 1_000_000;
|
|
}
|