provider: OpenCode Go's and Zen's Gemini models are asked on Gemini's generateContent, not chat (#2168, @bugyaluwang on X)

OpenCode Go's gemini-4-argon-contributor went to
/zen/go/v1/chat/completions, then Responses and Messages, and Go turns
each away with "Model does not support this protocol". OpenCode serves
each model on the API of the AI SDK package models.dev names in its
per-model provider.npm. catalog.APIOf knew @ai-sdk/openai (Responses)
and @ai-sdk/anthropic (Messages) but not @ai-sdk/google, and an OpenCode
provider had no Gemini URL. So a Gemini model had no API it is served
on. Zen's nine Gemini models (gemini-3-flash, 3.1-pro, 4-argon, ...)
failed the same way: the sibling.

- catalog.APIOf: @ai-sdk/google is "gemini".
- openCodeEndpoints fills in the Gemini base:
  - Zen's /zen/v1. OpenCode's proxy relays models/X:streamGenerateContent
    there to Google's route and reads the key from x-goog-api-key.
  - Go's /inference/go/v1. /zen/go/v1 has no Gemini route (404).
  openCodeRoot also takes /inference and /inference/go URLs.
- The gateway's existing Gemini translator does the rest:
  - models/<id>:streamGenerateContent?alt=sse, the key in x-goog-api-key;
  - OpenCode's x-opencode-session and its variants, as for every API;
  - the client is answered in its own API;
  - reasoning effort low/medium/high becomes thinkingConfig.thinkingLevel.
- Provider.NamedOnlyOn(Gemini) for OpenCode: a model the list names no
  API for (GLM, Kimi...) is never tried on Gemini's, in usable() and in
  the Test probe's model choice. Without it, a model turned away on all
  three falls through to Gemini's and answers with a bare 404.
- The model list isn't fetched at OpenCode's Gemini base: its models
  come from the chat list.
- Existing saved providers get the URL through normalize, as #1215's
  did. The GUI's per-model API picker already offers Gemini once
  p.gemini is set.

Run:
- New TestOpenCodeGoGeminiModelOnGeminiAPI. The fake answers with Zen's
  real SSE bytes. It checks:
  - the URL, x-goog-api-key, no Authorization, and a stable
    x-opencode-session across two turns;
  - chat, chat stream, messages, responses and a Gemini client are each
    answered;
  - thinkingLevel for low, medium and high.
- New TestOpenCodeZenGeminiAndOtherModelsUnchanged: Zen's gemini-3-flash
  goes on /zen/v1/models/...; GLM on Zen and Go stays on chat with
  Bearer; a model with no API named and turned away everywhere is never
  sent to Gemini's.
- TestOpenCodeEndpointsFilledIn now has a gemini column and /inference
  cases.
- Broken by hand, each went red:
  - APIOf's google case: the reporter's error, Go and Zen;
  - the Gemini URL fill;
  - NamedOnlyOn in usable (kimi-k3 sent to Gemini's API).
- gofmt -l; go vet on darwin, linux (nogui) and windows for catalog,
  provider and gateway.
- go test -tags nogui ./internal/catalog ./internal/provider
  ./internal/gateway ./internal/agent: all ok (gateway 1260s, agent
  1170s on a loaded machine).
- Real use, the owner's OpenCode key through the gateway in a sandbox
  HOME (in-process, fresh(t), real network, the live models.dev catalog):
  - Zen gemini-3-flash before the fix: 400 "OpenCode Zen: Model does not
    support this protocol" on chat and messages.
  - Zen gemini-3-flash after:
    - chat: 200 "Hi" (reasoning_effort low);
    - chat stream: 200 "Hi.", [DONE];
    - messages: 200 "Hi.".
  - Go gemini-4-argon-contributor at /inference/go/v1: 400 "This Go model
    trains on request data. Allow paid endpoints that train on request
    data in your workspace's Privacy settings to use it." Not consented
    to, as the issue asks.

Not run:
- A successful Go Gemini answer. The owner's workspace hasn't given that
  consent and has no active Go subscription (glm-5.3 on chat: 403). With
  the fix broken, Go gives this account the same consent 400 on chat,
  so Go's before/after rests on the reporter's error and the fakes.
- The full go test ./...
- The GUI.
This commit is contained in:
yetone
2026-10-14 21:23:15 +08:00
parent b9c589ebb1
commit e5cd125f06
7 changed files with 320 additions and 38 deletions
+7 -3
View File
@@ -783,9 +783,11 @@ func canonicallyPriced(all map[string]mdProvider, providers []string, b string)
func dashed(id string) string { return strings.ReplaceAll(id, ".", "-") }
// APIOf is the API a models.dev provider's model is served on, when the
// catalog says it's one of its own: "responses" or "anthropic" for a model
// OpenCode serves through OpenAI's or Anthropic's SDK, not the
// OpenAI-compatible one the rest of its models go through.
// catalog says it's one of its own: "responses", "anthropic" or "gemini"
// for a model OpenCode serves through OpenAI's, Anthropic's or Google's
// SDK (Gemini's generateContent: Zen's Gemini models, Go's Gemini 4 Argon
// Contributor, #2168), not the OpenAI-compatible one the rest of its
// models go through.
func APIOf(providerID, modelID string) string {
if p, ok := load()[providerID]; ok {
if m, ok := p.Models[modelID]; ok && m.Provider != nil {
@@ -794,6 +796,8 @@ func APIOf(providerID, modelID string) string {
return "responses"
case "@ai-sdk/anthropic":
return "anthropic"
case "@ai-sdk/google":
return "gemini"
}
}
}
+1 -1
View File
@@ -4345,7 +4345,7 @@ func (s *Server) usable(p provider.Provider, model string) []provider.Protocol {
apis := p.APIs(model)
var out []provider.Protocol
for _, proto := range p.Speaks() {
if s.fits(p.ID, model, proto) && (apis == nil || slices.Contains(apis, proto)) {
if s.fits(p.ID, model, proto) && (apis == nil && !p.NamedOnlyOn(proto) || slices.Contains(apis, proto)) {
out = append(out, proto)
}
}
+228
View File
@@ -0,0 +1,228 @@
package gateway
import (
"io"
"net/http"
"net/http/httptest"
"strings"
"sync"
"testing"
"github.com/tidwall/gjson"
"github.com/yetone/magpie/internal/provider"
)
// openCodeGeminiCatalog is models.dev's opencode-go and opencode as they
// list the Gemini models of #2168 (https://models.dev/api.json,
// 2026-10-14): Google's SDK for each, Go's with low, medium and high
// effort, beside a GLM on the provider's own OpenAI-compatible one.
const openCodeGeminiCatalog = `{
"opencode-go": {"id":"opencode-go","npm":"@ai-sdk/openai-compatible","api":"https://opencode.ai/zen/go/v1","models": {
"gemini-4-argon-contributor": {"id":"gemini-4-argon-contributor","name":"Gemini 4 Argon","reasoning":true,"provider":{"npm":"@ai-sdk/google"},
"reasoning_options":[{"effort":"low"},{"effort":"medium"},{"effort":"high"}]},
"glm-5.3": {"id":"glm-5.3","name":"GLM-5.3"}}},
"opencode": {"id":"opencode","npm":"@ai-sdk/openai-compatible","api":"https://opencode.ai/zen/v1","models": {
"gemini-3-flash": {"id":"gemini-3-flash","name":"Gemini 3 Flash","reasoning":true,"provider":{"npm":"@ai-sdk/google"}},
"glm-5.3": {"id":"glm-5.3","name":"GLM-5.3"}}}
}`
// openCodeGeminiSSE is Zen's own answer on
// /zen/v1/models/gemini-3-flash:streamGenerateContent?alt=sse to "Say hi
// in one word" (2026-10-14), byte for byte but for the thought signature,
// shortened.
const openCodeGeminiSSE = `data: {"createTime":"2026-10-14T12:18:31.471766Z","responseId":"F3PPatblHLDOsbwPqZPe-QU","modelVersion":"gemini-3-flash","candidates":[{"content":{"role":"model","parts":[{"text":"Hi."}]}}],"usageMetadata":{}}
data: {"createTime":"2026-10-14T12:18:31.471766Z","responseId":"F3PPatblHLDOsbwPqZPe-QU","modelVersion":"gemini-3-flash","candidates":[{"finishReason":"STOP","content":{"role":"model","parts":[{"text":"","thoughtSignature":"AY89a18MP3lS4K3OArBbSNxbDAHYyTJ2"}]}}],"usageMetadata":{"candidatesTokensDetails":[{"modality":"TEXT","tokenCount":2}],"promptTokensDetails":[{"modality":"TEXT","tokenCount":5}],"candidatesTokenCount":2,"promptTokenCount":5,"thoughtsTokenCount":67,"totalTokenCount":74}}
`
type openCodeAsk struct {
url, key, auth, session string
body []byte
}
// openCodeGeminiServer answers as OpenCode does (2026-10-14): a Gemini
// model on Gemini's generateContent at /zen/v1 or /inference/go/v1, a
// GLM on chat, and "Model does not support this protocol." for a model
// asked on an API it isn't served on.
func openCodeGeminiServer(t *testing.T, s *Server) func() []openCodeAsk {
t.Helper()
var mu sync.Mutex
var asked []openCodeAsk
s.client = &http.Client{Transport: countTransport(func(r *http.Request) (*http.Response, error) {
b, _ := io.ReadAll(r.Body)
r.Body.Close()
mu.Lock()
asked = append(asked, openCodeAsk{r.URL.Host + r.URL.RequestURI(), r.Header.Get("x-goog-api-key"), r.Header.Get("Authorization"), r.Header.Get("x-opencode-session"), b})
mu.Unlock()
reply := func(code int, ct, body string) (*http.Response, error) {
return &http.Response{StatusCode: code, Header: http.Header{"Content-Type": {ct}}, Body: io.NopCloser(strings.NewReader(body)), Request: r}, nil
}
path := r.URL.Path
gemini := strings.Contains(path, "/models/gemini-")
switch {
case r.Method != http.MethodPost:
return reply(404, "application/json", `{}`)
case gemini && (strings.HasPrefix(path, "/zen/v1/models/") || strings.HasPrefix(path, "/inference/go/v1/models/")):
return reply(200, "text/event-stream", openCodeGeminiSSE)
case strings.Contains(path, ":") || strings.Contains(path, "/models/"):
return reply(404, "text/html", `<html>Not Found</html>`)
case modelOf(b) == "glm-5.3" && strings.HasSuffix(path, "/chat/completions"):
return reply(200, "application/json", `{"id":"c","object":"chat.completion","choices":[{"index":0,"message":{"role":"assistant","content":"from glm"},"finish_reason":"stop"}],"usage":{"prompt_tokens":3,"completion_tokens":2}}`)
}
return reply(400, "application/json", `{"type":"error","error":{"type":"invalid_request_error","message":"Model does not support this protocol."}}`)
})}
return func() []openCodeAsk {
mu.Lock()
defer mu.Unlock()
out := asked
asked = nil
return out
}
}
func urlsOf(asked []openCodeAsk) []string {
var out []string
for _, a := range asked {
out = append(out, a.url)
}
return out
}
func serve(s *Server, path, body string) (int, string) {
rec := httptest.NewRecorder()
s.Handler().ServeHTTP(rec, httptest.NewRequest("POST", path, strings.NewReader(body)))
return rec.Code, rec.Body.String()
}
// #2168 (@bugyaluwang on X too): OpenCode Go's gemini-4-argon-contributor
// went to /zen/go/v1/chat/completions, the one API it isn't served on,
// and Go answered "Model does not support this protocol". models.dev
// lists it for Google's SDK, so it is asked on Gemini's
// streamGenerateContent at /inference/go/v1 (Go's /zen/go/v1 has none),
// signed as OpenCode signs one: the key in x-goog-api-key and the
// conversation in x-opencode-session. Whatever API the client spoke, it
// is answered in it, and a client's reasoning effort is Gemini's
// thinkingLevel.
func TestOpenCodeGoGeminiModelOnGeminiAPI(t *testing.T) {
fresh(t)
writeCatalog(t, openCodeGeminiCatalog)
if err := provider.Save(provider.Provider{ID: "opencode-go", Name: "OpenCode Go", Key: "sk-go", Chat: "https://opencode.ai/zen/go/v1",
Models: []string{"gemini-4-argon-contributor", "glm-5.3"}}); err != nil {
t.Fatal(err)
}
s := New()
took := openCodeGeminiServer(t, s)
const want = "opencode.ai/inference/go/v1/models/gemini-4-argon-contributor:streamGenerateContent?alt=sse"
check := func(what string, code int, body string) openCodeAsk {
t.Helper()
asked := took()
if len(asked) != 1 || asked[0].url != want {
t.Fatalf("%s: asked %v, want %s alone (%d %s)", what, urlsOf(asked), want, code, body)
}
a := asked[0]
if a.key != "sk-go" || a.auth != "" || a.session == "" {
t.Errorf("%s: x-goog-api-key %q Authorization %q x-opencode-session %q", what, a.key, a.auth, a.session)
}
if gjson.GetBytes(a.body, "model").Exists() || !strings.Contains(gjson.GetBytes(a.body, "contents").Raw, "Say hi") {
t.Errorf("%s: body %s", what, a.body)
}
if code != 200 {
t.Errorf("%s: %d %s", what, code, body)
}
return a
}
chat := `{"model":"opencode-go/gemini-4-argon-contributor","messages":[{"role":"user","content":"Say hi in one word"}]}`
code, body := serve(s, "/v1/chat/completions", chat)
first := check("chat", code, body)
if gjson.Get(body, "choices.0.message.content").String() != "Hi." || gjson.Get(body, "usage.prompt_tokens").Int() != 5 {
t.Errorf("chat answer: %s", body)
}
// the next turn of the same conversation keeps its session
code, body = serve(s, "/v1/chat/completions", `{"model":"opencode-go/gemini-4-argon-contributor","messages":[{"role":"user","content":"Say hi in one word"},{"role":"assistant","content":"Hi."},{"role":"user","content":"again"}]}`)
if again := check("chat, next turn", code, body); again.session != first.session {
t.Errorf("session %q then %q", first.session, again.session)
}
code, body = serve(s, "/v1/chat/completions", `{"model":"opencode-go/gemini-4-argon-contributor","stream":true,"messages":[{"role":"user","content":"Say hi in one word"}]}`)
check("chat stream", code, body)
if !strings.Contains(body, `"content":"Hi."`) || !strings.Contains(body, "[DONE]") {
t.Errorf("chat stream answer: %s", body)
}
code, body = serve(s, "/v1/messages", `{"model":"opencode-go/gemini-4-argon-contributor","max_tokens":64,"messages":[{"role":"user","content":"Say hi in one word"}]}`)
check("messages", code, body)
if gjson.Get(body, "content.#(type==\"text\").text").String() != "Hi." {
t.Errorf("messages answer: %s", body)
}
code, body = serve(s, "/v1/responses", `{"model":"opencode-go/gemini-4-argon-contributor","input":"Say hi in one word"}`)
check("responses", code, body)
if !strings.Contains(body, "Hi.") {
t.Errorf("responses answer: %s", body)
}
code, body = serve(s, "/v1beta/models/opencode-go/gemini-4-argon-contributor:generateContent", `{"contents":[{"role":"user","parts":[{"text":"Say hi in one word"}]}]}`)
check("gemini", code, body)
if gjson.Get(body, "candidates.0.content.parts.0.text").String() != "Hi." {
t.Errorf("gemini answer: %s", body)
}
for _, effort := range []string{"low", "medium", "high"} {
code, body = serve(s, "/v1/chat/completions", `{"model":"opencode-go/gemini-4-argon-contributor","reasoning_effort":"`+effort+`","messages":[{"role":"user","content":"Say hi in one word"}]}`)
a := check("effort "+effort, code, body)
if got := gjson.GetBytes(a.body, "generationConfig.thinkingConfig.thinkingLevel").String(); got != effort {
t.Errorf("effort %s: thinkingLevel %q in %s", effort, got, gjson.GetBytes(a.body, "generationConfig").Raw)
}
}
}
// The sibling at Zen: its Gemini models (gemini-3-flash here) are asked
// on Gemini's generateContent at /zen/v1, which relays them to Google.
// Each provider's other models stay on the API the client spoke: a GLM
// is never asked on Gemini's.
func TestOpenCodeZenGeminiAndOtherModelsUnchanged(t *testing.T) {
fresh(t)
writeCatalog(t, openCodeGeminiCatalog)
for _, p := range []provider.Provider{
{ID: "opencode-zen", Name: "OpenCode Zen", Key: "sk-zen", Chat: "https://opencode.ai/zen/v1", Models: []string{"gemini-3-flash", "glm-5.3", "kimi-k3"}},
{ID: "opencode-go", Name: "OpenCode Go", Key: "sk-go", Chat: "https://opencode.ai/zen/go/v1", Models: []string{"gemini-4-argon-contributor", "glm-5.3"}},
} {
if err := provider.Save(p); err != nil {
t.Fatal(err)
}
}
s := New()
took := openCodeGeminiServer(t, s)
code, body := serve(s, "/v1/chat/completions", `{"model":"opencode-zen/gemini-3-flash","messages":[{"role":"user","content":"Say hi in one word"}]}`)
asked := took()
if len(asked) != 1 || asked[0].url != "opencode.ai/zen/v1/models/gemini-3-flash:streamGenerateContent?alt=sse" || asked[0].key != "sk-zen" || asked[0].session == "" {
t.Errorf("zen gemini: asked %v (%d %s)", urlsOf(asked), code, body)
}
if code != 200 || gjson.Get(body, "choices.0.message.content").String() != "Hi." {
t.Errorf("zen gemini: %d %s", code, body)
}
for _, id := range []string{"opencode-zen", "opencode-go"} {
code, body := serve(s, "/v1/chat/completions", `{"model":"`+id+`/glm-5.3","messages":[{"role":"user","content":"hi"}]}`)
asked := took()
root := map[string]string{"opencode-zen": "opencode.ai/zen/v1", "opencode-go": "opencode.ai/zen/go/v1"}[id]
if len(asked) != 1 || asked[0].url != root+"/chat/completions" || asked[0].auth != "Bearer "+map[string]string{"opencode-zen": "sk-zen", "opencode-go": "sk-go"}[id] {
t.Errorf("%s glm: asked %v", id, urlsOf(asked))
}
if code != 200 || gjson.Get(body, "choices.0.message.content").String() != "from glm" {
t.Errorf("%s glm: %d %s", id, code, body)
}
}
// a model the list names no API for, turned away on all three, is
// still never tried on Gemini's: that serves the Gemini models alone
code, body = serve(s, "/v1/chat/completions", `{"model":"opencode-zen/kimi-k3","messages":[{"role":"user","content":"hi"}]}`)
for _, a := range took() {
if strings.Contains(a.url, "/models/") {
t.Errorf("kimi-k3 asked on Gemini's API: %s (%d %s)", a.url, code, body)
}
}
}
+6
View File
@@ -663,6 +663,12 @@ func (p Provider) fetchOne(ctx context.Context) (fetched, error) {
if p.Gemini == "" {
continue // Factory's, whose list is its sign-in's
}
if p.IsOpenCode() {
// OpenCode's Gemini models are in the list its other
// APIs share, asked at its chat URL; it has no Gemini
// list of its own
continue
}
// listed as the Gemini API lists them, the key in its header,
// and merged like any other protocol's list (#1346)
asked[protoBase] = true
+36 -10
View File
@@ -7,9 +7,11 @@ import (
)
// openCodeRoot is the root of OpenCode's gateway a base URL is at — Zen's
// (https://opencode.ai/zen) or Go's (…/zen/go), given with /v1 or without —
// and the models.dev provider that lists its models: opencode or
// opencode-go. Both are "" for any other URL.
// (https://opencode.ai/zen) or Go's (…/zen/go), or the inference API's
// that serves the same paths (…/inference, …/inference/go: models.dev's
// URL for both since October 2026), given with /v1 or without — and the
// models.dev provider that lists its models: opencode or opencode-go.
// Both are "" for any other URL.
func openCodeRoot(base string) (root, catalogID string) {
u, err := url.Parse(strings.TrimRight(strings.TrimSpace(base), "/"))
if err != nil || u.Scheme == "" {
@@ -19,29 +21,44 @@ func openCodeRoot(base string) (root, catalogID string) {
return "", ""
}
switch path := strings.TrimSuffix(strings.TrimRight(u.Path, "/"), "/v1"); path {
case "/zen/go":
case "/zen/go", "/inference/go":
return u.Scheme + "://" + u.Host + path, "opencode-go"
case "/zen":
case "/zen", "/inference":
return u.Scheme + "://" + u.Host + path, "opencode"
}
return "", ""
}
// openCodeGemini is the base of Gemini's generateContent at the gateway
// root is: models/{model}:streamGenerateContent is asked under it. Zen's
// /zen/v1 relays it to the inference API's Google route, reading the key
// from x-goog-api-key; Go's /zen/go/v1 has no such route (404), so Go's
// Gemini models are asked at the inference API's /inference/go/v1, where
// Go's docs give their endpoint (opencode.ai/v2/docs/console/go, #2168).
func openCodeGemini(root string) string {
if r, ok := strings.CutSuffix(root, "/zen/go"); ok {
return r + "/inference/go/v1"
}
return root + "/v1"
}
// openCodeEndpoints fills in the APIs of OpenCode's gateway a provider at
// it was saved without. Zen and Go serve each model on one API of three,
// all under one root — chat completions and Responses at /v1, Anthropic's
// Messages at the root — and turn it away on the other two. OpenCode asks
// a model through the AI SDK package models.dev's per-model provider.npm
// names: @ai-sdk/openai (Responses) for GPT, Grok and Muse Spark,
// @ai-sdk/anthropic (Messages) for Claude, MiniMax and some Qwen, and
// @ai-sdk/anthropic (Messages) for Claude, MiniMax and some Qwen,
// @ai-sdk/google (Gemini's generateContent) for Gemini, and
// @ai-sdk/openai-compatible (chat) for the rest. A provider at Go added by
// hand or brought from another app with its chat URL alone had nowhere
// but chat to send GPT, Grok, MiniMax or Muse Spark, which Go answers
// with "Model does not support this protocol" (#1215). A URL the user gave
// an API keeps it, and so does a catalog they named.
// with "Model does not support this protocol" (#1215), and none had
// anywhere but those three to send a Gemini model (#2168). A URL the user
// gave an API keeps it, and so does a catalog they named.
func (p *Provider) openCodeEndpoints() {
root, catalogID := "", ""
for _, u := range []string{p.Chat, p.Responses, p.Anthropic} {
for _, u := range []string{p.Chat, p.Responses, p.Anthropic, p.Gemini} {
if root, catalogID = openCodeRoot(u); root != "" {
break
}
@@ -52,6 +69,7 @@ func (p *Provider) openCodeEndpoints() {
p.Chat = cmp.Or(p.Chat, root+"/v1")
p.Responses = cmp.Or(p.Responses, root+"/v1")
p.Anthropic = cmp.Or(p.Anthropic, root)
p.Gemini = cmp.Or(p.Gemini, openCodeGemini(root))
p.Catalog = cmp.Or(p.Catalog, catalogID)
}
@@ -61,10 +79,18 @@ func (p *Provider) openCodeEndpoints() {
// saved with — the two serve one model on different APIs (MiniMax M2.7 on
// Messages at Go, on chat at Zen) — or, at another path, its own.
func (p Provider) openCodeCatalogs() []string {
for _, u := range []string{p.Chat, p.Responses, p.Anthropic} {
for _, u := range []string{p.Chat, p.Responses, p.Anthropic, p.Gemini} {
if _, id := openCodeRoot(u); id != "" {
return []string{id}
}
}
return p.Catalogs()
}
// NamedOnlyOn is whether p serves on proto only the models its list names
// that API for, so that one it names none for isn't asked there:
// OpenCode's Gemini API, which serves the Gemini models alone (each of
// OpenCode's models is served on one API family, its inference docs say).
// The rest are asked on chat, Responses or Messages, as before it had a
// Gemini URL (#2168).
func (p Provider) NamedOnlyOn(proto Protocol) bool { return proto == Gemini && p.IsOpenCode() }
+41 -23
View File
@@ -10,10 +10,13 @@ import (
)
// #1215: a provider at OpenCode's gateway saved with one URL gets the
// other two of that gateway's, and the models.dev list of the gateway its
// other APIs of that gateway's, and the models.dev list of the gateway its
// URL is at says which API each model goes on — Go's list for Go and
// Zen's for Zen, even when it was saved with the other's catalog. A URL
// or catalog the user gave stays theirs, and other hosts are left alone.
// #2168: Gemini's generateContent is one of them — Zen's at /zen/v1, Go's
// at the inference API's /inference/go/v1 (/zen/go/v1 has no such route)
// — and a model listed for Google's SDK goes on it.
func TestOpenCodeEndpointsFilledIn(t *testing.T) {
isolate(t)
t.Setenv("HOME", t.TempDir())
@@ -22,15 +25,17 @@ func TestOpenCodeEndpointsFilledIn(t *testing.T) {
cache := t.TempDir()
t.Setenv("XDG_CACHE_HOME", cache)
os.MkdirAll(filepath.Join(cache, "magpie"), 0o755)
// as models.dev lists them (2026-10-08): MiniMax M2.7 is Anthropic's
// SDK on Go and the OpenAI-compatible one on Zen
// as models.dev lists them (2026-10-08, Gemini 2026-10-14): MiniMax
// M2.7 is Anthropic's SDK on Go and the OpenAI-compatible one on Zen
if err := os.WriteFile(catalog.CachePath(), []byte(`{
"opencode-go": {"models": {
"gpt-6-luna": {"id":"gpt-6-luna","provider":{"npm":"@ai-sdk/openai"}},
"minimax-m2.7": {"id":"minimax-m2.7","provider":{"npm":"@ai-sdk/anthropic"}},
"gemini-4-argon-contributor": {"id":"gemini-4-argon-contributor","provider":{"npm":"@ai-sdk/google"}},
"glm-5.3": {"id":"glm-5.3"}}},
"opencode": {"models": {
"claude-opus-5": {"id":"claude-opus-5","provider":{"npm":"@ai-sdk/anthropic"}},
"gemini-3-flash": {"id":"gemini-3-flash","provider":{"npm":"@ai-sdk/google"}},
"minimax-m2.7": {"id":"minimax-m2.7"}}}
}`), 0o644); err != nil {
t.Fatal(err)
@@ -38,40 +43,53 @@ func TestOpenCodeEndpointsFilledIn(t *testing.T) {
catalog.Reset()
t.Cleanup(catalog.Reset)
const zg, zen, igo, inf = "https://opencode.ai/zen/go", "https://opencode.ai/zen", "https://opencode.ai/inference/go", "https://opencode.ai/inference"
for _, tc := range []struct {
name string
in Provider
chat, responses, anthropic, catlog string
apis map[string]Protocol // "" for none named
name string
in Provider
chat, responses, anthropic, gemini, catlog string
apis map[string]Protocol // "" for none named
}{
{"go, chat alone", Provider{ID: "opencode-go", Chat: "https://opencode.ai/zen/go/v1"},
"https://opencode.ai/zen/go/v1", "https://opencode.ai/zen/go/v1", "https://opencode.ai/zen/go", "opencode-go",
map[string]Protocol{"gpt-6-luna": Responses, "minimax-m2.7": Anthropic, "glm-5.3": ""}},
{"go, anthropic alone with /v1", Provider{ID: "ocgo", Anthropic: "https://opencode.ai/zen/go/v1"},
"https://opencode.ai/zen/go/v1", "https://opencode.ai/zen/go/v1", "https://opencode.ai/zen/go", "opencode-go",
{"go, chat alone", Provider{ID: "opencode-go", Chat: zg + "/v1"},
zg + "/v1", zg + "/v1", zg, igo + "/v1", "opencode-go",
map[string]Protocol{"gpt-6-luna": Responses, "minimax-m2.7": Anthropic, "gemini-4-argon-contributor": Gemini, "glm-5.3": ""}},
{"go, anthropic alone with /v1", Provider{ID: "ocgo", Anthropic: zg + "/v1"},
zg + "/v1", zg + "/v1", zg, igo + "/v1", "opencode-go",
map[string]Protocol{"gpt-6-luna": Responses}},
{"zen saved with go's catalog", Provider{ID: "opencode-go", Catalog: "opencode-go", Chat: "https://opencode.ai/zen/v1"},
"https://opencode.ai/zen/v1", "https://opencode.ai/zen/v1", "https://opencode.ai/zen", "opencode-go",
map[string]Protocol{"claude-opus-5": Anthropic, "minimax-m2.7": ""}},
{"a URL of the user's own stays", Provider{ID: "oc", Chat: "https://opencode.ai/zen/go/v1", Responses: "https://proxy.test/go/v1"},
"https://opencode.ai/zen/go/v1", "https://proxy.test/go/v1", "https://opencode.ai/zen/go", "opencode-go", nil},
{"go at the inference API", Provider{ID: "ocgo", Chat: igo + "/v1"},
igo + "/v1", igo + "/v1", igo, igo + "/v1", "opencode-go",
map[string]Protocol{"gemini-4-argon-contributor": Gemini, "glm-5.3": ""}},
{"zen saved with go's catalog", Provider{ID: "opencode-go", Catalog: "opencode-go", Chat: zen + "/v1"},
zen + "/v1", zen + "/v1", zen, zen + "/v1", "opencode-go",
map[string]Protocol{"claude-opus-5": Anthropic, "gemini-3-flash": Gemini, "minimax-m2.7": ""}},
{"zen at the inference API", Provider{ID: "oc", Chat: inf},
inf, inf + "/v1", inf, inf + "/v1", "opencode",
map[string]Protocol{"gemini-3-flash": Gemini}},
{"a URL of the user's own stays", Provider{ID: "oc", Chat: zg + "/v1", Responses: "https://proxy.test/go/v1", Gemini: "https://proxy.test/gemini"},
zg + "/v1", "https://proxy.test/go/v1", zg, "https://proxy.test/gemini", "opencode-go", nil},
{"another relay", Provider{ID: "relay", Catalog: "opencode-go", Chat: "https://relay.test/v1"},
"https://relay.test/v1", "", "", "opencode-go",
"https://relay.test/v1", "", "", "", "opencode-go",
map[string]Protocol{"gpt-6-luna": ""}},
{"another path at opencode.ai", Provider{ID: "oc-other", Chat: "https://opencode.ai/other/v1"},
"https://opencode.ai/other/v1", "", "", "", nil},
"https://opencode.ai/other/v1", "", "", "", "", nil},
} {
p := normalize(tc.in)
if p.Chat != tc.chat || p.Responses != tc.responses || p.Anthropic != tc.anthropic || p.Catalog != tc.catlog {
t.Errorf("%s: chat %q responses %q anthropic %q catalog %q", tc.name, p.Chat, p.Responses, p.Anthropic, p.Catalog)
if p.Chat != tc.chat || p.Responses != tc.responses || p.Anthropic != tc.anthropic || p.Gemini != tc.gemini || p.Catalog != tc.catlog {
t.Errorf("%s: chat %q responses %q anthropic %q gemini %q catalog %q", tc.name, p.Chat, p.Responses, p.Anthropic, p.Gemini, p.Catalog)
}
for model, want := range tc.apis {
got := p.APIs(model)
if want == "" && got != nil || want != "" && !slices.Equal(got, []Protocol{want}) {
t.Errorf("%s: %s APIs %v, want %q", tc.name, model, got, want)
}
if want != "" && p.Native(model) != want {
t.Errorf("%s: %s native %q, want %q", tc.name, model, p.Native(model), want)
// a Gemini model has no API of the three a client asks it on
// as it is: every request to it is translated
native := want
if want == Gemini {
native = ""
}
if want != "" && p.Native(model) != native {
t.Errorf("%s: %s native %q, want %q", tc.name, model, p.Native(model), native)
}
}
}
+1 -1
View File
@@ -382,7 +382,7 @@ func (p Provider) testModel(q Provider, proto Protocol) string {
if apis := p.APIs(id); apis != nil {
return slices.Contains(apis, proto)
}
return proto != Anthropic || isClaude(id)
return (proto != Anthropic || isClaude(id)) && !p.NamedOnlyOn(proto)
},
func(string) bool { return true },
} {