Skip to content

Commit

Permalink
throw error on closed source + HF
Browse files Browse the repository at this point in the history
  • Loading branch information
Wauplin committed Feb 25, 2025
1 parent c56bfc3 commit 34d61d0
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions packages/inference/src/lib/makeRequestOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,23 @@ export async function makeRequestOptions(
fetch: options?.fetch,
});

// If accessToken is passed, it should take precedence over includeCredentials
// Closed-source providers require an accessToken (cannot be routed).
const authMethod = providerConfig.closedSource
? "provider-key"
: accessToken
? accessToken.startsWith("hf_")
? "hf-token"
: "provider-key"
: includeCredentials === "include"
? "credentials-include"
: "none";
const authMethod = (() => {
if (providerConfig.closedSource) {
// Closed-source providers require an accessToken (cannot be routed).
if (accessToken && accessToken.startsWith("hf_")) {
throw new Error(`Provider ${provider} is closed-source and does not support HF tokens.`);
}
return "provider-key";
}
if (accessToken) {
return accessToken.startsWith("hf_") ? "hf-token" : "provider-key";
}
if (includeCredentials === "include") {
// If accessToken is passed, it should take precedence over includeCredentials
return "credentials-include";
}
return "none";
})();

// Make URL
const url = endpointUrl
Expand Down

1 comment on commit 34d61d0

@julien-c
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

Please sign in to comment.