Skip to content

Conversation

@roomote
Copy link

@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

Fixes issue where custom OpenRouter URLs were not respected across API operations, ensuring all interactions use the configured URL.

This description was created by Ellipsis for 24e00b6. 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
Author

roomote bot commented Oct 31, 2025

Code Review Complete

I've reviewed this PR and found no issues with the implementation. The changes correctly address the reported issue by:

  1. ✅ Using the configured openRouterBaseUrl in the image generation API instead of the hardcoded URL
  2. ✅ Dynamically extracting and including the custom OpenRouter domain in CSP headers for both development and production modes
  3. ✅ Passing the baseUrl parameter through to the webview hooks for model endpoint fetching

The implementation properly handles:

  • Fallback to the default OpenRouter URL when no custom URL is configured
  • Safe regex extraction of the domain with appropriate fallbacks
  • Consistent use of the custom URL across all OpenRouter API operations

All changes are well-structured and maintain backward compatibility.

Follow Along on Roo Code Cloud

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Oct 31, 2025
Copy link
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer PR - Needs Review size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Status: PR [Needs Review]

Development

Successfully merging this pull request may close these issues.

[ENHANCEMENT] When custom url is used in Openrouter, model retrieval and costs are still pointing to the official one

4 participants