Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/api/providers/openrouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,13 @@ export class OpenRouterHandler extends BaseProvider implements SingleCompletionH
}
}

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

const baseURL = options?.openRouterBaseUrl || "https://openrouter.ai/api/v1"

try {
const response = await axios.get("https://openrouter.ai/api/v1/models")
const response = await axios.get(`${baseURL}/models`)
const rawModels = response.data.data

for (const rawModel of rawModels) {
Expand Down
15 changes: 11 additions & 4 deletions src/core/webview/ClineProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,8 @@ export class ClineProvider implements vscode.WebviewViewProvider {
// to OpenRouter it would be showing outdated model info
// if we hadn't retrieved the latest at this point
// (see normalizeApiConfiguration > openrouter).
getOpenRouterModels().then(async (openRouterModels) => {
const { apiConfiguration: currentApiConfig } = await this.getState()
getOpenRouterModels(currentApiConfig).then(async (openRouterModels) => {
if (Object.keys(openRouterModels).length > 0) {
await fs.writeFile(
path.join(cacheDir, GlobalFileNames.openRouterModels),
Expand Down Expand Up @@ -1038,8 +1039,9 @@ export class ClineProvider implements vscode.WebviewViewProvider {
case "resetState":
await this.resetState()
break
case "refreshOpenRouterModels":
const openRouterModels = await getOpenRouterModels()
case "refreshOpenRouterModels": {
const { apiConfiguration: configForRefresh } = await this.getState()
const openRouterModels = await getOpenRouterModels(configForRefresh)

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

break
}
case "refreshGlamaModels":
const glamaModels = await getGlamaModels()

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