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

+21
View File
@@ -0,0 +1,21 @@
const REQUESTY_BASE_URL = "https://router.requesty.ai/v1"
type URLType = "router" | "app" | "api"
const replaceCname = (baseUrl: string, type: URLType): string => {
if (type === "router") {
return baseUrl
} else {
return baseUrl.replace("router", type).replace("v1", "")
}
}
export const toRequestyServiceUrl = (baseUrl?: string, service: URLType = "router"): URL => {
const url = replaceCname(baseUrl ?? REQUESTY_BASE_URL, service)
return new URL(url)
}
export const toRequestyServiceStringUrl = (baseUrl?: string, service: URLType = "router"): string => {
return toRequestyServiceUrl(baseUrl, service).toString()
}