Skip to content

Commit 4a75f85

Browse files
committed
feat: Add openRouterBaseUrl option
1 parent 7b66827 commit 4a75f85

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

src/api/providers/openrouter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class OpenRouterHandler implements ApiHandler, SingleCompletionHandler {
2626
constructor(options: ApiHandlerOptions) {
2727
this.options = options
2828
this.client = new OpenAI({
29-
baseURL: "https://openrouter.ai/api/v1",
29+
baseURL: this.options.openRouterBaseUrl,
3030
apiKey: this.options.openRouterApiKey,
3131
defaultHeaders: {
3232
"HTTP-Referer": "https://github.com/RooVetGit/Roo-Cline",

src/core/webview/ClineProvider.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ type GlobalStateKey =
9393
| "openAiStreamingEnabled"
9494
| "openRouterModelId"
9595
| "openRouterModelInfo"
96+
| "openRouterBaseUrl"
9697
| "openRouterUseMiddleOutTransform"
9798
| "allowedCommands"
9899
| "soundEnabled"
@@ -1293,6 +1294,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
12931294
azureApiVersion,
12941295
openAiStreamingEnabled,
12951296
openRouterModelId,
1297+
openRouterBaseUrl,
12961298
openRouterModelInfo,
12971299
openRouterUseMiddleOutTransform,
12981300
vsCodeLmModelSelector,
@@ -1331,6 +1333,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
13311333
await this.updateGlobalState("openAiStreamingEnabled", openAiStreamingEnabled)
13321334
await this.updateGlobalState("openRouterModelId", openRouterModelId)
13331335
await this.updateGlobalState("openRouterModelInfo", openRouterModelInfo)
1336+
await this.updateGlobalState("openRouterBaseUrl", openRouterBaseUrl)
13341337
await this.updateGlobalState("openRouterUseMiddleOutTransform", openRouterUseMiddleOutTransform)
13351338
await this.updateGlobalState("vsCodeLmModelSelector", vsCodeLmModelSelector)
13361339
await this.storeSecret("mistralApiKey", mistralApiKey)
@@ -1954,6 +1957,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
19541957
openAiStreamingEnabled,
19551958
openRouterModelId,
19561959
openRouterModelInfo,
1960+
openRouterBaseUrl,
19571961
openRouterUseMiddleOutTransform,
19581962
lastShownAnnouncementId,
19591963
customInstructions,
@@ -2022,6 +2026,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
20222026
this.getGlobalState("openAiStreamingEnabled") as Promise<boolean | undefined>,
20232027
this.getGlobalState("openRouterModelId") as Promise<string | undefined>,
20242028
this.getGlobalState("openRouterModelInfo") as Promise<ModelInfo | undefined>,
2029+
this.getGlobalState("openRouterBaseUrl") as Promise<string | undefined>,
20252030
this.getGlobalState("openRouterUseMiddleOutTransform") as Promise<boolean | undefined>,
20262031
this.getGlobalState("lastShownAnnouncementId") as Promise<string | undefined>,
20272032
this.getGlobalState("customInstructions") as Promise<string | undefined>,
@@ -2107,6 +2112,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
21072112
openAiStreamingEnabled,
21082113
openRouterModelId,
21092114
openRouterModelInfo,
2115+
openRouterBaseUrl,
21102116
openRouterUseMiddleOutTransform,
21112117
vsCodeLmModelSelector,
21122118
},

src/shared/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface ApiHandlerOptions {
2626
openRouterApiKey?: string
2727
openRouterModelId?: string
2828
openRouterModelInfo?: ModelInfo
29+
openRouterBaseUrl?: string
2930
awsAccessKey?: string
3031
awsSecretKey?: string
3132
awsSessionToken?: string

webview-ui/src/components/settings/ApiOptions.tsx

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) =
5151
const [vsCodeLmModels, setVsCodeLmModels] = useState<vscodemodels.LanguageModelChatSelector[]>([])
5252
const [anthropicBaseUrlSelected, setAnthropicBaseUrlSelected] = useState(!!apiConfiguration?.anthropicBaseUrl)
5353
const [azureApiVersionSelected, setAzureApiVersionSelected] = useState(!!apiConfiguration?.azureApiVersion)
54+
const [openRouterBaseUrlSelected, setOpenRouterBaseUrlSelected] = useState(!!apiConfiguration?.openRouterBaseUrl)
5455
const [isDescriptionExpanded, setIsDescriptionExpanded] = useState(false)
5556

5657
const { selectedProvider, selectedModelId, selectedModelInfo } = useMemo(() => {
@@ -303,12 +304,38 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) =
303304
<span style={{ fontWeight: 500 }}>OpenRouter API Key</span>
304305
</VSCodeTextField>
305306
{!apiConfiguration?.openRouterApiKey && (
306-
<VSCodeButtonLink
307-
href={getOpenRouterAuthUrl(uriScheme)}
308-
style={{ margin: "5px 0 0 0" }}
309-
appearance="secondary">
310-
Get OpenRouter API Key
311-
</VSCodeButtonLink>
307+
<p>
308+
<VSCodeButtonLink
309+
href={getOpenRouterAuthUrl(uriScheme)}
310+
style={{ margin: "5px 0 0 0" }}
311+
appearance="secondary">
312+
Get OpenRouter API Key
313+
</VSCodeButtonLink>
314+
</p>
315+
)}
316+
<Checkbox
317+
checked={openRouterBaseUrlSelected}
318+
onChange={(checked: boolean) => {
319+
setOpenRouterBaseUrlSelected(checked)
320+
if (!checked) {
321+
handleInputChange("openRouterBaseUrl")({
322+
target: {
323+
value: "",
324+
},
325+
})
326+
}
327+
}}>
328+
Use custom base URL
329+
</Checkbox>
330+
331+
{openRouterBaseUrlSelected && (
332+
<VSCodeTextField
333+
value={apiConfiguration?.openRouterBaseUrl || "https://openrouter.ai/api/v1"}
334+
style={{ width: "100%", marginTop: 3 }}
335+
type="url"
336+
onInput={handleInputChange("openRouterBaseUrl")}
337+
placeholder="Default: https://openrouter.ai/api/v1"
338+
/>
312339
)}
313340
<p
314341
style={{

0 commit comments

Comments
 (0)