fix: using baseURL to fetch models and get API key (#5732)

* fix: using baseURL to fetch models and get API key

* change set

* fix: keeping /v1 in URL

This is because `URL` constructor, strips the path when giving two
arguments.
This commit is contained in:
John Costa authored and GitHub committed 2025-09-11 19:52:42 -07:00
1 parent c3591290d2
commit 6b9dbccfd2
6 files changed
+128 -77

No files matched your search

@@ -1,6 +1,7 @@
import { EmptyRequest } from "@shared/proto/cline/common"
import { OpenRouterCompatibleModelInfo, OpenRouterModelInfo } from "@shared/proto/cline/models"
import axios from "axios"
import { toRequestyServiceUrl } from "@/shared/providers/requesty"
import { Controller } from ".."
/**
@@ -20,10 +21,15 @@ export async function refreshRequestyModels(controller: Controller, _: EmptyRequ
const models: Record<string, OpenRouterModelInfo> = {}
try {
const apiKey = controller.stateManager.getSecretKey("requestyApiKey")
const baseUrl = controller.stateManager.getGlobalStateKey("requestyBaseUrl")
const resolvedUrl = toRequestyServiceUrl(baseUrl)
const url = new URL(`${resolvedUrl.pathname}/models`, resolvedUrl).toString()
const headers = {
Authorization: `Bearer ${apiKey}`,
}
const response = await axios.get("https://router.requesty.ai/v1/models", { headers })
const response = await axios.get(url, { headers })
if (response.data?.data) {
for (const model of response.data.data) {
const modelInfo: OpenRouterModelInfo = OpenRouterModelInfo.create({