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.
97 lines
4.1 KiB
Go
97 lines
4.1 KiB
Go
package provider
|
|
|
|
import (
|
|
"cmp"
|
|
"net/url"
|
|
"strings"
|
|
)
|
|
|
|
// openCodeRoot is the root of OpenCode's gateway a base URL is at — Zen's
|
|
// (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 == "" {
|
|
return "", ""
|
|
}
|
|
if h := strings.ToLower(u.Hostname()); h != "opencode.ai" && !strings.HasSuffix(h, ".opencode.ai") {
|
|
return "", ""
|
|
}
|
|
switch path := strings.TrimSuffix(strings.TrimRight(u.Path, "/"), "/v1"); path {
|
|
case "/zen/go", "/inference/go":
|
|
return u.Scheme + "://" + u.Host + path, "opencode-go"
|
|
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,
|
|
// @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), 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, p.Gemini} {
|
|
if root, catalogID = openCodeRoot(u); root != "" {
|
|
break
|
|
}
|
|
}
|
|
if root == "" {
|
|
return
|
|
}
|
|
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)
|
|
}
|
|
|
|
// openCodeCatalogs are the models.dev providers that say which API a model
|
|
// of OpenCode's gateway is served on: the list of the gateway its URL is
|
|
// at (Go's for Go, Zen's for Zen) alone, whatever catalog the provider was
|
|
// 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, 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() }
|