v0.3.49 2470fda

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 TestAnthropicStreamHappyPath(t *testing.T) {
281	srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
282		w.Header().Set("content-type", "text/event-stream")
283		w.WriteHeader(http.StatusOK)
284		fl, _ := w.(http.Flusher)
285		write := func(s string) {
286			_, _ = w.Write([]byte(s))
287			if fl != nil {
288				fl.Flush()
289			}
290		}
291		write("event: message_start\ndata: {\"message\":{\"usage\":{\"input_tokens\":10,\"output_tokens\":0}}}\n\n")
292		write("event: content_block_start\ndata: {\"index\":0,\"content_block\":{\"type\":\"text\",\"text\":\"\"}}\n\n")
293		write("event: content_block_delta\ndata: {\"index\":0,\"delta\":{\"type\":\"text_delta\",\"text\":\"hi\"}}\n\n")
294		write("event: content_block_stop\ndata: {\"index\":0}\n\n")
295		write("event: message_delta\ndata: {\"delta\":{\"stop_reason\":\"end_turn\"},\"usage\":{\"output_tokens\":5}}\n\n")
296		write("event: message_stop\ndata: {}\n\n")
297	}))
298	defer srv.Close()
299
300	c := NewAnthropic("x", srv.URL)
301	evs, err := c.Stream(context.Background(), Request{Model: "claude-sonnet-4-5"})
302	if err != nil {
303		t.Fatal(err)
304	}
305	var gotText string
306	var done EventDone
307	for ev := range evs {
308		switch e := ev.(type) {
309		case EventTextDelta:
310			gotText += e.Delta
311		case EventDone:
312			done = e
313		}
314	}
315	if gotText != "hi" {
316		t.Fatalf("text=%q", gotText)
317	}
318	if done.Stop != StopEnd {
319		t.Fatalf("stop=%v", done.Stop)
320	}
321}
322
323func TestClaudeOpus5Catalog(t *testing.T) {
324	m, err := FindModel("anthropic", "claude-opus-5")
325	if err != nil {
326		t.Fatal(err)
327	}
328	if m.DisplayName != "Claude Opus 5" || m.ContextWindow != 1000000 || m.MaxOutput != 128000 || !m.Reasoning || !m.AdaptiveThinking || m.Speculative {
329		t.Fatalf("unexpected Opus 5 model: %+v", m)
330	}
331	if m.PriceInput != 5 || m.PriceOutput != 25 || m.PriceCacheRead != 0.5 || m.PriceCacheWrite != 6.25 {
332		t.Fatalf("unexpected Opus 5 pricing: %+v", m)
333	}
334}
335
336func TestClaudeSonnet5Catalog(t *testing.T) {
337	m, err := FindModel("anthropic", "claude-sonnet-5")
338	if err != nil {
339		t.Fatal(err)
340	}
341	if m.DisplayName != "Claude Sonnet 5" || m.ContextWindow != 1000000 || m.MaxOutput != 128000 || !m.Reasoning || !m.AdaptiveThinking {
342		t.Fatalf("unexpected Sonnet 5 model: %+v", m)
343	}
344	if m.PriceInput != 2 || m.PriceOutput != 10 || m.PriceCacheRead != 0.2 || m.PriceCacheWrite != 2.5 {
345		t.Fatalf("unexpected Sonnet 5 pricing: %+v", m)
346	}
347}
348
349func TestGondolaSeedCatalog(t *testing.T) {
350	kimi, err := FindModel("gondola", "kimi-k3")
351	if err != nil {
352		t.Fatal(err)
353	}
354	if kimi.ContextWindow != 1000000 || kimi.MaxOutput != 131072 || !kimi.Reasoning || kimi.AdaptiveThinking {
355		t.Fatalf("unexpected Kimi K3 model: %+v", kimi)
356	}
357	if kimi.PriceInput != 1.1475 || kimi.PriceOutput != 5.7375 || kimi.PriceCacheRead != 0.11475 {
358		t.Fatalf("unexpected Kimi K3 pricing: %+v", kimi)
359	}
360
361	opus, err := FindModel("gondola", "claude-opus-5")
362	if err != nil {
363		t.Fatal(err)
364	}
365	if !opus.AdaptiveThinking || opus.PriceInput != 1.836 || opus.PriceOutput != 9.18 || opus.PriceCacheRead != 0.1836 || opus.PriceCacheWrite != 2.295 {
366		t.Fatalf("unexpected Claude Opus 5 model: %+v", opus)
367	}
368}
369
370func TestOpenAICompatAnthropicReasoningEffort(t *testing.T) {
371	c := NewOpenRouter("token", "").(*openaiClient)
372	wire, err := c.buildRequest(Request{
373		Model:     "anthropic/claude-opus-4.8",
374		Reasoning: "maximum",
375		Messages:  []Message{{Role: RoleUser, Content: []Content{TextBlock{Text: "hi"}}}},
376	})
377	if err != nil {
378		t.Fatal(err)
379	}
380	if wire.ReasoningEffort != "xhigh" {
381		t.Fatalf("want xhigh for adaptive Anthropic model over OpenAI-compatible wire, got %q", wire.ReasoningEffort)
382	}
383
384	wire, err = c.buildRequest(Request{
385		Model:     "anthropic/claude-sonnet-5",
386		Reasoning: "maximum",
387		Messages:  []Message{{Role: RoleUser, Content: []Content{TextBlock{Text: "hi"}}}},
388	})
389	if err != nil {
390		t.Fatal(err)
391	}
392	if wire.ReasoningEffort != "xhigh" {
393		t.Fatalf("want xhigh for Claude Sonnet 5 over OpenAI-compatible wire, got %q", wire.ReasoningEffort)
394	}
395
396	wire, err = c.buildRequest(Request{
397		Model:     "gpt-5.1",
398		Reasoning: "maximum",
399		Messages:  []Message{{Role: RoleUser, Content: []Content{TextBlock{Text: "hi"}}}},
400	})
401	if err != nil {
402		t.Fatal(err)
403	}
404	if wire.ReasoningEffort != "high" {
405		t.Fatalf("want generic OpenAI-compatible maximum clamped to high, got %q", wire.ReasoningEffort)
406	}
407}
408
409func TestOpenAIBuildRequestSkipsReasoningOnlyAssistantMessages(t *testing.T) {
410	c := NewKimi("token", "").(*openaiClient)
411	wire, err := c.buildRequest(Request{
412		Model: "kimi-for-coding",
413		Messages: []Message{
414			{Role: RoleUser, Content: []Content{TextBlock{Text: "first"}}},
415			{Role: RoleAssistant, Content: []Content{ReasoningBlock{Summary: "thinking only"}}},
416			{Role: RoleUser, Content: []Content{TextBlock{Text: "second"}}},
417		},
418	})
419	if err != nil {
420		t.Fatal(err)
421	}
422	for i, msg := range wire.Messages {
423		if msg.Role == "assistant" && msg.Content == nil && len(msg.ToolCalls) == 0 {
424			t.Fatalf("message %d is empty assistant: %+v", i, msg)
425		}
426	}
427	if got := len(wire.Messages); got != 2 {
428		t.Fatalf("messages=%d want 2 after skipping reasoning-only assistant", got)
429	}
430}
431
432func TestOpenAIStreamHappyPath(t *testing.T) {
433	srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
434		w.Header().Set("content-type", "text/event-stream")
435		w.WriteHeader(http.StatusOK)
436		fl, _ := w.(http.Flusher)
437		write := func(s string) {
438			_, _ = w.Write([]byte(s))
439			if fl != nil {
440				fl.Flush()
441			}
442		}
443		write("data: {\"choices\":[{\"index\":0,\"delta\":{\"content\":\"hel\"},\"finish_reason\":null}]}\n\n")
444		write("data: {\"choices\":[{\"index\":0,\"delta\":{\"content\":\"lo\"},\"finish_reason\":\"stop\"}]}\n\n")
445		write("data: {\"choices\":[],\"usage\":{\"prompt_tokens\":8,\"completion_tokens\":2}}\n\n")
446		write("data: [DONE]\n\n")
447	}))
448	defer srv.Close()
449
450	c := NewOpenAI("x", srv.URL)
451	evs, err := c.Stream(context.Background(), Request{Model: "gpt-5"})
452	if err != nil {
453		t.Fatal(err)
454	}
455	var gotText string
456	var done EventDone
457	for ev := range evs {
458		switch e := ev.(type) {
459		case EventTextDelta:
460			gotText += e.Delta
461		case EventDone:
462			done = e
463		}
464	}
465	if gotText != "hello" {
466		t.Fatalf("text=%q", gotText)
467	}
468	if done.Stop != StopEnd {
469		t.Fatalf("stop=%v", done.Stop)
470	}
471}
472
473func TestDiscoverOpenRouter(t *testing.T) {
474	const body = `{"data":[
475		{"id":"x/full","pricing":{"prompt":"0.000003","completion":"0.000015"},
476		 "context_length":200000,"top_provider":{"max_completion_tokens":64000},
477		 "supported_parameters":["reasoning"]},
478		{"id":"x/fallback","top_provider":{"context_length":128000}},
479		{"id":""}]}`
480	srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
481		_, _ = w.Write([]byte(body))
482	}))
483	defer srv.Close()
484
485	models, err := DiscoverOpenRouter(context.Background(), srv.URL)
486	if err != nil {
487		t.Fatal(err)
488	}
489	if len(models) != 2 { // empty id dropped
490		t.Fatalf("want 2 models, got %d", len(models))
491	}
492	// per-token USD -> per-1M; reasoning from supported_parameters.
493	if m := models[0]; m.Provider != "openrouter" || m.ContextWindow != 200000 ||
494		m.MaxOutput != 64000 || !m.Reasoning || m.PriceInput != 3 || m.PriceOutput != 15 {
495		t.Errorf("model[0]: %+v", m)
496	}
497	// context falls back to top_provider; no reasoning.
498	if m := models[1]; m.ContextWindow != 128000 || m.MaxOutput != 0 || m.Reasoning {
499		t.Errorf("model[1]: %+v", m)
500	}
501}
502
503func TestGPT56CatalogEntries(t *testing.T) {
504	cases := []struct {
505		provider   string
506		id         string
507		context    int
508		priceInput float64
509		priceOut   float64
510		cacheRead  float64
511		cacheWrite float64
512	}{
513		{"openai", "gpt-5.6-luna", 272000, 1, 6, 0.1, 1.25},
514		{"openai", "gpt-5.6-sol", 272000, 5, 30, 0.5, 6.25},
515		{"openai", "gpt-5.6-terra", 272000, 2.5, 15, 0.25, 3.125},
516		{"openai-codex", "gpt-5.6-luna", 272000, 1, 6, 0.1, 1.25},
517		{"openai-codex", "gpt-5.6-sol", 272000, 5, 30, 0.5, 6.25},
518		{"openai-codex", "gpt-5.6-terra", 272000, 2.5, 15, 0.25, 3.125},
519		{"azure-openai-responses", "gpt-5.6-luna", 1050000, 1, 6, 0.1, 1.25},
520		{"azure-openai-responses", "gpt-5.6-sol", 1050000, 5, 30, 0.5, 6.25},
521		{"azure-openai-responses", "gpt-5.6-terra", 1050000, 2.5, 15, 0.25, 3.125},
522		{"vercel-ai-gateway", "openai/gpt-5.6-luna", 1050000, 1, 6, 0.1, 1.25},
523		{"vercel-ai-gateway", "openai/gpt-5.6-sol", 1050000, 5, 30, 0.5, 6.25},
524		{"vercel-ai-gateway", "openai/gpt-5.6-terra", 1050000, 2.5, 15, 0.25, 3.125},
525	}
526	for _, tc := range cases {
527		m, err := FindModel(tc.provider, tc.id)
528		if err != nil {
529			t.Fatal(err)
530		}
531		if m.ContextWindow != tc.context || m.MaxOutput != 128000 || !m.Reasoning {
532			t.Fatalf("%s/%s limits: %+v", tc.provider, tc.id, m)
533		}
534		if m.PriceInput != tc.priceInput || m.PriceOutput != tc.priceOut || m.PriceCacheRead != tc.cacheRead || m.PriceCacheWrite != tc.cacheWrite {
535			t.Fatalf("%s/%s prices: %+v", tc.provider, tc.id, m)
536		}
537	}
538}
539
540// TestOpenCodeGoCatalog pins entries added from the vendor's current Go
541// model lineup (https://opencode.ai/docs/go).
542func TestOpenCodeGoCatalog(t *testing.T) {
543	cases := []struct {
544		id        string
545		context   int
546		maxOut    int
547		priceIn   float64
548		priceOut  float64
549		cacheRead float64
550	}{
551		{"gpt-5.6-luna", 1050000, 128000, 0.2, 1.2, 0.02},
552		{"grok-4.5", 500000, 500000, 2, 6, 0.3},
553		{"kimi-k3", 1048576, 131072, 3, 15, 0.3},
554	}
555	for _, tc := range cases {
556		m, err := FindModel("opencode-go", tc.id)
557		if err != nil {
558			t.Fatal(err)
559		}
560		if m.ContextWindow != tc.context || m.MaxOutput != tc.maxOut || !m.Reasoning {
561			t.Fatalf("opencode-go/%s limits: %+v", tc.id, m)
562		}
563		if m.PriceInput != tc.priceIn || m.PriceOutput != tc.priceOut || m.PriceCacheRead != tc.cacheRead {
564			t.Fatalf("opencode-go/%s prices: %+v", tc.id, m)
565		}
566		if m.BaseURL != "https://opencode.ai/zen/go/v1" {
567			t.Fatalf("opencode-go/%s baseURL: %s", tc.id, m.BaseURL)
568		}
569	}
570
571	luna, err := FindModel("opencode-go", "gpt-5.6-luna")
572	if err != nil {
573		t.Fatal(err)
574	}
575	if luna.API != APIResponses || luna.PriceCacheWrite != 0.25 {
576		t.Fatalf("opencode-go/gpt-5.6-luna API or cache-write price: %+v", luna)
577	}
578	if luna.PriceTierInputTokens != 272000 || luna.PriceInputAbove != 0.4 || luna.PriceOutputAbove != 1.8 || luna.PriceCacheReadAbove != 0.04 || luna.PriceCacheWriteAbove != 0.5 {
579		t.Fatalf("opencode-go/gpt-5.6-luna long-context prices: %+v", luna)
580	}
581}
582
583// TestOpenAIOmitsZeroMaxTokens guards against sending max_tokens: 0 for
584// discovered models that don't advertise an output cap (MaxOutput == 0).
585func TestOpenAIOmitsZeroMaxTokens(t *testing.T) {
586	SetLiveModels([]Model{
587		{Provider: "openrouter", ID: "vendor/no-cap", DisplayName: "No Cap"},
588		{Provider: "openrouter", ID: "vendor/reason-no-cap", DisplayName: "Reason No Cap", Reasoning: true},
589		{Provider: "openrouter", ID: "vendor/capped", DisplayName: "Capped", MaxOutput: 4096},
590	})
591	defer SetLiveModels(nil)
592
593	c := NewOpenAI("x", "").(*openaiClient)
594
595	got, err := c.buildRequest(Request{Model: "vendor/no-cap"})
596	if err != nil {
597		t.Fatal(err)
598	}
599	if got.MaxTokens != nil {
600		t.Errorf("expected max_tokens omitted, got %d", *got.MaxTokens)
601	}
602
603	got, err = c.buildRequest(Request{Model: "vendor/reason-no-cap"})
604	if err != nil {
605		t.Fatal(err)
606	}
607	if got.MaxCompletionTok != nil {
608		t.Errorf("expected max_completion_tokens omitted, got %d", *got.MaxCompletionTok)
609	}
610
611	got, err = c.buildRequest(Request{Model: "vendor/capped"})
612	if err != nil {
613		t.Fatal(err)
614	}
615	if got.MaxTokens == nil || *got.MaxTokens != 4096 {
616		t.Errorf("expected max_tokens 4096, got %v", got.MaxTokens)
617	}
618}

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