Skip to content

Conversation

@PhunkyBob
Copy link

@PhunkyBob PhunkyBob commented Mar 4, 2025

Context

In OpenRouter, for the same model it's possible to use different providers.
By default, OpenRouter choose by itslef regarding the price and the availability.
For some models, different providers have different properties, like the context window or the speed.

image

This PR aims to let the user choose the provider he wants to use.

Solves #663

Implementation

  • Add a function getOpenRouterProvidersForModel in a new file webview-ui\src\utils\openrouter-helper.ts to get all providers available for a specific model, using [OpenRouter API)[https://openrouter.ai/docs/api-reference/list-endpoints-for-a-model].
  • Add a list of providers in the webview-ui\src\components\settings\ApiOptions.tsx (only when OpenRouter is selected).
  • Add a parameter openRouterSpecificProvider in the options to store the choice made by the user.
  • When the provider is changed, ApiConfiguration is updated with the new price / context window.
  • When a request is made in createMessage of src\api\providers\openrouter.ts, if a specific provider is asked, we add the corresponding parameter (order and allow_fallbacks) in the query.

Screenshots

before after
image image
Price and context are the default ones Price and context are updated

How to Test

  • Go to Roo Code settings.

  • Use "OpenRouter" as API Provider.

  • Select model qwen/qwen-2.5-coder-32b-instruct and keep default value.

  • Save and close.

  • Make a query.
    ➡️ context window will be of 33k

  • Go to Roo Code settings.

  • Use "OpenRouter" as API Provider.

  • Select model qwen/qwen-2.5-coder-32b-instruct.

  • In the provider list, choose Groq.

  • Save and close.

  • Make a query.
    ➡️ context window will be of 128k
    ➡️ answer will be blazing fast

  • Go to Activity Dashbord in your OpenRouter account.
    ➡️ Your two requests will have a different provider, cost and speed.


Important

Adds functionality to select specific providers for OpenRouter models, allowing customization of model properties like context window and pricing.

  • Behavior:
    • Adds getOpenRouterProvidersForModel in openrouter-helper.ts to fetch providers for a model.
    • Updates ApiOptions.tsx to include a dropdown for selecting OpenRouter providers.
    • Modifies createMessage in openrouter.ts to include provider parameters if specified.
  • State Management:
    • Adds openRouterSpecificProvider to ApiHandlerOptions in api.ts.
    • Updates ClineProvider.ts to handle openRouterSpecificProvider in global state.
  • UI:
    • Updates ApiOptions.tsx to display provider options with context and pricing details.

This description was created by Ellipsis for 0d8020391c8505cbfaa7ed4b1474f0abc03bce99. It will automatically update as commits are pushed.

@PhunkyBob PhunkyBob requested review from cte and mrubens as code owners March 4, 2025 15:28
@changeset-bot
Copy link

changeset-bot bot commented Mar 4, 2025

🦋 Changeset detected

Latest commit: 9fbbbf6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
roo-cline Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Mar 4, 2025
@PhunkyBob PhunkyBob changed the title Choose provider when using OpenRouter API provider: Choose specific provider when using OpenRouter Mar 4, 2025
@hannesrudolph hannesrudolph moved this to To triage in Roo Code Roadmap Mar 5, 2025
@hannesrudolph hannesrudolph moved this from To triage to PR - Needs Review in Roo Code Roadmap Mar 5, 2025
@PhunkyBob PhunkyBob force-pushed the openrouter_provider branch from e5f1ecf to 9111d3a Compare March 7, 2025 17:42
@PhunkyBob
Copy link
Author

PhunkyBob commented Mar 7, 2025

@mrubens
@cte
Newb question: do I have to merge with upstream every time you commit something on main branch?

@mrubens
Copy link
Collaborator

mrubens commented Mar 8, 2025

Nice, this is cool! Will take a closer look soon.

You don't have to merge with upstream every time, it's only in case of conflicts.

Related, you don't need to edit the changelog - that happens automatically later from the changeset. So maybe rebase that and the change to the readme out of this branch to make it less likely to have conflict? Thanks!

@PhunkyBob PhunkyBob force-pushed the openrouter_provider branch from b4768b4 to 15e0840 Compare March 8, 2025 17:30
@PhunkyBob
Copy link
Author

I struggle with the README.md and CHANGELOG.md files. Even when I restore them from main GitHub displays differences.
I guess you won't have problems when merging with your branch. 🤞

@PhunkyBob PhunkyBob force-pushed the openrouter_provider branch from 15e0840 to 3f87e85 Compare March 8, 2025 18:08
@mrubens mrubens moved this from PR [Unverified] to PR [Greenlit] in Roo Code Roadmap Mar 10, 2025
@mrubens
Copy link
Collaborator

mrubens commented Mar 11, 2025

This looks pretty good to me and useful. @cte do you have time to take a quick look as well since you've been dealing with the API config stuff more than me? Thanks!

@cte
Copy link
Collaborator

cte commented Mar 11, 2025

@cte do you have time to take a quick look as well since you've been dealing with the API config stuff more than me? Thanks!

Will do!

import { parseApiPrice } from "../../../src/utils/cost"

export const OPENROUTER_DEFAULT_PROVIDER_NAME = "[default]"
export async function getOpenRouterProvidersForModel(modelId: string) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can DRY things up a here a bit with the getOpenRouterModels function, which does a similar decoration of the model info. It probably also makes sense for getOpenRouterModels to live in this helper file. What do you think? I'm happy to take a stab at that later today as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first I wanted to include the getOpenRouterProvidersForModel function into the \src\api\providers\openrouter.ts file. But since there are no others import from "below webview-ui", I supposed it would be a bad idea.

Copy link
Collaborator

@cte cte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I left one comment about a potential improvement but I don't think it's blocking. I'll test and merge this today. Thank you!

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Mar 11, 2025
@PhunkyBob
Copy link
Author

@cte is there a chance to see this PR merged in the main repo?

@cte
Copy link
Collaborator

cte commented Mar 17, 2025

@cte is there a chance to see this PR merged in the main repo?

Yes - will take a look this morning.

@mrubens
Copy link
Collaborator

mrubens commented Mar 18, 2025

Merged in #1753!

@mrubens mrubens closed this Mar 18, 2025
@github-project-automation github-project-automation bot moved this from PR [Greenlit] to Done in Roo Code Roadmap Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants