opencode: Model auto-discovery - #60373
Conversation
Enum shows nicer errors to users than a random String
As per [OpenCode developer on Discord](https://discord.com/channels/1391832426048651334/1471233160993050918/1472020924881702912), "almost all models worth using support parallel tool calling natively". Manual tests confirmed all OpenCode Go models support this correctly (and was enabled by default for all but 1 model)
NOT TESTED but matches the google_ai behavior
- Remove hardcoded models - Use a Struct for models instead of an Enum - Remove default models (confusion as per zed-industries#56855) and matches Ollama - Generic cleanup and fixes after the ton of code removed + preparation for the next commit
This is an embarrassing one 🤦
Still keeping just "Failed parsing models.dev data" in the UI because the full error might be huge/confusing
Model fetch already happens on init and we don't need authentication to get models so there's no point in spawning yet another task to get models
|
FYI: Models.dev will sometime in the future get a new V2 API/schema: anomalyco/models.dev#3037 |
|
Yeah, no, I am closing this PR — testing the reliability and accuracy of Models.dev on Zed users is, in my opinion, a disgusting proposal. I appreciate and love using Zed for LLM-assisted development because Zed is somewhat more stable (not bleeding edge with a ton of experimental features that get added and removed every day and that force users to adopt&change their workflow regularly, but not many months behind either) and well thought out (for example, Zed wasn't the first to have parallel agents but when Zed added parallel agents it was fabulously integrated and a great experience) and this PR is completely against that. As a user, I would much rather have outdated models / have to define a Custom OpenCode model myself than getting a broken list of models or broken model configs. The bugfixes and tiny enhancements from this PR will be added in a new PR which will also update the models (adding reasoning levels to all models). I'll do that on Monday/Tuesday 🤞 When OpenCode V2 launches and when Models.dev V2 launches and is used by OpenCode and is shown to be stable, the model auto-discovery implementation from this PR can be resurrected, maybe with a toggle between "Use hard-coded model configurations" and "Use Models.dev to auto-discover model configurations". Apologies for the churn! |
**TL;DR**: model updates + reasoning levels + fixes discovered when working on zed-industries#60373 # Objective Since the model auto-discovery PR was [cancelled](zed-industries#60373 (comment)), here is a manual model list update! I also copied the stand-alone bugfixes/enhancements from that PR. ## Solution A lot of manual work 😅 **OpenCode Zen**: - added Fable 5 and Sonnet 5 - added models that were previously only available on OpenCode Go: GLM 5.2, Kimi K2.7 Code, and Minimax M3 - added reasoning levels for all models. I started from the data on [`Models.dev`](https://models.dev) (the `/api.json` raw data), and then I matched that with what is shown in the OpenCode CLI and what I know to be true **OpenCode Go**: - added reasoning levels for GLM 5.2 **OpenCode in general**: - added `protocol` validation for the settings, by moving from a random `String` to an `enum`, for both nicer error messages (random strings or typos will get an error instead of using `openai_chat` by default) and to avoid issues like [folks saying non-existent protocols are a thing](zed-industries#56869 (comment)) - enabled parallel tool calls by default. As per [OpenCode developer on Discord](https://discord.com/channels/1391832426048651334/1471233160993050918/1472020924881702912), _"almost all models worth using support parallel tool calling natively"_. Manual tests confirmed all OpenCode Go models support this correctly (and was enabled by default on the OpenCode side for all but 1 model). I initially wanted to skip this from the release notes, but I added it so folks are aware of it in case any issues are caused by this being enabled for all models - allegedly fixed Google thinking since reasoning levels / thinking effort levels were added for Google models and an auto-checker LLM highlighted that was not properly configured - added support for the new-ish `supports_disabling_thinking` so thinking-only models don't get a no-impact toggle to disable thinking I have no idea if any of the Free models will disappear in 2 days or not, so I did not update those 🤷 (as per decision in zed-industries#56869 (comment)) ## Testing The Zen and Google changes were not tested as I don't have a Zen subscription and I stubbornly refuse to get one. The Free&Go changes were tested by running a "_rename this variable for me. add a function. delete the function_" test with a few different models. ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [ ] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable --- Release Notes: - Agent: OpenCode settings now validate `protocol` values - Agent: OpenCode only shows the "Disable thinking" toggle if thinking can indeed be disabled/enabled - Agent: OpenCode models now enable parallel tool calls by default - Agent: Updated OpenCode Zen models (added Fable 5, Sonnet 5, GLM 5.2, Kimi K2.7 Code, and Minimax M3) - Agent: Added OpenCode Go GLM 5.2 reasoning effort levels - Agent: Added reasoning effort levels for all OpenCode Zen models - Agent: Fixed thinking for OpenCode Zen Google models
|
FYI: it looks like a bigger API revamp is happening as part of OpenCode V2: potentially moving to |
|
As always, thanks for your work on OpenCode support in Zed @Vlaaaaaaad |
**TL;DR**: model updates + reasoning levels + fixes discovered when working on zed-industries#60373 # Objective Since the model auto-discovery PR was [cancelled](zed-industries#60373 (comment)), here is a manual model list update! I also copied the stand-alone bugfixes/enhancements from that PR. ## Solution A lot of manual work 😅 **OpenCode Zen**: - added Fable 5 and Sonnet 5 - added models that were previously only available on OpenCode Go: GLM 5.2, Kimi K2.7 Code, and Minimax M3 - added reasoning levels for all models. I started from the data on [`Models.dev`](https://models.dev) (the `/api.json` raw data), and then I matched that with what is shown in the OpenCode CLI and what I know to be true **OpenCode Go**: - added reasoning levels for GLM 5.2 **OpenCode in general**: - added `protocol` validation for the settings, by moving from a random `String` to an `enum`, for both nicer error messages (random strings or typos will get an error instead of using `openai_chat` by default) and to avoid issues like [folks saying non-existent protocols are a thing](zed-industries#56869 (comment)) - enabled parallel tool calls by default. As per [OpenCode developer on Discord](https://discord.com/channels/1391832426048651334/1471233160993050918/1472020924881702912), _"almost all models worth using support parallel tool calling natively"_. Manual tests confirmed all OpenCode Go models support this correctly (and was enabled by default on the OpenCode side for all but 1 model). I initially wanted to skip this from the release notes, but I added it so folks are aware of it in case any issues are caused by this being enabled for all models - allegedly fixed Google thinking since reasoning levels / thinking effort levels were added for Google models and an auto-checker LLM highlighted that was not properly configured - added support for the new-ish `supports_disabling_thinking` so thinking-only models don't get a no-impact toggle to disable thinking I have no idea if any of the Free models will disappear in 2 days or not, so I did not update those 🤷 (as per decision in zed-industries#56869 (comment)) ## Testing The Zen and Google changes were not tested as I don't have a Zen subscription and I stubbornly refuse to get one. The Free&Go changes were tested by running a "_rename this variable for me. add a function. delete the function_" test with a few different models. ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [ ] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable --- Release Notes: - Agent: OpenCode settings now validate `protocol` values - Agent: OpenCode only shows the "Disable thinking" toggle if thinking can indeed be disabled/enabled - Agent: OpenCode models now enable parallel tool calls by default - Agent: Updated OpenCode Zen models (added Fable 5, Sonnet 5, GLM 5.2, Kimi K2.7 Code, and Minimax M3) - Agent: Added OpenCode Go GLM 5.2 reasoning effort levels - Agent: Added reasoning effort levels for all OpenCode Zen models - Agent: Fixed thinking for OpenCode Zen Google models
TL;DR: now that
models.devdata is not 100% terrible, automatically fill the OpenCode model list.Objective
This will avoid all the "Zed is missing models from OpenCode because the list is hardcoded" issues. See #56869 (comment) for a short overview or #55359, #54589, #58256, #58806 and then #54880, #55574, #56278, #56328, #57076, #57556, #57792, #58743, and #59236 for the whole drama (and probably a few issues/PRs/comments I missed) 😅
Might start a whole new chain of "OpenCode model config is wrong" + "Please go report that to OpenCode so they fix the data on Models.dev" issues 🙃 For the record, I am totally fine delaying the merge of this PR!
Solution
Background
When OpenCode was implemented in Zed Agent (both the original Zen-only version and then the current Zen+Free+Go version) a hardcoded list of models was used. This was both inline with other providers and it was the only valid option: there was nowhere to get the data from and the information needed to configure models was split in multiple places (OpenCode docs, OpenCode's Models.dev, hardcoded stuff in OpenCode, etc). Even this mid-May a lot of the required data was missing!
Over the past month, Anomaly (the company behind OpenCode) has been hard at work on making Models.dev the single source of truth for model configuration (mostly since they wanna use that in OpenCode too): reasoning details were added, bugs were fixed, automation was cleaned up, enhanced checks were configured, and so on. Last week there was still some missing data (DeepSeek in OpenCode CLI supported
low,medium,high, andmaxreasoning levels but onlyhighandmaxwere mentioned on the data, for example) or buggy data (for 6-ish hours there as a wrong endpoint set for Qwen models) but all those issues seem to be fixed now so finally we can implement model auto-discovery in Zed 🎉Implementation details
Short version: instead of hardcoded models, get the data from Models.dev, parse it into models + model configuration details, and use it in Zed. To not ruin performance, cache this and respect
etag+304 Not Modified. Also, I havefabulous risk management skillsanxiety and not too much confidence in Models.dev, so there's a ton of error handling.Testing
The overall implementation has been under testing for more than 3 weeks now, but the exact code on this PR only got some quick manual tests and validation: a "rename this variable for me. add a function. delete the function" test was ran using a few models.
This is quite a big change (almost a re-write) and I am not very confident, neither in the code nor in the data, so I would suggest having this remain in Zed Preview for a bit longer?
Review tips and Notes
First off, this is a huge PR and I apologize for that! I tried splitting it into easier-to-review commits but there is still a lot of code that could not be avoided. I'd suggest reviewing this commit-by-commit but since we're doing almost a re-write, reviewing only the final code might make sense?
Notes:
terriblenot great and there's nothing we can do about it. Feature Request: Support precise filtering of vendor id in the api anomalyco/models.dev#1749 means the fullhttps://models.dev/api.jsonhas to be downloaded, which is a chonky JSON that is more than 2MB and that contains data for more than 140 providers with a ton of models. Depending on the connection and latency, this means 1) a small delay and 2) cached data is ruined by updates to any of the non-OpenCode providers. There's no alternative to this — https://opencode.ai/zen/v1/models and https://opencode.ai/zen/go/v1/models only have the model names and we need the model configuration details too and those are only available onmodels.devwhich only offers huge JSONs 😞Decisions I made:
enable_model_autodiscoverycheckbox but I did not see the point in keeping that option (folks on restricted networks / slow networks / WiFi-less plane can't use LLMs, using OpenCode only with custom models makes little sense, etc)serde_json::to_string_prettyfor the model cache and a Last updated timestamp and I decided against logging a bunch of details about the cached models (too many logs or too many UI changes for little value, high complexity, user confusion, etc)Showcase
A few screenshots
Model list:

Settings, failure:

Settings, in progress:

Settings, normal:

Self-Review Checklist:
Release Notes:
models.devinstead of a hardcoded list in Zed)