feat(opencode): OpenRouter model discovery/pruning at runtime#20004
Open
Randomblock1 wants to merge 5 commits intoanomalyco:devfrom
Open
feat(opencode): OpenRouter model discovery/pruning at runtime#20004Randomblock1 wants to merge 5 commits intoanomalyco:devfrom
Randomblock1 wants to merge 5 commits intoanomalyco:devfrom
Conversation
For auto router the cost is marked as -1 but we can't use that, so just use 0
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Fixes minimax-m2.5:free
6 tasks
# Conflicts: # packages/opencode/src/provider/provider.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #4734
Fixes #279
Fixes #10594
Fixes #15962
And probably quite a few more...
Type of change
What does this PR do?
OpenCode currently relies on Models.dev as the source of truth for available OpenRouter models. This has caused many issues for users because the catalog and limited-time free models changes daily. Additionally, some model IDs that have been removed from OpenRouter are still in Models.dev (for example,
qwen3-4b:free).This is because Models.dev appears to have no automation (!?!?). If a new model is added to OpenRouter, someone has to go make a commit or PR, for EVERY model, and every free promotion. There are hundreds of models on OpenRouter (the point is to have all of them) so this is not a good solution by itself.
This PR implements model discovery at runtime for OpenRouter. OpenCode now fetches the live catalog directly from the OpenRouter Models API, (in addition to using Models.dev) ensuring all models are at least usable. A cache ensures that this does not impact startup performance much.
This is a fallback mechanism, not a complete replacement. High-quality, manually verified metadata in Models.dev is preferred, and in some cases, used for discovered models (OpenRouter API does not include interleaved info, so for example,
minimax-m2.5data is used to set interleaved forminimax-m2.5:free, as it errors after 1 message without it).As a result of the auto-mapping, some models may not have correctly optimized settings, for example
alibaba/tongyi-deepresearch-30b-a3b(which is a finetuned Qwen3) will use default settings instead of Qwen3 optimized ones.In addition to the OpenRouter discovery code, I refactored the core provider initialization to be provider-agnostic. GitLab-specific discovery logic was replaced with a generic loop that automatically handles
discoverModelsfor any provider that implements it. I had to add some OpenRouter-specific code there, but theoretically that could be made generic too, if other providers implement model pruning.How did you verify your code works?
Diff the models it lists from those in the OpenRouter API:
There's nothing, which means all OpenRouter models are accessible in OpenCode.
I was able to use free endpoints like
minimax-m2.5:freein OpenCode which is not in Models.dev, and was not visible or usable in the main branch.Screenshots / recordings
Not a UI change.
Checklist
If you do not follow this template your PR will be automatically rejected.