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 // ---- Kimi / Kimi Code ----
96 {
97 Provider: "kimi", ID: "kimi-for-coding", DisplayName: "Kimi-k2.6",
98 ContextWindow: 262144, MaxOutput: 32000, Reasoning: true,
99 // Kimi Coding's public model metadata currently reports zero-priced
100 // usage for this endpoint; keep the cost meter explicit instead of
101 // relying on the struct's zero defaults.
102 PriceInput: 0, PriceOutput: 0, PriceCacheRead: 0, PriceCacheWrite: 0,
103 BaseURL: "https://api.kimi.com/coding/v1",
104 },
105
106 // ---- OpenAI / GPT-5 family ----
107 {
108 Provider: "openai", ID: "gpt-5", DisplayName: "GPT-5",
109 ContextWindow: 400000, MaxOutput: 128000, Reasoning: true,
110 PriceInput: 1.25, PriceOutput: 10.00, PriceCacheRead: 0.125,
111 },
112 {
113 Provider: "openai", ID: "gpt-5-mini", DisplayName: "GPT-5 mini",
114 ContextWindow: 400000, MaxOutput: 128000, Reasoning: true,
115 PriceInput: 0.25, PriceOutput: 2.00, PriceCacheRead: 0.025,
116 },
117 {
118 Provider: "openai", ID: "gpt-5-nano", DisplayName: "GPT-5 nano",
119 ContextWindow: 400000, MaxOutput: 128000, Reasoning: true,
120 PriceInput: 0.05, PriceOutput: 0.40, PriceCacheRead: 0.005,
121 },
122
123 // ---- OpenAI / GPT-4.1 family ----
124 {
125 Provider: "openai", ID: "gpt-4.1", DisplayName: "GPT-4.1",
126 ContextWindow: 1047576, MaxOutput: 32768, Reasoning: false,
127 PriceInput: 2.00, PriceOutput: 8.00, PriceCacheRead: 0.50,
128 },
129 {
130 Provider: "openai", ID: "gpt-4.1-mini", DisplayName: "GPT-4.1 mini",
131 ContextWindow: 1047576, MaxOutput: 32768, Reasoning: false,
132 PriceInput: 0.40, PriceOutput: 1.60, PriceCacheRead: 0.10,
133 },
134 {
135 Provider: "openai", ID: "gpt-4.1-nano", DisplayName: "GPT-4.1 nano",
136 ContextWindow: 1047576, MaxOutput: 32768, Reasoning: false,
137 PriceInput: 0.10, PriceOutput: 0.40, PriceCacheRead: 0.03,
138 },
139
140 // ---- OpenAI / GPT-4o family ----
141 {
142 Provider: "openai", ID: "gpt-4o", DisplayName: "GPT-4o",
143 ContextWindow: 128000, MaxOutput: 16384, Reasoning: false,
144 PriceInput: 2.50, PriceOutput: 10.00, PriceCacheRead: 1.25,
145 },
146 {
147 Provider: "openai", ID: "gpt-4o-mini", DisplayName: "GPT-4o mini",
148 ContextWindow: 128000, MaxOutput: 16384, Reasoning: false,
149 PriceInput: 0.15, PriceOutput: 0.60, PriceCacheRead: 0.08,
150 },
151
152 // ---- OpenAI / reasoning models ----
153 {
154 Provider: "openai", ID: "o4-mini", DisplayName: "o4-mini",
155 ContextWindow: 200000, MaxOutput: 100000, Reasoning: true,
156 PriceInput: 1.10, PriceOutput: 4.40, PriceCacheRead: 0.275,
157 },
158 {
159 Provider: "openai", ID: "o3", DisplayName: "o3",
160 ContextWindow: 200000, MaxOutput: 100000, Reasoning: true,
161 PriceInput: 2.00, PriceOutput: 8.00, PriceCacheRead: 0.50,
162 },
163 {
164 Provider: "openai", ID: "o3-mini", DisplayName: "o3-mini",
165 ContextWindow: 200000, MaxOutput: 100000, Reasoning: true,
166 PriceInput: 1.10, PriceOutput: 4.40, PriceCacheRead: 0.55,
167 },
168 {
169 Provider: "openai", ID: "o1", DisplayName: "o1",
170 ContextWindow: 200000, MaxOutput: 100000, Reasoning: true,
171 PriceInput: 15.00, PriceOutput: 60.00, PriceCacheRead: 7.50,
172 },
173
174 // ---- Google / Gemini ----
175 {
176 Provider: "google", ID: "gemini-2.5-pro", DisplayName: "Gemini 2.5 Pro",
177 ContextWindow: 1_048_576, MaxOutput: 65536, Reasoning: true,
178 PriceInput: 1.25, PriceOutput: 10.00, PriceCacheRead: 0.31, PriceCacheWrite: 0,
179 },
180 {
181 Provider: "google", ID: "gemini-2.5-flash", DisplayName: "Gemini 2.5 Flash",
182 ContextWindow: 1_048_576, MaxOutput: 65536, Reasoning: true,
183 PriceInput: 0.30, PriceOutput: 2.50, PriceCacheRead: 0.075, PriceCacheWrite: 0,
184 },
185 {
186 Provider: "google", ID: "gemini-2.5-flash-lite", DisplayName: "Gemini 2.5 Flash-Lite",
187 ContextWindow: 1_048_576, MaxOutput: 65536, Reasoning: true,
188 PriceInput: 0.10, PriceOutput: 0.40, PriceCacheRead: 0.025, PriceCacheWrite: 0,
189 },
190 {
191 Provider: "google", ID: "gemini-2.0-flash", DisplayName: "Gemini 2.0 Flash",
192 ContextWindow: 1_048_576, MaxOutput: 8192, Reasoning: false,
193 PriceInput: 0.10, PriceOutput: 0.40, PriceCacheRead: 0.025, PriceCacheWrite: 0,
194 },
195 {
196 Provider: "google", ID: "gemini-2.0-flash-lite", DisplayName: "Gemini 2.0 Flash-Lite",
197 ContextWindow: 1_048_576, MaxOutput: 8192, Reasoning: false,
198 PriceInput: 0.075, PriceOutput: 0.30, PriceCacheRead: 0, PriceCacheWrite: 0,
199 },
200
201 // ---- Speculative: Anthropic ----
202 {
203 Provider: "anthropic", ID: "claude-opus-4-5", DisplayName: "Claude Opus 4.5",
204 // 200k ctx / 64k maxOutput per Anthropic's published sizing
205 // for the opus-4-5 family; the 1M context is a 4.6+ thing.
206 ContextWindow: 200000, MaxOutput: 64000, Reasoning: true,
207 PriceInput: 5.00, PriceOutput: 25.00, PriceCacheRead: 0.50, PriceCacheWrite: 6.25,
208 Speculative: true,
209 },
210 {
211 Provider: "anthropic", ID: "claude-opus-4-6", DisplayName: "Claude Opus 4.6",
212 ContextWindow: 1000000, MaxOutput: 128000, Reasoning: true,
213 PriceInput: 5.00, PriceOutput: 25.00, PriceCacheRead: 0.50, PriceCacheWrite: 6.25,
214 Speculative: true,
215 },
216 {
217 Provider: "anthropic", ID: "claude-opus-4-7", DisplayName: "Claude Opus 4.7",
218 ContextWindow: 1000000, MaxOutput: 128000, Reasoning: true,
219 PriceInput: 5.00, PriceOutput: 25.00, PriceCacheRead: 0.50, PriceCacheWrite: 6.25,
220 Speculative: true,
221 },
222 {
223 Provider: "anthropic", ID: "claude-sonnet-4-6", DisplayName: "Claude Sonnet 4.6",
224 ContextWindow: 1000000, MaxOutput: 64000, Reasoning: true,
225 PriceInput: 3.00, PriceOutput: 15.00, PriceCacheRead: 0.30, PriceCacheWrite: 3.75,
226 Speculative: true,
227 },
228
229 // ---- Speculative: OpenAI ----
230 // Context windows on the OpenAI gpt-5.x family differ by route:
231 // the direct API advertises 400k, the ChatGPT Codex OAuth backend
232 // caps at 272k. zot serves both auth modes from one catalog row
233 // per id, so we pin to the smaller number to keep the context-usage
234 // meter honest under subscription auth. Users on the direct API
235 // simply see a conservative headroom estimate.
236 {
237 Provider: "openai", ID: "gpt-5.1", DisplayName: "GPT-5.1",
238 ContextWindow: 272000, MaxOutput: 128000, Reasoning: true,
239 PriceInput: 1.25, PriceOutput: 10.00, PriceCacheRead: 0.125,
240 Speculative: true,
241 },
242 {
243 Provider: "openai", ID: "gpt-5.2", DisplayName: "GPT-5.2",
244 ContextWindow: 272000, MaxOutput: 128000, Reasoning: true,
245 PriceInput: 1.75, PriceOutput: 14.00, PriceCacheRead: 0.175,
246 Speculative: true,
247 },
248 {
249 Provider: "openai", ID: "gpt-5.3", DisplayName: "GPT-5.3",
250 ContextWindow: 272000, MaxOutput: 128000, Reasoning: true,
251 PriceInput: 1.75, PriceOutput: 14.00, PriceCacheRead: 0.175,
252 Speculative: true,
253 },
254 {
255 Provider: "openai", ID: "gpt-5.4", DisplayName: "GPT-5.4",
256 // ContextWindow: 272k across every route we support (OpenAI
257 // direct API and the ChatGPT Codex OAuth backend).
258 ContextWindow: 272000, MaxOutput: 128000, Reasoning: true,
259 PriceInput: 2.50, PriceOutput: 15.00, PriceCacheRead: 0.25,
260 Speculative: true,
261 },
262 {
263 Provider: "openai", ID: "gpt-5.4-mini", DisplayName: "GPT-5.4 mini",
264 // ContextWindow: 400k on the OpenAI direct API, 272k on the
265 // ChatGPT Codex OAuth backend. We pin to the smaller Codex
266 // cap so the context-usage meter is honest under subscription
267 // auth; direct-API users simply see a conservative headroom
268 // estimate rather than an inflated one.
269 ContextWindow: 272000, MaxOutput: 128000, Reasoning: true,
270 PriceInput: 0.75, PriceOutput: 4.50, PriceCacheRead: 0.075,
271 Speculative: true,
272 },
273 {
274 Provider: "openai", ID: "gpt-5.5", DisplayName: "GPT-5.5",
275 ContextWindow: 400000, MaxOutput: 128000, Reasoning: true,
276 PriceInput: 2.50, PriceOutput: 15.00, PriceCacheRead: 0.25,
277 Speculative: true,
278 },
279 {
280 Provider: "openai", ID: "gpt-5.5-mini", DisplayName: "GPT-5.5 mini",
281 ContextWindow: 400000, MaxOutput: 128000, Reasoning: true,
282 PriceInput: 0.75, PriceOutput: 4.50, PriceCacheRead: 0.075,
283 Speculative: true,
284 },
285}
286
287// DefaultModel is used when the user does not specify one.
288var DefaultModel = Catalog[0] // claude-sonnet-4-5
289
290// ----- active (merged) catalog -----
291//
292// Callers should use Active() / FindModel / ModelsForProvider for
293// lookups. They return the baked-in Catalog merged with any live
294// models loaded via SetLiveModels.
295
296var (
297 activeMu sync.RWMutex
298 active []Model = Catalog // default: just the static catalog
299)
300
301// SetLiveModels replaces the "live" overlay used by the active catalog.
302// Typically called after a successful /v1/models discovery or on load
303// from the on-disk cache.
304func SetLiveModels(live []Model) {
305 activeMu.Lock()
306 defer activeMu.Unlock()
307 if len(live) == 0 {
308 active = Catalog
309 return
310 }
311 active = MergeCatalog(live)
312}
313
314// Active returns the current merged catalog.
315func Active() []Model {
316 activeMu.RLock()
317 defer activeMu.RUnlock()
318 out := make([]Model, len(active))
319 copy(out, active)
320 return out
321}
322
323// FindModel returns a Model by id, optionally constrained by provider.
324// If provider is empty, the first matching id is returned. Looks up
325// against the merged active catalog.
326func FindModel(provider, id string) (Model, error) {
327 for _, m := range Active() {
328 if m.ID == id && (provider == "" || m.Provider == provider) {
329 return m, nil
330 }
331 }
332 return Model{}, fmt.Errorf("unknown model %q (provider=%q)", id, provider)
333}
334
335// ModelsForProvider returns all models for the given provider, from the
336// merged active catalog.
337func ModelsForProvider(provider string) []Model {
338 var out []Model
339 for _, m := range Active() {
340 if m.Provider == provider {
341 out = append(out, m)
342 }
343 }
344 return out
345}
346
347// ComputeCost returns the USD cost for the given usage on model m.
348func ComputeCost(m Model, u Usage) float64 {
349 const per = 1_000_000.0
350 return float64(u.InputTokens)*m.PriceInput/per +
351 float64(u.OutputTokens)*m.PriceOutput/per +
352 float64(u.CacheReadTokens)*m.PriceCacheRead/per +
353 float64(u.CacheWriteTokens)*m.PriceCacheWrite/per
354}