Skip to content

Commit 774248b

Browse files
committed
Fix more hard-coded openrouter urls
1 parent 3cd6c74 commit 774248b

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/api/providers/openrouter.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,13 @@ export class OpenRouterHandler extends BaseProvider implements SingleCompletionH
226226
}
227227
}
228228

229-
export async function getOpenRouterModels() {
229+
export async function getOpenRouterModels(options?: ApiHandlerOptions) {
230230
const models: Record<string, ModelInfo> = {}
231231

232+
const baseURL = options?.openRouterBaseUrl || "https://openrouter.ai/api/v1"
233+
232234
try {
233-
const response = await axios.get("https://openrouter.ai/api/v1/models")
235+
const response = await axios.get(`${baseURL}/models`)
234236
const rawModels = response.data.data
235237

236238
for (const rawModel of rawModels) {

src/core/webview/ClineProvider.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,8 @@ export class ClineProvider implements vscode.WebviewViewProvider {
789789
// to OpenRouter it would be showing outdated model info
790790
// if we hadn't retrieved the latest at this point
791791
// (see normalizeApiConfiguration > openrouter).
792-
getOpenRouterModels().then(async (openRouterModels) => {
792+
const { apiConfiguration: currentApiConfig } = await this.getState()
793+
getOpenRouterModels(currentApiConfig).then(async (openRouterModels) => {
793794
if (Object.keys(openRouterModels).length > 0) {
794795
await fs.writeFile(
795796
path.join(cacheDir, GlobalFileNames.openRouterModels),
@@ -1038,8 +1039,9 @@ export class ClineProvider implements vscode.WebviewViewProvider {
10381039
case "resetState":
10391040
await this.resetState()
10401041
break
1041-
case "refreshOpenRouterModels":
1042-
const openRouterModels = await getOpenRouterModels()
1042+
case "refreshOpenRouterModels": {
1043+
const { apiConfiguration: configForRefresh } = await this.getState()
1044+
const openRouterModels = await getOpenRouterModels(configForRefresh)
10431045

10441046
if (Object.keys(openRouterModels).length > 0) {
10451047
const cacheDir = await this.ensureCacheDirectoryExists()
@@ -1051,6 +1053,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
10511053
}
10521054

10531055
break
1056+
}
10541057
case "refreshGlamaModels":
10551058
const glamaModels = await getGlamaModels()
10561059

@@ -2154,7 +2157,11 @@ export class ClineProvider implements vscode.WebviewViewProvider {
21542157
async handleOpenRouterCallback(code: string) {
21552158
let apiKey: string
21562159
try {
2157-
const response = await axios.post("https://openrouter.ai/api/v1/auth/keys", { code })
2160+
const { apiConfiguration } = await this.getState()
2161+
const baseUrl = apiConfiguration.openRouterBaseUrl || "https://openrouter.ai/api/v1"
2162+
// Extract the base domain for the auth endpoint
2163+
const baseUrlDomain = baseUrl.match(/^(https?:\/\/[^\/]+)/)?.[1] || "https://openrouter.ai"
2164+
const response = await axios.post(`${baseUrlDomain}/api/v1/auth/keys`, { code })
21582165
if (response.data && response.data.key) {
21592166
apiKey = response.data.key
21602167
} else {

0 commit comments

Comments
 (0)