Skip to content

opencode: Model auto-discovery - #60373

Closed
Vlaaaaaaad wants to merge 14 commits into
zed-industries:mainfrom
Vlaaaaaaad:opencode-rewrite
Closed

opencode: Model auto-discovery#60373
Vlaaaaaaad wants to merge 14 commits into
zed-industries:mainfrom
Vlaaaaaaad:opencode-rewrite

Conversation

@Vlaaaaaaad

Copy link
Copy Markdown
Contributor

TL;DR: now that models.dev data 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, and max reasoning levels but only high and max were 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 have fabulous 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:

  • there is a bunch of super-verbose error handling and retries and logging. That's not due to dumb LLMs but very much due to me not trusting the reliability of models.dev and me wanting to make failures super-clear and easy to debug. If y'all think this is me going overboard, I am happy to remove it!
  • performance is 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 full https://models.dev/api.json has 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 on models.dev which only offers huge JSONs 😞
  • parallel tool call support is missing from the data available on Models.dev (see Request: New column for parallel tool calling anomalyco/models.dev#202) but OpenCode developers said on Discord that "almost all models worth using support parallel tool calling natively" and I manually confirmed that to be true for all OpenCode Go models
  • this has been in the works for a while now and this went through a ton of changes, so some code might look weird or unnatural to y'all but totally normal to me since I've been working on this for so long. Please let me know if that is the case!

Decisions I made:

  • no auto-update. I did consider running the auto-discovery every 15 minutes or every hour or whatever, but that would've been a bit too chaotic (potential surprises, mid-work interruptions, Zed doing too many network calls, etc)
  • no opt-in. I did initially have an enable_model_autodiscovery checkbox 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)
  • no hardcoded models kept. I did consider this option, especially since I am worried about the data quality on Models.dev, but that would have been difficult (complex merging logic, duplicate names, unclear icons or sourcing notes for each model in the list, etc) for no benefit (custom models can be used if the data is wrong for 1 model until the data is fixed)
  • not too much logging. I only kept serde_json::to_string_pretty for 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)
  • no cost data. The data from Models.dev also includes the cost for each model which would be nice to display in Zed, but right now that looks terrible so the data is dropped:
Screenshot of Zed model list showing cost after each model (literally markdown code block with $15/$60 content)

Showcase

A few screenshots

Model list:
Model list in Zed

Settings, failure:
Settings screen showing auto-discovery failure

Settings, in progress:
Settings screen showing in-progress auto-discovery

Settings, normal:
Settings screen showing when the last successful auto-discovery ran

Self-Review Checklist:

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content adheres to Zed's UI standards (UX/UI and icon guidelines)
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable (eh, debatable — see above)

Release Notes:

  • OpenCode: Auto-discover the model list (use data from models.dev instead of a hardcoded list in Zed)
  • OpenCode: Enable parallel tool calls for all models
  • OpenCode Zen: Fix thinking for Google models

 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
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Jul 3, 2026
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
@Vlaaaaaaad

Copy link
Copy Markdown
Contributor Author

FYI: Models.dev will sometime in the future get a new V2 API/schema: anomalyco/models.dev#3037

@Vlaaaaaaad

Copy link
Copy Markdown
Contributor Author

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!

@Vlaaaaaaad Vlaaaaaaad closed this Jul 5, 2026
@Vlaaaaaaad Vlaaaaaaad mentioned this pull request Jul 7, 2026
5 tasks
Vlaaaaaaad added a commit to Vlaaaaaaad/zed that referenced this pull request Jul 7, 2026
**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
@Vlaaaaaaad

Copy link
Copy Markdown
Contributor Author

FYI: it looks like a bigger API revamp is happening as part of OpenCode V2: potentially moving to https://console.opencode.ai/inference/openai/v1 instead of https://opencode.ai/zen/v1, for example. After OpenCode V2 launches I'll look at doing the optional auto-discovery implementation, assuming I have the bandwidth 🤞

@Tobbe

Tobbe commented Jul 16, 2026

Copy link
Copy Markdown

As always, thanks for your work on OpenCode support in Zed @Vlaaaaaaad

jolutz pushed a commit to jolutz/zed that referenced this pull request Aug 8, 2026
**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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants