1package provider
2
3import (
4 "fmt"
5 "sync"
6)
7
8// Model describes a single LLM we know about.
9type Model struct {
10 Provider string // "anthropic" | "openai"
11 ID string // API id
12 DisplayName string
13 ContextWindow int
14 MaxOutput int
15 Reasoning bool // supports reasoning/thinking
16
17 // Prices are USD per 1M tokens.
18 PriceInput float64
19 PriceOutput float64
20 PriceCacheRead float64
21 PriceCacheWrite float64
22
23 // Speculative marks models whose ids are known from the upstream
24 // vendor's CLI but not yet live on their public API. They'll 404
25 // today but start working the moment the provider flips the switch.
26 Speculative bool
27
28 // BaseURL overrides the provider's default API endpoint for this
29 // model. Optional; when empty the provider's default (or the
30 // --base-url flag) is used. Useful for local models served by
31 // ollama, vLLM, LM Studio, etc.
32 BaseURL string
33
34 // Source is where this model entry came from: "catalog" (baked in),
35 // "live" (discovered via /v1/models), or "cache" (loaded from the
36 // on-disk cache). Informational.
37 Source string
38}
39
40// Catalog is the hardcoded, read-only list of supported models.
41// Prices are USD per 1M tokens. The list is curated to what zot's
42// clients (Anthropic Messages + OpenAI Chat Completions) can actually
43// talk to; models that are only reachable through the OpenAI Responses
44// API (o1-pro, o3-pro, gpt-5-pro) are omitted.
45var Catalog = []Model{
46 // ---- Anthropic / Claude 4.x ----
47 {
48 Provider: "anthropic", ID: "claude-sonnet-4-5", DisplayName: "Claude Sonnet 4.5",
49 ContextWindow: 200000, MaxOutput: 64000, Reasoning: true,
50 PriceInput: 3.00, PriceOutput: 15.00, PriceCacheRead: 0.30, PriceCacheWrite: 3.75,
51 },
52 {
53 Provider: "anthropic", ID: "claude-opus-4-1", DisplayName: "Claude Opus 4.1",
54 ContextWindow: 200000, MaxOutput: 32000, Reasoning: true,
55 PriceInput: 15.00, PriceOutput: 75.00, PriceCacheRead: 1.50, PriceCacheWrite: 18.75,
56 },
57 {
58 Provider: "anthropic", ID: "claude-opus-4-0", DisplayName: "Claude Opus 4",
59 ContextWindow: 200000, MaxOutput: 32000, Reasoning: true,
60 PriceInput: 15.00, PriceOutput: 75.00, PriceCacheRead: 1.50, PriceCacheWrite: 18.75,
61 },
62 {
63 Provider: "anthropic", ID: "claude-sonnet-4-0", DisplayName: "Claude Sonnet 4",
64 ContextWindow: 200000, MaxOutput: 64000, Reasoning: true,
65 PriceInput: 3.00, PriceOutput: 15.00, PriceCacheRead: 0.30, PriceCacheWrite: 3.75,
66 },
67 {
68 Provider: "anthropic", ID: "claude-haiku-4-5", DisplayName: "Claude Haiku 4.5",
69 ContextWindow: 200000, MaxOutput: 64000, Reasoning: true,
70 PriceInput: 1.00, PriceOutput: 5.00, PriceCacheRead: 0.10, PriceCacheWrite: 1.25,
71 },
72
73 // ---- Anthropic / Claude 3.x (legacy) ----
74 {
75 Provider: "anthropic", ID: "claude-3-7-sonnet-20250219", DisplayName: "Claude Sonnet 3.7",
76 ContextWindow: 200000, MaxOutput: 64000, Reasoning: true,
77 PriceInput: 3.00, PriceOutput: 15.00, PriceCacheRead: 0.30, PriceCacheWrite: 3.75,
78 },
79 {
80 Provider: "anthropic", ID: "claude-3-5-sonnet-20241022", DisplayName: "Claude Sonnet 3.5 v2",
81 ContextWindow: 200000, MaxOutput: 8192, Reasoning: false,
82 PriceInput: 3.00, PriceOutput: 15.00, PriceCacheRead: 0.30, PriceCacheWrite: 3.75,
83 },
84 {
85 Provider: "anthropic", ID: "claude-3-5-haiku-latest", DisplayName: "Claude Haiku 3.5",
86 ContextWindow: 200000, MaxOutput: 8192, Reasoning: false,
87 PriceInput: 0.80, PriceOutput: 4.00, PriceCacheRead: 0.08, PriceCacheWrite: 1.00,
88 },
89 {
90 Provider: "anthropic", ID: "claude-3-opus-20240229", DisplayName: "Claude Opus 3",
91 ContextWindow: 200000, MaxOutput: 4096, Reasoning: false,
92 PriceInput: 15.00, PriceOutput: 75.00, PriceCacheRead: 1.50, PriceCacheWrite: 18.75,
93 },
94
95 // ---- DeepSeek ----
96 // The current public DeepSeek API exposes the V4 family on
97 // api.deepseek.com/v1. Pro is the flagship reasoning model;
98 // Flash is the cheaper/faster sibling. Both accept image inputs
99 // (multimodal parts: image_url) in addition to text.
100 {
101 Provider: "deepseek", ID: "deepseek-v4-pro", DisplayName: "DeepSeek V4 Pro",
102 ContextWindow: 128000, MaxOutput: 8192, Reasoning: true,
103 PriceInput: 0.55, PriceOutput: 2.19, PriceCacheRead: 0.14,
104 BaseURL: "https://api.deepseek.com/v1",
105 },
106 {
107 Provider: "deepseek", ID: "deepseek-v4-flash", DisplayName: "DeepSeek V4 Flash",
108 ContextWindow: 128000, MaxOutput: 8192, Reasoning: false,
109 PriceInput: 0.27, PriceOutput: 1.10, PriceCacheRead: 0.07,
110 BaseURL: "https://api.deepseek.com/v1",
111 },
112
113 // ---- Kimi / Kimi Code ----
114 // Anthropic-messages on https://api.kimi.com/coding (no /v1 suffix;
115 // the Anthropic client appends /v1/messages itself).
116 {
117 Provider: "kimi", ID: "kimi-for-coding", DisplayName: "Kimi-k2.6",
118 ContextWindow: 262144, MaxOutput: 32000, Reasoning: true,
119 PriceInput: 0, PriceOutput: 0, PriceCacheRead: 0, PriceCacheWrite: 0,
120 BaseURL: "https://api.kimi.com/coding",
121 },
122
123 // ---- OpenAI / GPT-5 family ----
124 {
125 Provider: "openai", ID: "gpt-5", DisplayName: "GPT-5",
126 ContextWindow: 400000, MaxOutput: 128000, Reasoning: true,
127 PriceInput: 1.25, PriceOutput: 10.00, PriceCacheRead: 0.125,
128 },
129 {
130 Provider: "openai", ID: "gpt-5-mini", DisplayName: "GPT-5 mini",
131 ContextWindow: 400000, MaxOutput: 128000, Reasoning: true,
132 PriceInput: 0.25, PriceOutput: 2.00, PriceCacheRead: 0.025,
133 },
134 {
135 Provider: "openai", ID: "gpt-5-nano", DisplayName: "GPT-5 nano",
136 ContextWindow: 400000, MaxOutput: 128000, Reasoning: true,
137 PriceInput: 0.05, PriceOutput: 0.40, PriceCacheRead: 0.005,
138 },
139
140 // ---- OpenAI / GPT-4.1 family ----
141 {
142 Provider: "openai", ID: "gpt-4.1", DisplayName: "GPT-4.1",
143 ContextWindow: 1047576, MaxOutput: 32768, Reasoning: false,
144 PriceInput: 2.00, PriceOutput: 8.00, PriceCacheRead: 0.50,
145 },
146 {
147 Provider: "openai", ID: "gpt-4.1-mini", DisplayName: "GPT-4.1 mini",
148 ContextWindow: 1047576, MaxOutput: 32768, Reasoning: false,
149 PriceInput: 0.40, PriceOutput: 1.60, PriceCacheRead: 0.10,
150 },
151 {
152 Provider: "openai", ID: "gpt-4.1-nano", DisplayName: "GPT-4.1 nano",
153 ContextWindow: 1047576, MaxOutput: 32768, Reasoning: false,
154 PriceInput: 0.10, PriceOutput: 0.40, PriceCacheRead: 0.03,
155 },
156
157 // ---- OpenAI / GPT-4o family ----
158 {
159 Provider: "openai", ID: "gpt-4o", DisplayName: "GPT-4o",
160 ContextWindow: 128000, MaxOutput: 16384, Reasoning: false,
161 PriceInput: 2.50, PriceOutput: 10.00, PriceCacheRead: 1.25,
162 },
163 {
164 Provider: "openai", ID: "gpt-4o-mini", DisplayName: "GPT-4o mini",
165 ContextWindow: 128000, MaxOutput: 16384, Reasoning: false,
166 PriceInput: 0.15, PriceOutput: 0.60, PriceCacheRead: 0.08,
167 },
168
169 // ---- OpenAI / reasoning models ----
170 {
171 Provider: "openai", ID: "o4-mini", DisplayName: "o4-mini",
172 ContextWindow: 200000, MaxOutput: 100000, Reasoning: true,
173 PriceInput: 1.10, PriceOutput: 4.40, PriceCacheRead: 0.275,
174 },
175 {
176 Provider: "openai", ID: "o3", DisplayName: "o3",
177 ContextWindow: 200000, MaxOutput: 100000, Reasoning: true,
178 PriceInput: 2.00, PriceOutput: 8.00, PriceCacheRead: 0.50,
179 },
180 {
181 Provider: "openai", ID: "o3-mini", DisplayName: "o3-mini",
182 ContextWindow: 200000, MaxOutput: 100000, Reasoning: true,
183 PriceInput: 1.10, PriceOutput: 4.40, PriceCacheRead: 0.55,
184 },
185 {
186 Provider: "openai", ID: "o1", DisplayName: "o1",
187 ContextWindow: 200000, MaxOutput: 100000, Reasoning: true,
188 PriceInput: 15.00, PriceOutput: 60.00, PriceCacheRead: 7.50,
189 },
190
191 // ---- Google / Gemini ----
192 {
193 Provider: "google", ID: "gemini-2.5-pro", DisplayName: "Gemini 2.5 Pro",
194 ContextWindow: 1_048_576, MaxOutput: 65536, Reasoning: true,
195 PriceInput: 1.25, PriceOutput: 10.00, PriceCacheRead: 0.31, PriceCacheWrite: 0,
196 },
197 {
198 Provider: "google", ID: "gemini-2.5-flash", DisplayName: "Gemini 2.5 Flash",
199 ContextWindow: 1_048_576, MaxOutput: 65536, Reasoning: true,
200 PriceInput: 0.30, PriceOutput: 2.50, PriceCacheRead: 0.075, PriceCacheWrite: 0,
201 },
202 {
203 Provider: "google", ID: "gemini-2.5-flash-lite", DisplayName: "Gemini 2.5 Flash-Lite",
204 ContextWindow: 1_048_576, MaxOutput: 65536, Reasoning: true,
205 PriceInput: 0.10, PriceOutput: 0.40, PriceCacheRead: 0.025, PriceCacheWrite: 0,
206 },
207 {
208 Provider: "google", ID: "gemini-2.0-flash", DisplayName: "Gemini 2.0 Flash",
209 ContextWindow: 1_048_576, MaxOutput: 8192, Reasoning: false,
210 PriceInput: 0.10, PriceOutput: 0.40, PriceCacheRead: 0.025, PriceCacheWrite: 0,
211 },
212 {
213 Provider: "google", ID: "gemini-2.0-flash-lite", DisplayName: "Gemini 2.0 Flash-Lite",
214 ContextWindow: 1_048_576, MaxOutput: 8192, Reasoning: false,
215 PriceInput: 0.075, PriceOutput: 0.30, PriceCacheRead: 0, PriceCacheWrite: 0,
216 },
217
218 // ---- Speculative: Anthropic ----
219 {
220 Provider: "anthropic", ID: "claude-opus-4-5", DisplayName: "Claude Opus 4.5",
221 // 200k ctx / 64k maxOutput per Anthropic's published sizing
222 // for the opus-4-5 family; the 1M context is a 4.6+ thing.
223 ContextWindow: 200000, MaxOutput: 64000, Reasoning: true,
224 PriceInput: 5.00, PriceOutput: 25.00, PriceCacheRead: 0.50, PriceCacheWrite: 6.25,
225 Speculative: true,
226 },
227 {
228 Provider: "anthropic", ID: "claude-opus-4-6", DisplayName: "Claude Opus 4.6",
229 ContextWindow: 1000000, MaxOutput: 128000, Reasoning: true,
230 PriceInput: 5.00, PriceOutput: 25.00, PriceCacheRead: 0.50, PriceCacheWrite: 6.25,
231 Speculative: true,
232 },
233 {
234 Provider: "anthropic", ID: "claude-opus-4-7", DisplayName: "Claude Opus 4.7",
235 ContextWindow: 1000000, MaxOutput: 128000, Reasoning: true,
236 PriceInput: 5.00, PriceOutput: 25.00, PriceCacheRead: 0.50, PriceCacheWrite: 6.25,
237 Speculative: true,
238 },
239 {
240 Provider: "anthropic", ID: "claude-sonnet-4-6", DisplayName: "Claude Sonnet 4.6",
241 ContextWindow: 1000000, MaxOutput: 64000, Reasoning: true,
242 PriceInput: 3.00, PriceOutput: 15.00, PriceCacheRead: 0.30, PriceCacheWrite: 3.75,
243 Speculative: true,
244 },
245
246 // ---- Speculative: OpenAI ----
247 // Public OpenAI API route. The ChatGPT/Codex subscription route is
248 // represented separately below as provider "openai-codex".
249 {
250 Provider: "openai", ID: "gpt-5.1", DisplayName: "GPT-5.1",
251 ContextWindow: 272000, MaxOutput: 128000, Reasoning: true,
252 PriceInput: 1.25, PriceOutput: 10.00, PriceCacheRead: 0.125,
253 Speculative: true,
254 },
255 {
256 Provider: "openai", ID: "gpt-5.2", DisplayName: "GPT-5.2",
257 ContextWindow: 272000, MaxOutput: 128000, Reasoning: true,
258 PriceInput: 1.75, PriceOutput: 14.00, PriceCacheRead: 0.175,
259 Speculative: true,
260 },
261 {
262 Provider: "openai", ID: "gpt-5.3", DisplayName: "GPT-5.3",
263 ContextWindow: 272000, MaxOutput: 128000, Reasoning: true,
264 PriceInput: 1.75, PriceOutput: 14.00, PriceCacheRead: 0.175,
265 Speculative: true,
266 },
267 {
268 Provider: "openai", ID: "gpt-5.4", DisplayName: "GPT-5.4",
269 // ContextWindow: 272k across every route we support (OpenAI
270 // direct API and the ChatGPT Codex OAuth backend).
271 ContextWindow: 272000, MaxOutput: 128000, Reasoning: true,
272 PriceInput: 2.50, PriceOutput: 15.00, PriceCacheRead: 0.25,
273 Speculative: true,
274 },
275 {
276 Provider: "openai", ID: "gpt-5.4-mini", DisplayName: "GPT-5.4 mini",
277 ContextWindow: 400000, MaxOutput: 128000, Reasoning: true,
278 PriceInput: 0.75, PriceOutput: 4.50, PriceCacheRead: 0.075,
279 Speculative: true,
280 },
281 {
282 Provider: "openai", ID: "gpt-5.5", DisplayName: "GPT-5.5",
283 ContextWindow: 400000, MaxOutput: 128000, Reasoning: true,
284 PriceInput: 2.50, PriceOutput: 15.00, PriceCacheRead: 0.25,
285 Speculative: true,
286 },
287 {
288 Provider: "openai", ID: "gpt-5.5-mini", DisplayName: "GPT-5.5 mini",
289 ContextWindow: 400000, MaxOutput: 128000, Reasoning: true,
290 PriceInput: 0.75, PriceOutput: 4.50, PriceCacheRead: 0.075,
291 Speculative: true,
292 },
293
294 // ---- OpenAI Codex / ChatGPT subscription backend ----
295 // Same model ids as the OpenAI family, but routed through the
296 // ChatGPT Codex OAuth backend rather than api.openai.com.
297 {
298 Provider: "openai-codex", ID: "gpt-5.2", DisplayName: "GPT-5.2 Codex",
299 ContextWindow: 272000, MaxOutput: 128000, Reasoning: true,
300 PriceInput: 1.75, PriceOutput: 14.00, PriceCacheRead: 0.175,
301 Speculative: true,
302 },
303 {
304 Provider: "openai-codex", ID: "gpt-5.3-codex", DisplayName: "GPT-5.3 Codex",
305 ContextWindow: 272000, MaxOutput: 128000, Reasoning: true,
306 PriceInput: 1.75, PriceOutput: 14.00, PriceCacheRead: 0.175,
307 Speculative: true,
308 },
309 {
310 Provider: "openai-codex", ID: "gpt-5.3-codex-spark", DisplayName: "GPT-5.3 Codex Spark",
311 ContextWindow: 272000, MaxOutput: 128000, Reasoning: true,
312 PriceInput: 1.75, PriceOutput: 14.00, PriceCacheRead: 0.175,
313 Speculative: true,
314 },
315 {
316 Provider: "openai-codex", ID: "gpt-5.4", DisplayName: "GPT-5.4 Codex",
317 ContextWindow: 272000, MaxOutput: 128000, Reasoning: true,
318 PriceInput: 2.50, PriceOutput: 15.00, PriceCacheRead: 0.25,
319 Speculative: true,
320 },
321 {
322 Provider: "openai-codex", ID: "gpt-5.4-mini", DisplayName: "GPT-5.4 mini Codex",
323 ContextWindow: 272000, MaxOutput: 128000, Reasoning: true,
324 PriceInput: 0.75, PriceOutput: 4.50, PriceCacheRead: 0.075,
325 Speculative: true,
326 },
327 {
328 Provider: "openai-codex", ID: "gpt-5.5", DisplayName: "GPT-5.5 Codex",
329 ContextWindow: 272000, MaxOutput: 128000, Reasoning: true,
330 PriceInput: 2.50, PriceOutput: 15.00, PriceCacheRead: 0.25,
331 Speculative: true,
332 },
333 {
334 Provider: "openai-codex", ID: "gpt-5.5-mini", DisplayName: "GPT-5.5 mini Codex",
335 ContextWindow: 272000, MaxOutput: 128000, Reasoning: true,
336 PriceInput: 0.75, PriceOutput: 4.50, PriceCacheRead: 0.075,
337 Speculative: true,
338 },
339}
340
341// DefaultModel is used when the user does not specify one.
342var DefaultModel = Catalog[0] // claude-sonnet-4-5
343
344// ----- active (merged) catalog -----
345//
346// Callers should use Active() / FindModel / ModelsForProvider for
347// lookups. They return the baked-in Catalog merged with any live
348// models loaded via SetLiveModels.
349
350var (
351 activeMu sync.RWMutex
352 active []Model = Catalog // default: just the static catalog
353)
354
355// SetLiveModels replaces the "live" overlay used by the active catalog.
356// Typically called after a successful /v1/models discovery or on load
357// from the on-disk cache.
358func SetLiveModels(live []Model) {
359 activeMu.Lock()
360 defer activeMu.Unlock()
361 if len(live) == 0 {
362 active = Catalog
363 return
364 }
365 active = MergeCatalog(live)
366}
367
368// Active returns the current merged catalog.
369func Active() []Model {
370 activeMu.RLock()
371 defer activeMu.RUnlock()
372 out := make([]Model, len(active))
373 copy(out, active)
374 return out
375}
376
377// FindModel returns a Model by id, optionally constrained by provider.
378// If provider is empty, the first matching id is returned. Looks up
379// against the merged active catalog.
380func FindModel(provider, id string) (Model, error) {
381 for _, m := range Active() {
382 if m.ID == id && (provider == "" || m.Provider == provider) {
383 return m, nil
384 }
385 }
386 return Model{}, fmt.Errorf("unknown model %q (provider=%q)", id, provider)
387}
388
389// ModelsForProvider returns all models for the given provider, from the
390// merged active catalog.
391func ModelsForProvider(provider string) []Model {
392 var out []Model
393 for _, m := range Active() {
394 if m.Provider == provider {
395 out = append(out, m)
396 }
397 }
398 return out
399}
400
401// ComputeCost returns the USD cost for the given usage on model m.
402func ComputeCost(m Model, u Usage) float64 {
403 const per = 1_000_000.0
404 return float64(u.InputTokens)*m.PriceInput/per +
405 float64(u.OutputTokens)*m.PriceOutput/per +
406 float64(u.CacheReadTokens)*m.PriceCacheRead/per +
407 float64(u.CacheWriteTokens)*m.PriceCacheWrite/per
408}