-
Notifications
You must be signed in to change notification settings - Fork 3.8k
feat: Add OpenRouter Provider Support with Dynamic Model Loading #8738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: Add OpenRouter Provider Support with Dynamic Model Loading #8738
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 issues found across 6 files
Prompt for AI agents (all 2 issues)
Understand the root cause of the following 2 issues and fix them.
<file name="gui/src/pages/AddNewModel/configs/openRouterModel.ts">
<violation number="1" location="gui/src/pages/AddNewModel/configs/openRouterModel.ts:60">
Because nearly every OpenRouter model populates `architecture.modality`, this condition marks all of them as not open source—including open-weight models—so they disappear from any open-source-only filters. Please base `isOpenSource` on a discriminator that actually reflects open weights (e.g., the presence of a Hugging Face ID) instead of the modality flag.</violation>
</file>
<file name="gui/src/components/modelSelection/ModelSelectionListbox.tsx">
<violation number="1" location="gui/src/components/modelSelection/ModelSelectionListbox.tsx:161">
Popular list entries lost the pointer cursor class, so they no longer show a pointer on hover—please add `cursor-pointer` back to keep them visibly interactive.</violation>
</file>
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Ask questions if you need clarification on any suggestion
Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR
| model: model.id, | ||
| contextLength, | ||
| }, | ||
| isOpenSource: model.architecture?.modality ? false : true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because nearly every OpenRouter model populates architecture.modality, this condition marks all of them as not open source—including open-weight models—so they disappear from any open-source-only filters. Please base isOpenSource on a discriminator that actually reflects open weights (e.g., the presence of a Hugging Face ID) instead of the modality flag.
Prompt for AI agents
Address the following comment on gui/src/pages/AddNewModel/configs/openRouterModel.ts at line 60:
<comment>Because nearly every OpenRouter model populates `architecture.modality`, this condition marks all of them as not open source—including open-weight models—so they disappear from any open-source-only filters. Please base `isOpenSource` on a discriminator that actually reflects open weights (e.g., the presence of a Hugging Face ID) instead of the modality flag.</comment>
<file context>
@@ -0,0 +1,107 @@
+ model: model.id,
+ contextLength,
+ },
+ isOpenSource: model.architecture?.modality ? false : true,
+ tags: [provider as any],
+ };
</file context>
✅ Addressed in 564e0b0
ai suggestion Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
…tha-sarathyy/continue into addmodel-openrouter-provider
|
I have read the CLA Document and I hereby sign the CLA |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@partha-sarathyy this is great!
The only change I'd request is could you write a super simple script or similar to eliminate all the unused parameters/extra data from the operouter models JSON to whittle it down to a more manageable size? I think it should be a few hundred lines tops. You might even just prompt Continue to rewrite it with the following changes:
- Descriptions need to be shorter to fit in the UI. Once brief sentence max
- All unused fields should be eliminated (most of them)
You could include brief instructions on where you got the JSON and the prompt you used to clean it up, in a comment
|
@RomneyDa thanks for the review. |
RomneyDa
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@partha-sarathyy appreciate the followup!
I think it should be a few hundred lines tops
I'm still a bit concerned with maintainability of 2000 lines of model constants. Is there a way we could dynamically fetch this from openrouter only when openrouter is selected or similar?
|
@RomneyDa yeah I think it's totally possible and I'll look into it |
- Replaced the import of openRouterModelsList with getOpenRouterModelsList. - Added a new function `initializeOpenRouterModels` to fetch and initialize OpenRouter models from the API. - Updated the providers object with the fetched models upon successful retrieval. - Added error handling to reset the models list in case of a fetch failure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 issues found across 4 files (reviewed changes from recent commits).
Prompt for AI agents (all 2 issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="gui/src/forms/AddModelForm.tsx">
<violation number="1" location="gui/src/forms/AddModelForm.tsx:45">
`initializeOpenRouterModels` performs network work and should run in an effect, not on every render; wrap the call in a mount-only `useEffect` so it executes once.</violation>
</file>
<file name="gui/src/pages/AddNewModel/configs/providers.ts">
<violation number="1" location="gui/src/pages/AddNewModel/configs/providers.ts:53">
Loading OpenRouter models asynchronously leaves `providers.openrouter.packages` empty on first use, so selecting the provider before the fetch completes sets `selectedModel` to undefined and crashes when `selectedModel.params` is accessed.</violation>
</file>
Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR
| */ | ||
| export async function initializeOpenRouterModels() { | ||
| try { | ||
| openRouterModelsList = await getOpenRouterModelsList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Loading OpenRouter models asynchronously leaves providers.openrouter.packages empty on first use, so selecting the provider before the fetch completes sets selectedModel to undefined and crashes when selectedModel.params is accessed.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At gui/src/pages/AddNewModel/configs/providers.ts, line 53:
<comment>Loading OpenRouter models asynchronously leaves `providers.openrouter.packages` empty on first use, so selecting the provider before the fetch completes sets `selectedModel` to undefined and crashes when `selectedModel.params` is accessed.</comment>
<file context>
@@ -41,6 +41,26 @@ const openSourceModels = Object.values(models).filter(
+ */
+export async function initializeOpenRouterModels() {
+ try {
+ openRouterModelsList = await getOpenRouterModelsList();
+ // Update the providers object with the fetched models
+ if (providers.openrouter) {
</file context>
…r and effect hook
feat(openrouter): Add OpenRouter Provider Support with Dynamic Model Loading
Overview
This PR adds OpenRouter as a model provider in Continue, with automatic model loading from OpenRouter JSON data and an enhanced model selection UI featuring fuzzy search.
Changes Made
1. OpenRouter Model Data Processing (
openRouterModel.ts)ModelPackageformat.openRouterModels.json.ModelPackagetype.openRouterModels) and array (openRouterModelsList) formats.Files:
2. Provider Configuration (
providers.ts)openRouterModelsList.OpenRouteropenrouter.pngFile:
3. Enhanced Model Selection UI (
ModelSelectionListbox.tsx)searchPlaceholderprop for context-specific labels.File:
Other modified imports:
Search Algorithm Details
UI Improvements
@heroicons/react/24/outline.Technical Details
New Dependencies
useState,useEffect,useMemo.File Structure (new / modified)
Usage Examples
For users:
gpt,claude,llama.Files Added
openrouter.png(ensure included in repo assets)Tests / Verification
openRouterModels.json.Notes for Reviewers
openRouterModels.jsonandopenrouter.pngare included in packaged assets/build.Breaking Changes
!and a BREAKING CHANGE section.Changelog (one-liner)
feat(openrouter): add OpenRouter provider with dynamic model loading and fuzzy search for model selection
Adds OpenRouter as a provider with dynamic model loading from OpenRouter data and adds fuzzy search to the model/provider selection for faster discovery.