diff --git a/main.go b/main.go index 6497ec8..d1ff7dc 100644 --- a/main.go +++ b/main.go @@ -85,6 +85,7 @@ var llmTransport = &http.Transport{ } var defCfg = Cfg{"https://api.kilo.ai/api/openrouter", "openrouter/free", "-", 0.7, 300, 120, 1000, true, "auto", 262144, map[string]string{"reasoning_effort": "high"}} +const opencodeAgentVersion = "opencode/1.18.30" func atoiD(s string, d int) int { if v, e := strconv.Atoi(strings.TrimSpace(s)); e == nil { @@ -103,7 +104,8 @@ func queryModelsContextWindow(cfg *Cfg) int { } req, err := http.NewRequest("GET", strings.TrimRight(cfg.Endpoint, "/")+"/models", nil) if err != nil { return 0 } - req.Header.Set("User-Agent", "Mozilla/5.0 (compatible; Bantam/1.0)") + req.Header.Set("User-Agent", opencodeAgentVersion) + req.Header.Set("X-Session-ID", projectID()) if cfg.APIKey != "" && cfg.APIKey != "-" { req.Header.Set("Authorization", "Bearer "+cfg.APIKey) } resp, err := client.Do(req) if err != nil || resp.StatusCode >= 400 { return 0 } @@ -175,7 +177,8 @@ func listModels(cfg *Cfg) (string, error) { } req, err := http.NewRequest("GET", strings.TrimRight(cfg.Endpoint, "/")+"/models", nil) if err != nil { return "", err } - req.Header.Set("User-Agent", "Mozilla/5.0 (compatible; Bantam/1.0)") + req.Header.Set("User-Agent", opencodeAgentVersion) + req.Header.Set("X-Session-ID", projectID()) if cfg.APIKey != "" && cfg.APIKey != "-" { req.Header.Set("Authorization", "Bearer "+cfg.APIKey) } resp, err := client.Do(req) if err != nil { return "", err } @@ -1043,7 +1046,8 @@ func llm(ctx context.Context, cfg *Cfg, msgs []Message, tools []map[string]any) if COL { fmt.Print("\r" + pend) } else { fmt.Println(pend) } req, _ := http.NewRequestWithContext(ctx, "POST", strings.TrimRight(cfg.Endpoint, "/")+"/chat/completions", bytes.NewReader(body)) req.Header.Set("Content-Type", "application/json") - req.Header.Set("User-Agent", "Mozilla/5.0 (compatible; Bantam/1.0)") + req.Header.Set("User-Agent", opencodeAgentVersion) + req.Header.Set("X-Session-ID", projectID()) if cfg.APIKey != "" && cfg.APIKey != "-" { req.Header.Set("Authorization", "Bearer "+cfg.APIKey) } resp, err = client.Do(req) var is4xxClientErr bool diff --git a/main_test.go b/main_test.go index 60008b7..5e7b1de 100644 --- a/main_test.go +++ b/main_test.go @@ -1170,7 +1170,7 @@ func TestLLMNonStreamingAndHeaders(t *testing.T) { if gotAuth != "Bearer secret" { t.Errorf("auth = %q", gotAuth) } - if !strings.Contains(gotUA, "Bantam/1.0") { + if !strings.Contains(gotUA, "opencode/1.18.30") { t.Errorf("user-agent = %q", gotUA) } if m.Content == nil || *m.Content != "hi" || m.ReasoningContent != "think" {