Skip to content

Commit e7a6408

Browse files
opencodeendolith
authored andcommitted
fix: recognise real OpenCode Go keys, and correct the Go catalog
Two things in the opencode_go/ support were wrong, and both were wrong because they were written from assumption rather than from the published behaviour. The docs (opencode.ai/docs/go) and the OpenCode repo itself settle both. **Go keys are `sk-`, not `oc_`.** The console's `Key.create` produces `sk-` plus 64 characters, and anomalyco/opencode#40343 describes a Go key as "sk-... API key from the Zen console". `_is_opencode_go_key` only recognised `oc_`, so a valid Go key saved in a profile was classified as foreign, discarded, and replaced with a "set OPENCODE_GO_API_KEY" error -- meaning the profile route the documentation recommends could never work. It appeared to work only because the environment variable was set. That fix exposes a design flaw underneath: the guard existed to stop a foreign profile key reaching the gateway, but Go, OpenAI, Anthropic and DashScope keys all start with `sk-`, so no prefix can separate them. The shape test is kept (oc_ is still accepted, and it rejects obvious non-credentials) but it no longer decides precedence. That is now stated flatly: an explicit OPENCODE_GO_API_KEY wins, else a Go-shaped profile key, else a loud failure. The trade-off is deliberate -- a wrongly rejected Go key blocks a working setup, whereas a genuinely foreign key still produces the gateway's own "Invalid API key.", which is self-explanatory now that the docs say a Go key looks like an OpenAI one. Two tests encoded the old premise (treating `sk-` as the foreign shape) and were corrected rather than worked around; their docstrings record why, so the change is not silently reverted. test_go_shaped_profile_key_is_kept is deleted as redundant: under the flat precedence its scenario is covered in both directions by the new tests. **The model lists had drifted.** The Qwen ids were generated with `range(5, 9)` over `qwen3.{n}-{plus,max}`, which invented models that do not exist (qwen3.5-plus, qwen3.6-max, qwen3.8-plus) while depending on the range happening to line up. They are now explicit, transcribed from the endpoint table: messages = minimax-m2.5/2.7/m3 and qwen3.6-plus, qwen3.7-{plus,max}, qwen3.8-{flash,max}; responses = grok-4.6/4.7, gpt-5.6-luna, gpt-6-luna, muse-spark-1.2/1.3-contributor. A test asserts the three lists partition the catalog and that no model appears in two, and every documented chat-completions model is parametrised through load() so one wrongly classified as unsupported fails here rather than at request time. **Vision was a silent downgrade.** LiteLLM has no entry for the `openai/<go-model>` spelling, so its vision probe reports False for every Go model, and OI renders images to text descriptions instead of sending them -- no error to notice. `deepseek-v4-flash-vision-exp` is now answered for explicitly. The list is one entry because only "vision" in the published name marks a model as multimodal; claiming vision for a text-only model would just move the failure. Docs updated: the profile-key path, the `sk-` ambiguity and what to check on `Invalid API key.`, the corrected endpoint families, and where the live catalog lives. Suite unchanged at the known baseline of 14.
1 parent 717cf2b commit e7a6408

3 files changed

Lines changed: 284 additions & 53 deletions

File tree

‎docs/settings/all-settings.mdx‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,11 @@ llm:
243243

244244
Use an OpenCode Go subscription by prefixing the model with `opencode_go/`. Set
245245
`OPENCODE_GO_API_KEY` to your key from [opencode.ai](https://opencode.ai/docs/go/)
246-
(not your OpenAI key — it is a different credential).
246+
(not your OpenAI key — it is a different credential). A key saved in your profile
247+
as `llm.api_key` also works; if both are set, `OPENCODE_GO_API_KEY` wins. Note
248+
that a Go key starts with `sk-` just like an OpenAI one, so the two cannot be
249+
told apart automatically — if a request fails with `Invalid API key.`, check
250+
that the key in your profile really is the Go one.
247251

248252
<CodeGroup>
249253

@@ -258,6 +262,7 @@ interpreter.llm.model = "opencode_go/deepseek-v4-flash"
258262
```yaml Profile
259263
llm:
260264
model: opencode_go/deepseek-v4-flash
265+
api_key: sk-...
261266
```
262267

263268
</CodeGroup>
@@ -267,10 +272,18 @@ stable per-conversation id so provider routing and prompt caching stay warm. A
267272
`%reset` starts a new conversation and therefore a new session id.
268273

269274
Go serves each model over one specific endpoint. Open Interpreter speaks chat
270-
completions, so the DeepSeek, GLM, Kimi, MiMo and Hy3 families work. MiniMax and
271-
Qwen models are only served over Anthropic messages, and Grok/GPT-5.6-Luna over
272-
the OpenAI responses API; selecting one of those raises an error rather than
273-
letting the gateway quietly answer with a different model.
275+
completions, so the DeepSeek, GLM, Kimi, MiMo, LongCat and Hy families work.
276+
MiniMax and Qwen models are only served over Anthropic messages, and Grok,
277+
GPT-5.6-Luna, GPT-6-Luna and Muse Spark over the OpenAI responses API; selecting
278+
one of those raises an error rather than letting the gateway quietly answer with
279+
a different model.
280+
281+
LiteLLM does not know these model ids, so Open Interpreter answers for the ones
282+
whose capability would otherwise be silently wrong: `deepseek-v4-flash-vision-exp`
283+
is treated as vision-capable, and without that its images would be replaced by
284+
text descriptions with no error. Other Go models are left to auto-detection.
285+
`GET https://opencode.ai/zen/go/v1/models` returns the live catalog if you want
286+
to confirm what is currently served.
274287

275288
Override the default base URL with `OPENCODE_GO_API_BASE` or `llm.api_base`. A
276289
base URL left over from a different provider (an `api_base` in your profile, or

‎interpreter/core/llm/llm.py‎

Lines changed: 61 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,23 @@ class AccessDeniedError(Exception):
7575
# Source: https://opencode.ai/docs/go/ (endpoint table), which also serves the
7676
# live list at https://opencode.ai/zen/go/v1/models.
7777
_OPENCODE_GO_DEFAULT_BASE = "https://opencode.ai/zen/go/v1"
78+
# Go models that are NOT served over /chat/completions, keyed by the wire format
79+
# they do use. Taken from the endpoint table in opencode.ai/docs/go (retrieved
80+
# 2026-09-29); the live catalog is also at GET https://opencode.ai/zen/go/v1/models.
81+
# LiteLLM has no entry for these ids, so OI has to carry the fact itself.
82+
#
83+
# Everything else in the Go catalog -- glm-*, kimi-*, mimo-*, longcat-*, hy*,
84+
# deepseek-v4*, space-bunny-free -- is chat/completions and works unmodified.
7885
_OPENCODE_GO_MESSAGES_MODELS = frozenset(
7986
{
8087
"minimax-m2.5",
8188
"minimax-m2.7",
8289
"minimax-m3",
90+
"qwen3.6-plus",
91+
"qwen3.7-max",
92+
"qwen3.7-plus",
8393
"qwen3.8-flash",
84-
*(f"qwen3.{n}-{tier}" for n in range(5, 9) for tier in ("plus", "max")),
94+
"qwen3.8-max",
8595
}
8696
)
8797
_OPENCODE_GO_RESPONSES_MODELS = frozenset(
@@ -94,6 +104,16 @@ class AccessDeniedError(Exception):
94104
"muse-spark-1.3-contributor",
95105
}
96106
)
107+
# Go models that accept image input. LiteLLM's registry does not know the Go
108+
# ids, so `litellm.supports_vision` returns False for all of them and OI would
109+
# silently render images to text descriptions instead of sending them -- a
110+
# capability loss with no error. Only "vision" in the published name marks a Go
111+
# model as multimodal, so the list is deliberately small rather than guessed.
112+
_OPENCODE_GO_VISION_MODELS = frozenset(
113+
{
114+
"deepseek-v4-flash-vision-exp",
115+
}
116+
)
97117

98118

99119
def _is_opencode_go_base(api_base):
@@ -117,13 +137,24 @@ def _is_opencode_go_base(api_base):
117137
def _is_opencode_go_key(api_key):
118138
"""Whether an already-configured api_key is shaped like an OpenCode credential.
119139
120-
OpenCode issues keys starting with ``oc_`` (``oc_sk_...``). Anything else is
121-
assumed to belong to another provider, so that stale keys from the profile --
122-
an OpenAI key left there by OI's onboarding, for example -- cannot be sent
123-
to the gateway instead of OPENCODE_GO_API_KEY. Sending a foreign key yields
124-
exactly ``Invalid API key.``, which blames the Go key that never arrived.
140+
OpenCode issues Zen/Go keys as ``sk-`` followed by 64 characters (see the
141+
console's ``Key.create`` in anomalyco/opencode, and anomalyco/opencode#40343,
142+
where a Go key is described as "sk-... API key from the Zen console"). An
143+
earlier version of this assumed an ``oc_`` prefix and consequently treated
144+
every real Go key as foreign, so a key saved in a profile was discarded and
145+
the user was told to set ``OPENCODE_GO_API_KEY`` instead -- the profile path
146+
documented in docs/settings/all-settings.mdx could not work.
147+
148+
``oc_`` is still accepted: it is accepted by the gateway, and profiles
149+
written when that was assumed may hold such a value.
150+
151+
Note the limit of prefix matching here: ``sk-`` is also OpenAI's own format,
152+
so this cannot actually tell a Go key from an OpenAI one. It only rejects
153+
keys that are neither shape. That asymmetry is deliberate -- wrongly
154+
rejecting a valid Go key blocks a working configuration, while a genuinely
155+
foreign key still fails with the gateway's own clear "Invalid API key."
125156
"""
126-
return bool(api_key) and api_key.lower().startswith(("oc_",))
157+
return bool(api_key) and api_key.lower().startswith(("sk-", "oc_"))
127158

128159
# Models already warned about during this process when both a reasoning_effort and
129160
# include_reasoning: false are configured. That combination cannot take effect (a
@@ -865,22 +896,23 @@ def load(self):
865896
go_base = os.environ.get("OPENCODE_GO_API_BASE", _OPENCODE_GO_DEFAULT_BASE)
866897
if self.api_base is None or not _is_opencode_go_base(self.api_base):
867898
self.api_base = go_base
868-
# Same reasoning as api_base: the profile may still hold an api_key
869-
# saved for a different provider (often an OpenAI key from OI's
870-
# onboarding). Sending that to the Go gateway produces exactly
871-
# "Invalid API key." at 401, which blames the Go key the user set
872-
# via the environment but never reaches the gateway. An explicit
873-
# OPENCODE_GO_API_KEY therefore wins over a non-Go-shaped profile
874-
# key; a Go-shaped key the user put in the profile is kept.
875-
if self.api_key is None or not _is_opencode_go_key(self.api_key):
876-
env_key = os.environ.get("OPENCODE_GO_API_KEY")
877-
if env_key:
878-
self.api_key = env_key
879-
# Without an override, a non-Go-shaped profile key cannot be
880-
# sent to the gateway; leaving it in place would repeat the
881-
# "Invalid API key." failure the check above exists to prevent.
882-
elif self.api_key is not None and not _is_opencode_go_key(self.api_key):
883-
self.api_key = None
899+
# Precedence is: an explicit OPENCODE_GO_API_KEY, then a Go-shaped key
900+
# already in the profile, then a loud failure.
901+
#
902+
# The shape test cannot be the deciding vote. Go keys are `sk-`, and so
903+
# are OpenAI, Anthropic and DashScope keys, so no prefix separates a
904+
# Go credential from a foreign one -- the original design assumed they
905+
# differed (an `oc_` prefix), which silently discarded every real Go
906+
# key saved in a profile. A weak signal must therefore never override
907+
# an explicit choice: when the environment variable is set it wins,
908+
# and a profile key is only discarded when it is not recognisable at
909+
# all, which leaves the loud error below rather than a 401 from the
910+
# gateway blaming a key the user believes they set correctly.
911+
env_key = os.environ.get("OPENCODE_GO_API_KEY")
912+
if env_key:
913+
self.api_key = env_key
914+
elif not _is_opencode_go_key(self.api_key):
915+
self.api_key = None
884916
if not self.api_key:
885917
raise ValueError(
886918
"The opencode_go/ model prefix requires an OpenCode Go API key. "
@@ -894,6 +926,12 @@ def load(self):
894926
# passes the check but earns no caching. The value is filled in per
895927
# request (see run()) rather than stored here, so that it tracks
896928
# conversation_id when %reset mints a new one.
929+
# LiteLLM does not know the openai/<go-model> spelling, so its vision
930+
# probe reports False for every Go model; without this a Go model
931+
# that does take images would have them replaced by text
932+
# descriptions, silently and without an error.
933+
if model_name in _OPENCODE_GO_VISION_MODELS and self.supports_vision is None:
934+
self.supports_vision = True
897935
self._is_opencode_go = True
898936
self.model = f"openai/{model_name}"
899937

0 commit comments

Comments
 (0)