Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Oct 31, 2025

Summary

This PR fixes an issue where custom OpenRouter URLs were not being fully respected throughout the application. When users configured a custom OpenRouter endpoint, some operations (model retrieval, cost calculations, CSP headers) would still use the hardcoded official OpenRouter URL.

Problem

As reported in #8947:

  • When a custom URL is set in OpenRouter configuration, model retrieval and cost calculations still interact with the official OpenRouter endpoints
  • CSP headers were hardcoded to only allow connections to the official OpenRouter domain
  • This affected users who need to use self-hosted, proxy, or third-party OpenRouter-compatible endpoints

Solution

This PR ensures that all OpenRouter interactions respect the custom URL configuration:

Changes Made

  1. Image Generation API - Use configured instead of hardcoded URL

    • : Updated method to use custom base URL
  2. CSP Headers - Dynamically include custom OpenRouter domain in Content Security Policy

    • : Extract and include custom domain in CSP headers for both production and development modes
  3. Model Endpoints Fetching - Pass custom base URL to webview hooks

    • : Added parameter
    • : Pass to the hook

Testing

  • ✅ All existing tests pass
  • ✅ OpenRouter provider tests pass
  • ✅ OpenRouter fetcher tests pass
  • ✅ ClineProvider tests pass

Fixes

Fixes #8947


Important

This PR ensures that all OpenRouter interactions respect the custom URL configuration, affecting image generation, CSP headers, and model endpoint fetching.

  • Behavior:
    • Ensure all OpenRouter interactions use custom URL if configured, instead of default https://openrouter.ai/api/v1.
    • Affects image generation, CSP headers, and model endpoint fetching.
  • Files and Functions:
    • openrouter.ts: Update OpenRouterHandler to use custom URL for API requests.
    • ClineProvider.ts: Modify CSP headers to include custom OpenRouter domain.
    • ApiOptions.tsx and useOpenRouterModelProviders.ts: Pass custom URL to hooks and functions for model provider fetching.
  • Testing:
    • All existing tests pass, including OpenRouter provider and fetcher tests.

This description was created by Ellipsis for 1cad764663c6599fe7363f9242b380c32dd937bd. You can customize this summary. It will automatically update as commits are pushed.

- Use configured openRouterBaseUrl in image generation instead of hardcoded URL
- Dynamically include custom OpenRouter domain in CSP headers
- Pass baseUrl to webview hooks for model endpoints fetching
- Update useOpenRouterModelProviders hook to use custom baseUrl

Fixes #8947
@roomote roomote bot requested review from cte, jr and mrubens as code owners October 31, 2025 13:43
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Oct 31, 2025
@roomote
Copy link
Contributor Author

roomote bot commented Oct 31, 2025

Rooviewer Clock   See task on Roo Cloud

Review Update

Reviewed commit 24e00b6. No new changes since the last review at commit 1cad764. All previously identified issues have been resolved.

Outstanding Issues

  • Inconsistent default base URL usage between CSP sections and auth callback (resolved in 1cad764)
Previous reviews

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Oct 31, 2025
Copy link
Contributor Author

@roomote roomote bot left a comment

Choose a reason for hiding this comment

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

No issues found.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Nov 3, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Nov 3, 2025
@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Needs Review] in Roo Code Roadmap Nov 3, 2025
@hannesrudolph hannesrudolph added PR - Needs Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Nov 3, 2025

// Get the OpenRouter base URL from configuration
const { apiConfiguration } = await this.getState()
const openRouterBaseUrl = apiConfiguration.openRouterBaseUrl || "https://openrouter.ai"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't the default base URL have /api/v1 in it?

Copy link
Member

Choose a reason for hiding this comment

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

In this case only the origin part of the URL is used so there's no need to add the v1 part.

@mrubens mrubens moved this from PR [Needs Review] to PR [Changes Requested] in Roo Code Roadmap Nov 6, 2025
daniel-lxs added a commit that referenced this pull request Nov 6, 2025
- Replace hardcoded 'https://openrouter.ai' fallback with derived domain
  from the same default base URL pattern used everywhere else
- Extract domain from 'https://openrouter.ai/api/v1' for better consistency
- Maintains backward compatibility and existing functionality
- All tests still pass

Fixes inconsistent OpenRouter base URL default in PR #8951
@daniel-lxs daniel-lxs force-pushed the fix/openrouter-custom-url-8947 branch from 1cad764 to 24e00b6 Compare November 6, 2025 22:50
@daniel-lxs daniel-lxs moved this from PR [Changes Requested] to PR [Needs Review] in Roo Code Roadmap Nov 6, 2025
@mrubens mrubens merged commit 2abdad6 into main Nov 7, 2025
40 checks passed
@mrubens mrubens deleted the fix/openrouter-custom-url-8947 branch November 7, 2025 15:35
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Nov 7, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Nov 7, 2025