Skip to content

Commit ed51aef

Browse files
committed
fix(litellm): handle baseurl with paths correctly
1 parent a163053 commit ed51aef

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/api/providers/fetchers/__tests__/litellm.spec.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,48 @@ describe("getLiteLLMModels", () => {
3939
})
4040
})
4141

42+
it("handles base URLs with a path correctly", async () => {
43+
const mockResponse = {
44+
data: {
45+
data: [],
46+
},
47+
}
48+
49+
mockedAxios.get.mockResolvedValue(mockResponse)
50+
51+
await getLiteLLMModels("test-api-key", "http://localhost:4000/litellm")
52+
53+
expect(mockedAxios.get).toHaveBeenCalledWith("http://localhost:4000/litellm/v1/model/info", {
54+
headers: {
55+
Authorization: "Bearer test-api-key",
56+
"Content-Type": "application/json",
57+
...DEFAULT_HEADERS,
58+
},
59+
timeout: 5000,
60+
})
61+
})
62+
63+
it("handles base URLs with a path and trailing slash correctly", async () => {
64+
const mockResponse = {
65+
data: {
66+
data: [],
67+
},
68+
}
69+
70+
mockedAxios.get.mockResolvedValue(mockResponse)
71+
72+
await getLiteLLMModels("test-api-key", "http://localhost:4000/litellm/")
73+
74+
expect(mockedAxios.get).toHaveBeenCalledWith("http://localhost:4000/litellm/v1/model/info", {
75+
headers: {
76+
Authorization: "Bearer test-api-key",
77+
"Content-Type": "application/json",
78+
...DEFAULT_HEADERS,
79+
},
80+
timeout: 5000,
81+
})
82+
})
83+
4284
it("successfully fetches and formats LiteLLM models", async () => {
4385
const mockResponse = {
4486
data: {

src/api/providers/fetchers/litellm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export async function getLiteLLMModels(apiKey: string, baseUrl: string): Promise
2424
headers["Authorization"] = `Bearer ${apiKey}`
2525
}
2626
// Use URL constructor to properly join base URL and path
27-
const url = new URL("/v1/model/info", baseUrl).href
27+
const url = new URL("v1/model/info", baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`).href
2828
// Added timeout to prevent indefinite hanging
2929
const response = await axios.get(url, { headers, timeout: 5000 })
3030
const models: ModelRecord = {}

0 commit comments

Comments
 (0)