Skip to content

Commit 071a0ba

Browse files
authored
[inference providers] wavespeed: override base URL to use router.huggingface.co (#1820)
Fixes CORS and authentication issues when requesting wavespeed through router.huggingface.co
1 parent 4937e3b commit 071a0ba

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

packages/inference/src/providers/wavespeed.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,17 @@ abstract class WavespeedAITask extends TaskProviderHelper {
9595
url?: string,
9696
headers?: Record<string, string>
9797
): Promise<Blob> {
98-
if (!headers) {
98+
if (!url || !headers) {
9999
throw new InferenceClientInputError("Headers are required for WaveSpeed AI API calls");
100100
}
101101

102-
const resultUrl = response.data.urls.get;
102+
const parsedUrl = new URL(url);
103+
const resultPath = new URL(response.data.urls.get).pathname;
104+
/// override the base url to use the router.huggingface.co if going through huggingface router
105+
const baseUrl = `${parsedUrl.protocol}//${parsedUrl.host}${
106+
parsedUrl.host === "router.huggingface.co" ? "/wavespeed" : ""
107+
}`;
108+
const resultUrl = `${baseUrl}${resultPath}`;
103109

104110
// Poll for results until completion
105111
while (true) {

0 commit comments

Comments
 (0)