// Rates as of 2026-Q1 — update periodically
const MODEL_RATES = {
    // Anthropic
    'claude-opus-4-6': { input: 15.00, output: 75.00 },
    'claude-sonnet-4-6': { input: 3.00, output: 15.00 },
    'claude-haiku-4-5': { input: 0.25, output: 1.25 },
    'claude-haiku-4-5-20251001': { input: 0.25, output: 1.25 },
    // OpenAI
    'gpt-4o': { input: 2.50, output: 10.00 },
    'gpt-4o-mini': { input: 0.15, output: 0.60 },
    'gpt-4-turbo': { input: 10.00, output: 30.00 },
    'o1': { input: 15.00, output: 60.00 },
    'o3-mini': { input: 1.10, output: 4.40 },
    // DeepSeek
    'deepseek-chat': { input: 0.27, output: 1.10 },
    'deepseek-reasoner': { input: 0.55, output: 2.19 },
    // Google
    'gemini-2.5-flash': { input: 0.15, output: 0.60 },
    'gemini-2.5-pro': { input: 1.25, output: 5.00 },
};
// Default: Claude Sonnet — used for 'claude-code' provider or unknown models
const DEFAULT_RATE = MODEL_RATES['claude-sonnet-4-6'];
/**
 * Estimates the USD cost of an LLM call using character-based token approximation.
 * Rule of thumb: ~4 characters per token. Actual costs may vary.
 * Use for guardrail enforcement, not billing.
 */
export function estimateCost(inputText, outputText, model) {
    const rate = (model && MODEL_RATES[model]) ? MODEL_RATES[model] : DEFAULT_RATE;
    const inputTokens = Math.ceil(inputText.length / 4);
    const outputTokens = Math.ceil(outputText.length / 4);
    return (inputTokens * rate.input + outputTokens * rate.output) / 1_000_000;
}
export function formatCost(usd) {
    if (usd === 0)
        return '$0.0000';
    if (usd < 0.0001)
        return `<$0.0001`;
    return `$${usd.toFixed(4)}`;
}
