v0.3.53 356583d

provider_test.go RawHistoryFolder

1package provider
2
3import (
4	"context"
5	"math"
6	"net/http"
7	"net/http/httptest"
8	"strings"
9	"testing"
10)
11
12func TestSSEParse(t *testing.T) {
13	r := strings.NewReader("event: foo\ndata: {\"a\":1}\n\ndata: hello\ndata: world\n\n")
14	ch := make(chan sseEvent, 4)
15	go readSSE(r, ch)
16
17	e := <-ch
18	if e.Event != "foo" || e.Data != `{"a":1}` {
19		t.Fatalf("event 1: %+v", e)
20	}
21	e = <-ch
22	if e.Event != "" || e.Data != "hello\nworld" {
23		t.Fatalf("event 2: %+v", e)
24	}
25	if _, ok := <-ch; ok {
26		t.Fatalf("channel not closed")
27	}
28}
29
30func TestModelCatalog(t *testing.T) {
31	if len(Catalog) == 0 {
32		t.Fatal("empty catalog")
33	}
34	if _, err := FindModel("anthropic", "claude-sonnet-4-5"); err != nil {
35		t.Fatal(err)
36	}
37	if _, err := FindModel("openai", "gpt-5"); err != nil {
38		t.Fatal(err)
39	}
40	if _, err := FindModel("", "nope"); err == nil {
41		t.Fatal("expected error")
42	}
43}
44
45func TestVertexGeminiFlashCatalogLimits(t *testing.T) {
46	for _, id := range []string{"gemini-3.1-flash-lite", "gemini-3.5-flash"} {
47		m, err := FindModel("google-vertex", id)
48		if err != nil {
49			t.Fatal(err)
50		}
51		if m.ContextWindow != 1048576 || m.MaxOutput != 65535 || !m.Reasoning {
52			t.Errorf("%s metadata = %+v", id, m)
53		}
54	}
55}
56
57func TestComputeCost(t *testing.T) {
58	m, _ := FindModel("anthropic", "claude-sonnet-4-5")
59	cost := ComputeCost(m, Usage{InputTokens: 1_000_000, OutputTokens: 1_000_000})
60	want := m.PriceInput + m.PriceOutput
61	if cost != want {
62		t.Fatalf("cost=%v want=%v", cost, want)
63	}
64}
65
66func TestComputeCostInputTier(t *testing.T) {
67	m := Model{
68		PriceInput: 1, PriceOutput: 2, PriceCacheRead: 0.1,
69		PriceTierInputTokens: 100,
70		PriceInputAbove:      3, PriceOutputAbove: 4, PriceCacheReadAbove: 0.2,
71	}
72	below := ComputeCost(m, Usage{InputTokens: 50, OutputTokens: 10, CacheReadTokens: 50})
73	wantBelow := (50.0*1 + 10*2 + 50*0.1) / 1_000_000
74	if math.Abs(below-wantBelow) > 1e-12 {
75		t.Fatalf("below-tier cost=%v want=%v", below, wantBelow)
76	}
77
78	above := ComputeCost(m, Usage{InputTokens: 51, OutputTokens: 10, CacheReadTokens: 50})
79	wantAbove := (51.0*3 + 10*4 + 50*0.2) / 1_000_000
80	if math.Abs(above-wantAbove) > 1e-12 {
81		t.Fatalf("above-tier cost=%v want=%v", above, wantAbove)
82	}
83}
84
85func TestAnthropicErrorStatus(t *testing.T) {
86	srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
87		w.WriteHeader(http.StatusUnauthorized)
88		_, _ = w.Write([]byte(`{"error":{"type":"auth","message":"bad key"}}`))
89	}))
90	defer srv.Close()
91
92	c := NewAnthropic("x", srv.URL)
93	_, err := c.Stream(context.Background(), Request{Model: "claude-sonnet-4-5"})
94	if err == nil || !strings.Contains(err.Error(), "401") {
95		t.Fatalf("want 401 err, got %v", err)
96	}
97}
98
99func TestOpenAIErrorStatus(t *testing.T) {
100	srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
101		w.WriteHeader(http.StatusBadRequest)
102		_, _ = w.Write([]byte(`{"error":{"message":"nope"}}`))
103	}))
104	defer srv.Close()
105
106	c := NewOpenAI("x", srv.URL)
107	_, err := c.Stream(context.Background(), Request{Model: "gpt-5"})
108	if err == nil || !strings.Contains(err.Error(), "400") {
109		t.Fatalf("want 400 err, got %v", err)
110	}
111}
112
113func TestMiniMaxM3CatalogAndRequest(t *testing.T) {
114	for _, provider := range []string{"minimax", "minimax-cn"} {
115		m, err := FindModel(provider, "MiniMax-M3")
116		if err != nil {
117			t.Fatal(err)
118		}
119		if m.ContextWindow != 1000000 || m.MaxOutput != 131072 || !m.Reasoning || !m.AdaptiveThinkingCompat {
120			t.Errorf("%s metadata = %+v", provider, m)
121		}
122		if m.PriceInput != 0.3 || m.PriceOutput != 1.2 || m.PriceCacheRead != 0.06 || m.PriceTierInputTokens != 512000 || m.PriceInputAbove != 0.6 || m.PriceOutputAbove != 2.4 || m.PriceCacheReadAbove != 0.12 {
123			t.Errorf("%s pricing = %+v", provider, m)
124		}
125	}
126
127	c := NewAnthropicCompat("minimax", "x", "https://api.minimax.io/anthropic").(*anthropicClient)
128	temp := float32(0.7)
129	wire, err := c.buildRequest(Request{
130		Model:       "MiniMax-M3",
131		Reasoning:   "high",
132		Temperature: &temp,
133		Messages:    []Message{{Role: RoleUser, Content: []Content{TextBlock{Text: "hi"}}}},
134	})
135	if err != nil {
136		t.Fatal(err)
137	}
138	if wire.Thinking == nil || wire.Thinking.Type != "adaptive" || wire.Thinking.BudgetTokens != 0 {
139		t.Fatalf("want adaptive thinking without a budget, got %+v", wire.Thinking)
140	}
141	if wire.OutputConfig != nil {
142		t.Fatalf("MiniMax-M3 must not send output_config, got %+v", wire.OutputConfig)
143	}
144	if wire.Temperature == nil || *wire.Temperature != temp {
145		t.Fatalf("MiniMax-M3 should keep temperature, got %v", wire.Temperature)
146	}
147}
148
149func TestAnthropicAdaptiveThinking(t *testing.T) {
150	c := NewAnthropic("x", "").(*anthropicClient)
151	temp := float32(0.7)
152
153	// Opus 5 -> adaptive thinking, effort set, no budget, no temperature.
154	wire, err := c.buildRequest(Request{
155		Model:       "claude-opus-5",
156		Reasoning:   "high",
157		Temperature: &temp,
158		Messages:    []Message{{Role: RoleUser, Content: []Content{TextBlock{Text: "hi"}}}},
159	})
160	if err != nil {
161		t.Fatal(err)
162	}
163	if wire.Thinking == nil || wire.Thinking.Type != "adaptive" {
164		t.Fatalf("want adaptive thinking, got %+v", wire.Thinking)
165	}
166	if wire.Thinking.BudgetTokens != 0 {
167		t.Fatalf("adaptive must not send budget_tokens, got %d", wire.Thinking.BudgetTokens)
168	}
169	if wire.OutputConfig == nil || wire.OutputConfig.Effort != "high" {
170		t.Fatalf("want effort=high, got %+v", wire.OutputConfig)
171	}
172	if wire.Temperature != nil {
173		t.Fatalf("adaptive must drop temperature, got %v", *wire.Temperature)
174	}
175
176	// maximum -> xhigh effort.
177	wire, err = c.buildRequest(Request{
178		Model:     "claude-opus-5",
179		Reasoning: "maximum",
180		Messages:  []Message{{Role: RoleUser, Content: []Content{TextBlock{Text: "hi"}}}},
181	})
182	if err != nil {
183		t.Fatal(err)
184	}
185	if wire.OutputConfig == nil || wire.OutputConfig.Effort != "xhigh" {
186		t.Fatalf("want effort=xhigh, got %+v", wire.OutputConfig)
187	}
188
189	// max is a separate native tier above xhigh on adaptive models.
190	wire, err = c.buildRequest(Request{
191		Model:     "claude-opus-5",
192		Reasoning: "max",
193		Messages:  []Message{{Role: RoleUser, Content: []Content{TextBlock{Text: "hi"}}}},
194	})
195	if err != nil {
196		t.Fatal(err)
197	}
198	if wire.OutputConfig == nil || wire.OutputConfig.Effort != "max" {
199		t.Fatalf("want effort=max, got %+v", wire.OutputConfig)
200	}
201
202	// Sonnet 5 -> adaptive thinking, effort set, no budget, no temperature.
203	wire, err = c.buildRequest(Request{
204		Model:       "claude-sonnet-5",
205		Reasoning:   "high",
206		Temperature: &temp,
207		Messages:    []Message{{Role: RoleUser, Content: []Content{TextBlock{Text: "hi"}}}},
208	})
209	if err != nil {
210		t.Fatal(err)
211	}
212	if wire.Thinking == nil || wire.Thinking.Type != "adaptive" {
213		t.Fatalf("want adaptive thinking for Sonnet 5, got %+v", wire.Thinking)
214	}
215	if wire.Thinking.BudgetTokens != 0 {
216		t.Fatalf("Sonnet 5 adaptive must not send budget_tokens, got %d", wire.Thinking.BudgetTokens)
217	}
218	if wire.OutputConfig == nil || wire.OutputConfig.Effort != "high" {
219		t.Fatalf("want Sonnet 5 effort=high, got %+v", wire.OutputConfig)
220	}
221	if wire.Temperature != nil {
222		t.Fatalf("Sonnet 5 adaptive must drop temperature, got %v", *wire.Temperature)
223	}
224
225	// Opus 4.5 -> budget-based thinking, no output_config, temperature kept.
226	wire, err = c.buildRequest(Request{
227		Model:       "claude-opus-4-5",
228		Reasoning:   "high",
229		Temperature: &temp,
230		Messages:    []Message{{Role: RoleUser, Content: []Content{TextBlock{Text: "hi"}}}},
231	})
232	if err != nil {
233		t.Fatal(err)
234	}
235	if wire.Thinking == nil || wire.Thinking.Type != "enabled" || wire.Thinking.BudgetTokens <= 0 {
236		t.Fatalf("want budget thinking, got %+v", wire.Thinking)
237	}
238	if wire.OutputConfig != nil {
239		t.Fatalf("budget models must not send output_config, got %+v", wire.OutputConfig)
240	}
241	if wire.Temperature == nil || *wire.Temperature != temp {
242		t.Fatalf("budget model should keep temperature, got %v", wire.Temperature)
243	}
244}
245
246func TestAnthropicBuildRequestStripsAssistantImages(t *testing.T) {
247	c := NewAnthropic("x", "").(*anthropicClient)
248	wire, err := c.buildRequest(Request{
249		Model: "claude-sonnet-4-5",
250		Messages: []Message{
251			{Role: RoleUser, Content: []Content{TextBlock{Text: "make an image"}}},
252			{Role: RoleAssistant, Content: []Content{
253				TextBlock{Text: "done"},
254				ImageBlock{MimeType: "image/png", Data: []byte("png")},
255				TextBlock{Text: "Saved image: `zot-gemini-image-x.png`"},
256			}},
257			{Role: RoleUser, Content: []Content{TextBlock{Text: "hello"}}},
258		},
259	})
260	if err != nil {
261		t.Fatal(err)
262	}
263	if len(wire.Messages) != 3 {
264		t.Fatalf("messages=%d", len(wire.Messages))
265	}
266	assistant := wire.Messages[1]
267	if assistant.Role != "assistant" {
268		t.Fatalf("role=%q", assistant.Role)
269	}
270	if len(assistant.Content) != 2 {
271		t.Fatalf("assistant content=%+v", assistant.Content)
272	}
273	for _, b := range assistant.Content {
274		if _, ok := b.(anthImageBlock); ok {
275			t.Fatalf("assistant image block was not stripped: %+v", assistant.Content)
276		}
277	}
278}
279
280func TestAnthropicBuildRequestDeduplicatesToolResults(t *testing.T) {
281	c := NewAnthropic("x", "").(*anthropicClient)
282	wire, err := c.buildRequest(Request{
283		Model: "claude-sonnet-4-5",
284		Messages: []Message{
285			{Role: RoleUser, Content: []Content{TextBlock{Text: "read the file"}}},
286			{Role: RoleAssistant, Content: []Content{
287				ToolCallBlock{ID: "tool-1", Name: "read"},
288			}},
289			{Role: RoleTool, Content: []Content{
290				ToolResultBlock{CallID: "tool-1", Content: []Content{TextBlock{Text: "first result"}}},
291			}},
292			{Role: RoleTool, Content: []Content{
293				ToolResultBlock{CallID: "tool-1", Content: []Content{TextBlock{Text: "duplicate result"}}},
294			}},
295		},
296	})
297	if err != nil {
298		t.Fatal(err)
299	}
300	if len(wire.Messages) != 3 {
301		t.Fatalf("messages=%d, want 3 after dropping duplicate result message", len(wire.Messages))
302	}
303	blocks := wire.Messages[2].Content
304	if len(blocks) != 1 {
305		t.Fatalf("tool result blocks=%d, want 1", len(blocks))
306	}
307	result, ok := blocks[0].(anthToolResultBlock)
308	if !ok {
309		t.Fatalf("tool result block type=%T", blocks[0])
310	}
311	if string(result.Content) != `"first result"` {
312		t.Fatalf("tool result content=%s", result.Content)
313	}
314}
315
316func TestAnthropicStreamHappyPath(t *testing.T) {
317	srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
318		w.Header().Set("content-type", "text/event-stream")
319		w.WriteHeader(http.StatusOK)
320		fl, _ := w.(http.Flusher)
321		write := func(s string) {
322			_, _ = w.Write([]byte(s))
323			if fl != nil {
324				fl.Flush()
325			}
326		}
327		write("event: message_start\ndata: {\"message\":{\"usage\":{\"input_tokens\":10,\"output_tokens\":0}}}\n\n")
328		write("event: content_block_start\ndata: {\"index\":0,\"content_block\":{\"type\":\"text\",\"text\":\"\"}}\n\n")
329		write("event: content_block_delta\ndata: {\"index\":0,\"delta\":{\"type\":\"text_delta\",\"text\":\"hi\"}}\n\n")
330		write("event: content_block_stop\ndata: {\"index\":0}\n\n")
331		write("event: message_delta\ndata: {\"delta\":{\"stop_reason\":\"end_turn\"},\"usage\":{\"output_tokens\":5}}\n\n")
332		write("event: message_stop\ndata: {}\n\n")
333	}))
334	defer srv.Close()
335
336	c := NewAnthropic("x", srv.URL)
337	evs, err := c.Stream(context.Background(), Request{Model: "claude-sonnet-4-5"})
338	if err != nil {
339		t.Fatal(err)
340	}
341	var gotText string
342	var done EventDone
343	for ev := range evs {
344		switch e := ev.(type) {
345		case EventTextDelta:
346			gotText += e.Delta
347		case EventDone:
348			done = e
349		}
350	}
351	if gotText != "hi" {
352		t.Fatalf("text=%q", gotText)
353	}
354	if done.Stop != StopEnd {
355		t.Fatalf("stop=%v", done.Stop)
356	}
357}
358
359func TestClaudeOpus5Catalog(t *testing.T) {
360	m, err := FindModel("anthropic", "claude-opus-5")
361	if err != nil {
362		t.Fatal(err)
363	}
364	if m.DisplayName != "Claude Opus 5" || m.ContextWindow != 1000000 || m.MaxOutput != 128000 || !m.Reasoning || !m.AdaptiveThinking || m.Speculative {
365		t.Fatalf("unexpected Opus 5 model: %+v", m)
366	}
367	if m.PriceInput != 5 || m.PriceOutput != 25 || m.PriceCacheRead != 0.5 || m.PriceCacheWrite != 6.25 {
368		t.Fatalf("unexpected Opus 5 pricing: %+v", m)
369	}
370}
371
372func TestClaudeSonnet5Catalog(t *testing.T) {
373	m, err := FindModel("anthropic", "claude-sonnet-5")
374	if err != nil {
375		t.Fatal(err)
376	}
377	if m.DisplayName != "Claude Sonnet 5" || m.ContextWindow != 1000000 || m.MaxOutput != 128000 || !m.Reasoning || !m.AdaptiveThinking {
378		t.Fatalf("unexpected Sonnet 5 model: %+v", m)
379	}
380	if m.PriceInput != 2 || m.PriceOutput != 10 || m.PriceCacheRead != 0.2 || m.PriceCacheWrite != 2.5 {
381		t.Fatalf("unexpected Sonnet 5 pricing: %+v", m)
382	}
383}
384
385func TestGondolaSeedCatalog(t *testing.T) {
386	kimi, err := FindModel("gondola", "kimi-k3")
387	if err != nil {
388		t.Fatal(err)
389	}
390	if kimi.ContextWindow != 1000000 || kimi.MaxOutput != 131072 || !kimi.Reasoning || kimi.AdaptiveThinking {
391		t.Fatalf("unexpected Kimi K3 model: %+v", kimi)
392	}
393	if kimi.PriceInput != 1.1475 || kimi.PriceOutput != 5.7375 || kimi.PriceCacheRead != 0.11475 {
394		t.Fatalf("unexpected Kimi K3 pricing: %+v", kimi)
395	}
396
397	opus, err := FindModel("gondola", "claude-opus-5")
398	if err != nil {
399		t.Fatal(err)
400	}
401	if !opus.AdaptiveThinking || opus.PriceInput != 1.836 || opus.PriceOutput != 9.18 || opus.PriceCacheRead != 0.1836 || opus.PriceCacheWrite != 2.295 {
402		t.Fatalf("unexpected Claude Opus 5 model: %+v", opus)
403	}
404}
405
406func TestOpenAICompatAnthropicReasoningEffort(t *testing.T) {
407	c := NewOpenRouter("token", "").(*openaiClient)
408	wire, err := c.buildRequest(Request{
409		Model:     "anthropic/claude-opus-4.8",
410		Reasoning: "maximum",
411		Messages:  []Message{{Role: RoleUser, Content: []Content{TextBlock{Text: "hi"}}}},
412	})
413	if err != nil {
414		t.Fatal(err)
415	}
416	if wire.ReasoningEffort != "xhigh" {
417		t.Fatalf("want xhigh for adaptive Anthropic model over OpenAI-compatible wire, got %q", wire.ReasoningEffort)
418	}
419
420	wire, err = c.buildRequest(Request{
421		Model:     "anthropic/claude-sonnet-5",
422		Reasoning: "maximum",
423		Messages:  []Message{{Role: RoleUser, Content: []Content{TextBlock{Text: "hi"}}}},
424	})
425	if err != nil {
426		t.Fatal(err)
427	}
428	if wire.ReasoningEffort != "xhigh" {
429		t.Fatalf("want xhigh for Claude Sonnet 5 over OpenAI-compatible wire, got %q", wire.ReasoningEffort)
430	}
431
432	wire, err = c.buildRequest(Request{
433		Model:     "gpt-5.1",
434		Reasoning: "maximum",
435		Messages:  []Message{{Role: RoleUser, Content: []Content{TextBlock{Text: "hi"}}}},
436	})
437	if err != nil {
438		t.Fatal(err)
439	}
440	if wire.ReasoningEffort != "high" {
441		t.Fatalf("want generic OpenAI-compatible maximum clamped to high, got %q", wire.ReasoningEffort)
442	}
443}
444
445func TestOpenAIBuildRequestSkipsReasoningOnlyAssistantMessages(t *testing.T) {
446	c := NewKimi("token", "").(*openaiClient)
447	wire, err := c.buildRequest(Request{
448		Model: "kimi-for-coding",
449		Messages: []Message{
450			{Role: RoleUser, Content: []Content{TextBlock{Text: "first"}}},
451			{Role: RoleAssistant, Content: []Content{ReasoningBlock{Summary: "thinking only"}}},
452			{Role: RoleUser, Content: []Content{TextBlock{Text: "second"}}},
453		},
454	})
455	if err != nil {
456		t.Fatal(err)
457	}
458	for i, msg := range wire.Messages {
459		if msg.Role == "assistant" && msg.Content == nil && len(msg.ToolCalls) == 0 {
460			t.Fatalf("message %d is empty assistant: %+v", i, msg)
461		}
462	}
463	if got := len(wire.Messages); got != 2 {
464		t.Fatalf("messages=%d want 2 after skipping reasoning-only assistant", got)
465	}
466}
467
468func TestOpenAIStreamHappyPath(t *testing.T) {
469	srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
470		w.Header().Set("content-type", "text/event-stream")
471		w.WriteHeader(http.StatusOK)
472		fl, _ := w.(http.Flusher)
473		write := func(s string) {
474			_, _ = w.Write([]byte(s))
475			if fl != nil {
476				fl.Flush()
477			}
478		}
479		write("data: {\"choices\":[{\"index\":0,\"delta\":{\"content\":\"hel\"},\"finish_reason\":null}]}\n\n")
480		write("data: {\"choices\":[{\"index\":0,\"delta\":{\"content\":\"lo\"},\"finish_reason\":\"stop\"}]}\n\n")
481		write("data: {\"choices\":[],\"usage\":{\"prompt_tokens\":8,\"completion_tokens\":2}}\n\n")
482		write("data: [DONE]\n\n")
483	}))
484	defer srv.Close()
485
486	c := NewOpenAI("x", srv.URL)
487	evs, err := c.Stream(context.Background(), Request{Model: "gpt-5"})
488	if err != nil {
489		t.Fatal(err)
490	}
491	var gotText string
492	var done EventDone
493	for ev := range evs {
494		switch e := ev.(type) {
495		case EventTextDelta:
496			gotText += e.Delta
497		case EventDone:
498			done = e
499		}
500	}
501	if gotText != "hello" {
502		t.Fatalf("text=%q", gotText)
503	}
504	if done.Stop != StopEnd {
505		t.Fatalf("stop=%v", done.Stop)
506	}
507}
508
509func TestDiscoverOpenRouter(t *testing.T) {
510	const body = `{"data":[
511		{"id":"x/full","pricing":{"prompt":"0.000003","completion":"0.000015"},
512		 "context_length":200000,"top_provider":{"max_completion_tokens":64000},
513		 "supported_parameters":["reasoning"]},
514		{"id":"x/fallback","top_provider":{"context_length":128000}},
515		{"id":""}]}`
516	srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
517		_, _ = w.Write([]byte(body))
518	}))
519	defer srv.Close()
520
521	models, err := DiscoverOpenRouter(context.Background(), srv.URL)
522	if err != nil {
523		t.Fatal(err)
524	}
525	if len(models) != 2 { // empty id dropped
526		t.Fatalf("want 2 models, got %d", len(models))
527	}
528	// per-token USD -> per-1M; reasoning from supported_parameters.
529	if m := models[0]; m.Provider != "openrouter" || m.ContextWindow != 200000 ||
530		m.MaxOutput != 64000 || !m.Reasoning || m.PriceInput != 3 || m.PriceOutput != 15 {
531		t.Errorf("model[0]: %+v", m)
532	}
533	// context falls back to top_provider; no reasoning.
534	if m := models[1]; m.ContextWindow != 128000 || m.MaxOutput != 0 || m.Reasoning {
535		t.Errorf("model[1]: %+v", m)
536	}
537}
538
539func TestGPT56CatalogEntries(t *testing.T) {
540	cases := []struct {
541		provider   string
542		id         string
543		context    int
544		priceInput float64
545		priceOut   float64
546		cacheRead  float64
547		cacheWrite float64
548	}{
549		{"openai", "gpt-5.6-luna", 272000, 1, 6, 0.1, 1.25},
550		{"openai", "gpt-5.6-sol", 272000, 5, 30, 0.5, 6.25},
551		{"openai", "gpt-5.6-terra", 272000, 2.5, 15, 0.25, 3.125},
552		{"openai-codex", "gpt-5.6-luna", 272000, 1, 6, 0.1, 1.25},
553		{"openai-codex", "gpt-5.6-sol", 272000, 5, 30, 0.5, 6.25},
554		{"openai-codex", "gpt-5.6-terra", 272000, 2.5, 15, 0.25, 3.125},
555		{"azure-openai-responses", "gpt-5.6-luna", 1050000, 1, 6, 0.1, 1.25},
556		{"azure-openai-responses", "gpt-5.6-sol", 1050000, 5, 30, 0.5, 6.25},
557		{"azure-openai-responses", "gpt-5.6-terra", 1050000, 2.5, 15, 0.25, 3.125},
558		{"vercel-ai-gateway", "openai/gpt-5.6-luna", 1050000, 1, 6, 0.1, 1.25},
559		{"vercel-ai-gateway", "openai/gpt-5.6-sol", 1050000, 5, 30, 0.5, 6.25},
560		{"vercel-ai-gateway", "openai/gpt-5.6-terra", 1050000, 2.5, 15, 0.25, 3.125},
561	}
562	for _, tc := range cases {
563		m, err := FindModel(tc.provider, tc.id)
564		if err != nil {
565			t.Fatal(err)
566		}
567		if m.ContextWindow != tc.context || m.MaxOutput != 128000 || !m.Reasoning {
568			t.Fatalf("%s/%s limits: %+v", tc.provider, tc.id, m)
569		}
570		if m.PriceInput != tc.priceInput || m.PriceOutput != tc.priceOut || m.PriceCacheRead != tc.cacheRead || m.PriceCacheWrite != tc.cacheWrite {
571			t.Fatalf("%s/%s prices: %+v", tc.provider, tc.id, m)
572		}
573	}
574}
575
576// TestOpenCodeGoCatalog pins entries added from the vendor's current Go
577// model lineup (https://opencode.ai/docs/go).
578func TestOpenCodeGoCatalog(t *testing.T) {
579	cases := []struct {
580		id        string
581		context   int
582		maxOut    int
583		priceIn   float64
584		priceOut  float64
585		cacheRead float64
586	}{
587		{"gpt-5.6-luna", 1050000, 128000, 0.2, 1.2, 0.02},
588		{"grok-4.5", 500000, 500000, 2, 6, 0.3},
589		{"kimi-k3", 1048576, 131072, 3, 15, 0.3},
590	}
591	for _, tc := range cases {
592		m, err := FindModel("opencode-go", tc.id)
593		if err != nil {
594			t.Fatal(err)
595		}
596		if m.ContextWindow != tc.context || m.MaxOutput != tc.maxOut || !m.Reasoning {
597			t.Fatalf("opencode-go/%s limits: %+v", tc.id, m)
598		}
599		if m.PriceInput != tc.priceIn || m.PriceOutput != tc.priceOut || m.PriceCacheRead != tc.cacheRead {
600			t.Fatalf("opencode-go/%s prices: %+v", tc.id, m)
601		}
602		if m.BaseURL != "https://opencode.ai/zen/go/v1" {
603			t.Fatalf("opencode-go/%s baseURL: %s", tc.id, m.BaseURL)
604		}
605	}
606
607	luna, err := FindModel("opencode-go", "gpt-5.6-luna")
608	if err != nil {
609		t.Fatal(err)
610	}
611	if luna.API != APIResponses || luna.PriceCacheWrite != 0.25 {
612		t.Fatalf("opencode-go/gpt-5.6-luna API or cache-write price: %+v", luna)
613	}
614	if luna.PriceTierInputTokens != 272000 || luna.PriceInputAbove != 0.4 || luna.PriceOutputAbove != 1.8 || luna.PriceCacheReadAbove != 0.04 || luna.PriceCacheWriteAbove != 0.5 {
615		t.Fatalf("opencode-go/gpt-5.6-luna long-context prices: %+v", luna)
616	}
617}
618
619// TestOpenAIOmitsZeroMaxTokens guards against sending max_tokens: 0 for
620// discovered models that don't advertise an output cap (MaxOutput == 0).
621func TestOpenAIOmitsZeroMaxTokens(t *testing.T) {
622	SetLiveModels([]Model{
623		{Provider: "openrouter", ID: "vendor/no-cap", DisplayName: "No Cap"},
624		{Provider: "openrouter", ID: "vendor/reason-no-cap", DisplayName: "Reason No Cap", Reasoning: true},
625		{Provider: "openrouter", ID: "vendor/capped", DisplayName: "Capped", MaxOutput: 4096},
626	})
627	defer SetLiveModels(nil)
628
629	c := NewOpenAI("x", "").(*openaiClient)
630
631	got, err := c.buildRequest(Request{Model: "vendor/no-cap"})
632	if err != nil {
633		t.Fatal(err)
634	}
635	if got.MaxTokens != nil {
636		t.Errorf("expected max_tokens omitted, got %d", *got.MaxTokens)
637	}
638
639	got, err = c.buildRequest(Request{Model: "vendor/reason-no-cap"})
640	if err != nil {
641		t.Fatal(err)
642	}
643	if got.MaxCompletionTok != nil {
644		t.Errorf("expected max_completion_tokens omitted, got %d", *got.MaxCompletionTok)
645	}
646
647	got, err = c.buildRequest(Request{Model: "vendor/capped"})
648	if err != nil {
649		t.Fatal(err)
650	}
651	if got.MaxTokens == nil || *got.MaxTokens != 4096 {
652		t.Errorf("expected max_tokens 4096, got %v", got.MaxTokens)
653	}
654}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 477

↑↓ moveenter openesc close