File size: 10,152 Bytes
ed57015
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import type Database from 'better-sqlite3';

/**
 * Paid-equivalent pricing per model: what the SAME model (or its nearest
 * equivalent) costs per million tokens on paid APIs. Used by the analytics
 * "Est. savings" stat so it reflects realistic savings rather than pricing
 * every token like a frontier model.
 *
 * Source: OpenRouter public pricing API (paid, non-:free variants),
 * snapshot 2026-06-05; closed models use their official API prices.
 * `null` = no paid equivalent exists (stealth/preview models) β€” analytics
 * falls back to a modest default.
 *
 * Format: [platform, model_id, $/M input, $/M output]
 */
type PricingRow = [string, string, number | null, number | null];

export const MODEL_PRICING: PricingRow[] = [
  // Cerebras
  ['cerebras', 'gpt-oss-120b', 0.039, 0.18],
  ['cerebras', 'llama3.1-8b', 0.02, 0.03],
  ['cerebras', 'qwen-3-235b-a22b-instruct-2507', 0.071, 0.10],
  ['cerebras', 'zai-glm-4.7', 0.40, 1.75],
  // legacy ids (older DBs)
  ['cerebras', 'qwen-3-coder-480b', 0.22, 1.80],
  ['cerebras', 'llama-4-maverick-17b-128e-instruct', 0.15, 0.60],
  ['cerebras', 'qwen3-235b', 0.455, 1.82],

  // Cloudflare Workers AI
  ['cloudflare', '@cf/deepseek-ai/deepseek-r1-distill-qwen-32b', 0.29, 0.29],
  ['cloudflare', '@cf/google/gemma-4-26b-a4b-it', 0.06, 0.33],
  ['cloudflare', '@cf/ibm-granite/granite-4.0-h-micro', 0.017, 0.112],
  ['cloudflare', '@cf/meta/llama-3.3-70b-instruct-fp8-fast', 0.10, 0.32],
  ['cloudflare', '@cf/meta/llama-4-scout-17b-16e-instruct', 0.08, 0.30],
  ['cloudflare', '@cf/moonshotai/kimi-k2.6', 0.684, 3.42],
  ['cloudflare', '@cf/nvidia/nemotron-3-120b-a12b', 0.09, 0.45],
  ['cloudflare', '@cf/openai/gpt-oss-120b', 0.039, 0.18],
  ['cloudflare', '@cf/qwen/qwen3-30b-a3b-fp8', 0.09, 0.45],
  ['cloudflare', '@cf/zai-org/glm-4.7-flash', 0.06, 0.40],
  ['cloudflare', '@cf/meta/llama-3.1-70b-instruct', 0.40, 0.40], // legacy

  // Cohere (official API prices; Reasoning shares Command A pricing)
  ['cohere', 'command-a-03-2025', 2.50, 10.00],
  ['cohere', 'command-a-reasoning-08-2025', 2.50, 10.00],
  ['cohere', 'command-r-08-2024', 0.15, 0.60],
  ['cohere', 'command-r-plus-08-2024', 2.50, 10.00],

  // GitHub Models (OpenAI official prices)
  ['github', 'gpt-4o', 2.50, 10.00],
  ['github', 'openai/gpt-4.1', 2.00, 8.00],
  ['github', 'openai/gpt-5', 1.25, 10.00], // legacy

  // Google AI Studio (official prices)
  ['google', 'gemini-2.5-flash', 0.30, 2.50],
  ['google', 'gemini-2.5-flash-lite', 0.10, 0.40],
  ['google', 'gemini-2.5-pro', 1.25, 10.00],
  ['google', 'gemini-3-flash-preview', 0.50, 3.00],
  ['google', 'gemini-3.1-flash-lite-preview', 0.25, 1.50],
  ['google', 'gemini-3.1-pro-preview', 2.00, 12.00],
  ['google', 'gemini-3.5-flash', 1.50, 9.00],
  ['google', 'gemma-4-26b-a4b-it', 0.06, 0.33],
  ['google', 'gemma-4-31b-it', 0.12, 0.37],

  // Groq (compound is an agentic pipeline β€” estimated at its underlying
  // gpt-oss models' prices)
  ['groq', 'groq/compound', 0.039, 0.18],
  ['groq', 'groq/compound-mini', 0.029, 0.14],
  ['groq', 'llama-3.1-8b-instant', 0.02, 0.03],
  ['groq', 'llama-3.3-70b-versatile', 0.10, 0.32],
  ['groq', 'meta-llama/llama-4-scout-17b-16e-instruct', 0.08, 0.30],
  ['groq', 'llama-4-scout-17b-16e-instruct', 0.08, 0.30], // legacy id
  ['groq', 'openai/gpt-oss-120b', 0.039, 0.18],
  ['groq', 'openai/gpt-oss-20b', 0.029, 0.14],
  ['groq', 'openai/gpt-oss-safeguard-20b', 0.075, 0.30],
  ['groq', 'qwen/qwen3-32b', 0.08, 0.28],

  // Hugging Face Inference
  ['huggingface', 'Qwen/Qwen3-Coder-Next', 0.11, 0.80],
  ['huggingface', 'deepseek-ai/DeepSeek-V4-Flash', 0.098, 0.197],
  ['huggingface', 'moonshotai/Kimi-K2.6', 0.684, 3.42],
  ['huggingface', 'accounts/fireworks/models/llama-v3p3-70b-instruct', 0.10, 0.32], // legacy

  // Kilo (Poolside Laguna is stealth β€” no paid equivalent)
  ['kilo', 'nvidia/nemotron-3-super-120b-a12b:free', 0.09, 0.45],
  ['kilo', 'poolside/laguna-m.1:free', null, null],
  ['kilo', 'poolside/laguna-xs.2:free', null, null],
  ['kilo', 'stepfun/step-3.7-flash:free', 0.20, 1.15],

  // LLM7
  ['llm7', 'codestral-latest', 0.30, 0.90],

  // Mistral (official La Plateforme prices; Magistral per official page)
  ['mistral', 'codestral-latest', 0.30, 0.90],
  ['mistral', 'devstral-latest', 0.40, 2.00],
  ['mistral', 'magistral-medium-latest', 2.00, 5.00],
  ['mistral', 'ministral-8b-latest', 0.15, 0.15],
  ['mistral', 'mistral-large-latest', 0.50, 1.50],
  ['mistral', 'mistral-medium-latest', 1.50, 7.50],
  ['mistral', 'mistral-small-latest', 0.15, 0.60],

  // Moonshot / MiniMax (legacy platforms, may exist in older DBs)
  ['moonshot', 'kimi-latest', 0.684, 3.42],
  ['minimax', 'MiniMax-M1', 0.40, 2.20],

  // NVIDIA NIM
  ['nvidia', 'deepseek-ai/deepseek-v4-flash', 0.098, 0.197],
  ['nvidia', 'deepseek-ai/deepseek-v4-pro', 0.435, 0.87],
  ['nvidia', 'google/gemma-4-31b-it', 0.12, 0.37],
  ['nvidia', 'meta/llama-3.1-70b-instruct', 0.40, 0.40],
  ['nvidia', 'meta/llama-3.3-70b-instruct', 0.10, 0.32],
  ['nvidia', 'meta/llama-4-maverick-17b-128e-instruct', 0.15, 0.60],
  ['nvidia', 'minimaxai/minimax-m2.7', 0.279, 1.20],
  ['nvidia', 'mistralai/mistral-large-3-675b-instruct-2512', 0.50, 1.50],
  ['nvidia', 'moonshotai/kimi-k2.6', 0.684, 3.42],
  ['nvidia', 'nvidia/nemotron-3-nano-30b-a3b', 0.05, 0.20],
  ['nvidia', 'nvidia/nemotron-3-super-120b-a12b', 0.09, 0.45],
  ['nvidia', 'qwen/qwen3-coder-480b-a35b-instruct', 0.22, 1.80],
  ['nvidia', 'z-ai/glm-5.1', 0.98, 3.08],

  // Ollama (local models priced at their cloud-API equivalents β€” that's
  // what running them elsewhere would cost)
  ['ollama', 'cogito-2.1:671b', 1.25, 1.25],
  ['ollama', 'deepseek-v3.2', 0.229, 0.343],
  ['ollama', 'devstral-2:123b', 0.40, 2.00],
  ['ollama', 'gemma4:31b', 0.12, 0.37],
  ['ollama', 'glm-4.7', 0.40, 1.75],
  ['ollama', 'gpt-oss:120b', 0.039, 0.18],
  ['ollama', 'gpt-oss:20b', 0.029, 0.14],
  ['ollama', 'kimi-k2-thinking', 0.60, 2.50],
  ['ollama', 'mistral-large-3:675b', 0.50, 1.50],
  ['ollama', 'qwen3-coder-next', 0.11, 0.80],
  ['ollama', 'qwen3-coder:480b', 0.22, 1.80],

  // OpenCode Zen (big-pickle is stealth β€” no equivalent; V24 rows priced at
  // the OpenRouter paid variants, snapshot 2026-06-07)
  ['opencode', 'big-pickle', null, null],
  ['opencode', 'deepseek-v4-flash-free', 0.098, 0.197],
  ['opencode', 'mimo-v2.5-free', 0.14, 0.28],
  ['opencode', 'minimax-m3-free', 0.30, 1.20],
  ['opencode', 'nemotron-3-super-free', 0.09, 0.45],
  ['opencode', 'nemotron-3-ultra-free', 0.50, 2.50],

  // OpenRouter :free pools (priced at the same model's paid variant)
  // V23 additions snapshot the OpenRouter pricing API on 2026-06-07.
  ['openrouter', 'cognitivecomputations/dolphin-mistral-24b-venice-edition:free', null, null], // free-only route
  ['openrouter', 'google/gemma-4-26b-a4b-it:free', 0.06, 0.33],
  ['openrouter', 'google/gemma-4-31b-it:free', 0.12, 0.37],
  ['openrouter', 'meta-llama/llama-3.2-3b-instruct:free', 0.05, 0.34],
  ['openrouter', 'moonshotai/kimi-k2.6:free', 0.684, 3.42],
  ['openrouter', 'nvidia/nemotron-3-ultra-550b-a55b:free', 0.50, 2.50],
  ['openrouter', 'nvidia/nemotron-nano-12b-v2-vl:free', null, null], // no paid variant listed
  // LFM 2.5 1.2B has no paid listing; tiny-model estimate
  ['openrouter', 'liquid/lfm-2.5-1.2b-instruct:free', 0.01, 0.04],
  ['openrouter', 'liquid/lfm-2.5-1.2b-thinking:free', 0.01, 0.04],
  ['openrouter', 'meta-llama/llama-3.3-70b-instruct:free', 0.10, 0.32],
  ['openrouter', 'nousresearch/hermes-3-llama-3.1-405b:free', 1.00, 1.00],
  ['openrouter', 'nvidia/nemotron-3-nano-30b-a3b:free', 0.05, 0.20],
  ['openrouter', 'nvidia/nemotron-3-nano-omni-30b-a3b-reasoning:free', 0.05, 0.20],
  ['openrouter', 'nvidia/nemotron-3-super-120b-a12b:free', 0.09, 0.45],
  ['openrouter', 'nvidia/nemotron-nano-9b-v2:free', 0.04, 0.16],
  ['openrouter', 'openai/gpt-oss-120b:free', 0.039, 0.18],
  ['openrouter', 'openai/gpt-oss-20b:free', 0.029, 0.14],
  ['openrouter', 'openrouter/owl-alpha', null, null], // stealth
  ['openrouter', 'poolside/laguna-m.1:free', null, null],
  ['openrouter', 'poolside/laguna-xs.2:free', null, null],
  ['openrouter', 'qwen/qwen3-coder:free', 0.22, 1.80],
  ['openrouter', 'qwen/qwen3-next-80b-a3b-instruct:free', 0.09, 1.10],
  ['openrouter', 'z-ai/glm-4.5-air:free', 0.125, 0.85],
  // legacy ids
  ['openrouter', 'deepseek/deepseek-v3.1:free', 0.21, 0.79],
  ['openrouter', 'moonshotai/kimi-k2:free', 0.57, 2.30],

  // Pollinations (serves gpt-oss-20b)
  ['pollinations', 'openai-fast', 0.029, 0.14],

  // Reka (live /v1/models pricing, 2026-06-17)
  ['reka', 'reka-flash-3', 0.10, 0.20],
  ['reka', 'reka-edge-2603', 0.10, 0.10],

  // SambaNova rows were removed in V23 (platform dropped β€” free tier retired).

  // Zhipu (4.5-flash estimated at the 4.7-flash rate β€” no paid 4.5-flash;
  // 4.6v-flash priced at OpenRouter's paid z-ai/glm-4.6v)
  ['zhipu', 'glm-4.5-flash', 0.06, 0.40],
  ['zhipu', 'glm-4.6v-flash', 0.30, 0.90],
  ['zhipu', 'glm-4.7-flash', 0.06, 0.40],
];

/** Fallback $/M for models with no mapping (custom endpoints, stealth). */
export const FALLBACK_INPUT_PER_M = 0.20;
export const FALLBACK_OUTPUT_PER_M = 0.80;

/**
 * Adds the pricing columns (idempotent) and refreshes prices for every
 * known model. Runs on every boot β€” it's ~100 UPDATEs in one transaction
 * and keeps prices current when this map is updated in a release.
 */
export function applyModelPricing(db: Database.Database): void {
  const columns = db.prepare('PRAGMA table_info(models)').all() as { name: string }[];
  if (!columns.some(c => c.name === 'paid_input_per_m')) {
    db.prepare('ALTER TABLE models ADD COLUMN paid_input_per_m REAL').run();
  }
  if (!columns.some(c => c.name === 'paid_output_per_m')) {
    db.prepare('ALTER TABLE models ADD COLUMN paid_output_per_m REAL').run();
  }

  const update = db.prepare(`
    UPDATE models SET paid_input_per_m = ?, paid_output_per_m = ?
    WHERE platform = ? AND model_id = ?
  `);
  const applyAll = db.transaction(() => {
    for (const [platform, modelId, input, output] of MODEL_PRICING) {
      update.run(input, output, platform, modelId);
    }
  });
  applyAll();
}