Skip to content

Commit 5e812cf

Browse files
fix: changing base URL for fetching models
1 parent 44086e4 commit 5e812cf

File tree

7 files changed

+50
-14
lines changed

7 files changed

+50
-14
lines changed

src/api/providers/fetchers/modelCache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export const getModels = async (options: GetModelsOptions): Promise<ModelRecord>
5959
break
6060
case "requesty":
6161
// Requesty models endpoint requires an API key for per-user custom policies
62-
models = await getRequestyModels(options.apiKey)
62+
models = await getRequestyModels(options.baseUrl, options.apiKey)
6363
break
6464
case "glama":
6565
models = await getGlamaModels()

src/api/providers/fetchers/requesty.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import axios from "axios"
33
import type { ModelInfo } from "@roo-code/types"
44

55
import { parseApiPrice } from "../../../shared/cost"
6+
import { toRequestyServiceUrl } from "../../../shared/utils/requesty"
67

7-
export async function getRequestyModels(apiKey?: string): Promise<Record<string, ModelInfo>> {
8+
export async function getRequestyModels(baseUrl?: string, apiKey?: string): Promise<Record<string, ModelInfo>> {
89
const models: Record<string, ModelInfo> = {}
910

1011
try {
@@ -14,8 +15,10 @@ export async function getRequestyModels(apiKey?: string): Promise<Record<string,
1415
headers["Authorization"] = `Bearer ${apiKey}`
1516
}
1617

17-
const url = "https://router.requesty.ai/v1/models"
18-
const response = await axios.get(url, { headers })
18+
const resolvedBaseUrl = toRequestyServiceUrl(baseUrl)
19+
const modelsUrl = new URL("models", resolvedBaseUrl)
20+
21+
const response = await axios.get(modelsUrl.toString(), { headers })
1922
const rawModels = response.data.data
2023

2124
for (const rawModel of rawModels) {

src/api/providers/requesty.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { DEFAULT_HEADERS } from "./constants"
1515
import { getModels } from "./fetchers/modelCache"
1616
import { BaseProvider } from "./base-provider"
1717
import type { SingleCompletionHandler, ApiHandlerCreateMessageMetadata } from "../index"
18+
import { toRequestyServiceUrl } from "../../shared/utils/requesty"
1819

1920
// Requesty usage includes an extra field for Anthropic use cases.
2021
// Safely cast the prompt token details section to the appropriate structure.
@@ -40,21 +41,23 @@ export class RequestyHandler extends BaseProvider implements SingleCompletionHan
4041
protected options: ApiHandlerOptions
4142
protected models: ModelRecord = {}
4243
private client: OpenAI
44+
private baseURL: string
4345

4446
constructor(options: ApiHandlerOptions) {
4547
super()
4648

4749
this.options = options
50+
this.baseURL = toRequestyServiceUrl(options.requestyBaseUrl)
4851

4952
this.client = new OpenAI({
50-
baseURL: options.requestyBaseUrl || "https://router.requesty.ai/v1",
53+
baseURL: this.baseURL,
5154
apiKey: this.options.requestyApiKey ?? "not-provided",
5255
defaultHeaders: DEFAULT_HEADERS,
5356
})
5457
}
5558

5659
public async fetchModel() {
57-
this.models = await getModels({ provider: "requesty" })
60+
this.models = await getModels({ provider: "requesty", baseUrl: this.baseURL })
5861
return this.getModel()
5962
}
6063

src/shared/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export const getModelMaxOutputTokens = ({
135135
export type GetModelsOptions =
136136
| { provider: "openrouter" }
137137
| { provider: "glama" }
138-
| { provider: "requesty"; apiKey?: string }
138+
| { provider: "requesty"; apiKey?: string; baseUrl?: string }
139139
| { provider: "unbound"; apiKey?: string }
140140
| { provider: "litellm"; apiKey: string; baseUrl: string }
141141
| { provider: "ollama"; baseUrl?: string }

src/shared/utils/requesty.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const REQUESTY_BASE_URL = "https://router.requesty.ai/v1"
2+
3+
type URLType = "router" | "app" | "api"
4+
5+
const replaceCname = (baseUrl: string, type: URLType): string => {
6+
if (type === "router") {
7+
return baseUrl
8+
} else {
9+
return baseUrl.replace("router", type).replace("v1", "")
10+
}
11+
}
12+
13+
export const toRequestyServiceUrl = (baseUrl?: string, service: URLType = "router"): string => {
14+
let url = replaceCname(baseUrl ?? REQUESTY_BASE_URL, service)
15+
16+
return new URL(url).toString()
17+
}

webview-ui/src/components/settings/providers/RequestyBalanceDisplay.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import { VSCodeLink } from "@vscode/webview-ui-toolkit/react"
22

33
import { useRequestyKeyInfo } from "@/components/ui/hooks/useRequestyKeyInfo"
4+
import { toRequestyServiceUrl } from "@roo/utils/requesty"
45

5-
export const RequestyBalanceDisplay = ({ apiKey }: { apiKey: string }) => {
6-
const { data: keyInfo } = useRequestyKeyInfo(apiKey)
6+
type RequestyBalanceDisplayProps = {
7+
apiKey: string
8+
baseUrl?: string
9+
}
10+
11+
export const RequestyBalanceDisplay = ({ baseUrl, apiKey }: RequestyBalanceDisplayProps) => {
12+
const { data: keyInfo } = useRequestyKeyInfo(baseUrl, apiKey)
713

814
if (!keyInfo) {
915
return null
@@ -13,8 +19,11 @@ export const RequestyBalanceDisplay = ({ apiKey }: { apiKey: string }) => {
1319
const balance = parseFloat(keyInfo.org_balance)
1420
const formattedBalance = balance.toFixed(2)
1521

22+
const resolvedBaseUrl = toRequestyServiceUrl(baseUrl, "app")
23+
const settingsUrl = new URL("settings", resolvedBaseUrl)
24+
1625
return (
17-
<VSCodeLink href="https://app.requesty.ai/settings" className="text-vscode-foreground hover:underline">
26+
<VSCodeLink href={settingsUrl.toString()} className="text-vscode-foreground hover:underline">
1827
${formattedBalance}
1928
</VSCodeLink>
2029
)

webview-ui/src/components/ui/hooks/useRequestyKeyInfo.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import axios from "axios"
22
import { z } from "zod"
33
import { useQuery, UseQueryOptions } from "@tanstack/react-query"
4+
import { toRequestyServiceUrl } from "@roo/utils/requesty"
45

56
const requestyKeyInfoSchema = z.object({
67
name: z.string(),
@@ -14,11 +15,14 @@ const requestyKeyInfoSchema = z.object({
1415

1516
export type RequestyKeyInfo = z.infer<typeof requestyKeyInfoSchema>
1617

17-
async function getRequestyKeyInfo(apiKey?: string) {
18+
async function getRequestyKeyInfo(baseUrl?: string, apiKey?: string) {
1819
if (!apiKey) return null
1920

21+
const url = toRequestyServiceUrl(baseUrl, "api")
22+
const apiKeyUrl = new URL("x/apikey", url)
23+
2024
try {
21-
const response = await axios.get("https://api.requesty.ai/x/apikey", {
25+
const response = await axios.get(apiKeyUrl.toString(), {
2226
headers: {
2327
Authorization: `Bearer ${apiKey}`,
2428
"Content-Type": "application/json",
@@ -39,10 +43,10 @@ async function getRequestyKeyInfo(apiKey?: string) {
3943
}
4044

4145
type UseRequestyKeyInfoOptions = Omit<UseQueryOptions<RequestyKeyInfo | null>, "queryKey" | "queryFn">
42-
export const useRequestyKeyInfo = (apiKey?: string, options?: UseRequestyKeyInfoOptions) => {
46+
export const useRequestyKeyInfo = (baseUrl?: string, apiKey?: string, options?: UseRequestyKeyInfoOptions) => {
4347
return useQuery<RequestyKeyInfo | null>({
4448
queryKey: ["requesty-key-info", apiKey],
45-
queryFn: () => getRequestyKeyInfo(apiKey),
49+
queryFn: () => getRequestyKeyInfo(baseUrl, apiKey),
4650
staleTime: 30 * 1000, // 30 seconds
4751
enabled: !!apiKey,
4852
...options,

0 commit comments

Comments
 (0)