Uh oh!
There was an error while loading. Please reload this page.
feat(opencode): OpenRouter model discovery/pruning at runtime - #20004
feat(opencode): OpenRouter model discovery/pruning at runtime#20004Randomblock1 wants to merge 5 commits into
Conversation
For auto router the cost is marked as -1 but we can't use that, so just use 0
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Fixes minimax-m2.5:free
# Conflicts: # packages/opencode/src/provider/provider.ts
rekram1-node
commented
May 15, 2026
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
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.