@@ -4,8 +4,10 @@ import { NEBIUS_API_BASE_URL } from "../providers/nebius";
44import { REPLICATE_API_BASE_URL } from "../providers/replicate" ;
55import { SAMBANOVA_API_BASE_URL } from "../providers/sambanova" ;
66import { TOGETHER_API_BASE_URL } from "../providers/together" ;
7+ import { NOVITA_API_BASE_URL } from "../providers/novita" ;
78import { FIREWORKS_AI_API_BASE_URL } from "../providers/fireworks-ai" ;
89import { HYPERBOLIC_API_BASE_URL } from "../providers/hyperbolic" ;
10+ import { BLACKFORESTLABS_AI_API_BASE_URL } from "../providers/black-forest-labs" ;
911import type { InferenceProvider } from "../types" ;
1012import type { InferenceTask , Options , RequestArgs } from "../types" ;
1113import { isUrl } from "./isUrl" ;
@@ -29,8 +31,6 @@ export async function makeRequestOptions(
2931 stream ?: boolean ;
3032 } ,
3133 options ?: Options & {
32- /** When a model can be used for multiple tasks, and we want to run a non-default task */
33- forceTask ?: string | InferenceTask ;
3434 /** To load default model if needed */
3535 taskHint ?: InferenceTask ;
3636 chatCompletion ?: boolean ;
@@ -40,14 +40,11 @@ export async function makeRequestOptions(
4040 let otherArgs = remainingArgs ;
4141 const provider = maybeProvider ?? "hf-inference" ;
4242
43- const { forceTask , includeCredentials, taskHint, chatCompletion } = options ?? { } ;
43+ const { includeCredentials, taskHint, chatCompletion } = options ?? { } ;
4444
4545 if ( endpointUrl && provider !== "hf-inference" ) {
4646 throw new Error ( `Cannot use endpointUrl with a third-party provider.` ) ;
4747 }
48- if ( forceTask && provider !== "hf-inference" ) {
49- throw new Error ( `Cannot use forceTask with a third-party provider.` ) ;
50- }
5148 if ( maybeModel && isUrl ( maybeModel ) ) {
5249 throw new Error ( `Model URLs are no longer supported. Use endpointUrl instead.` ) ;
5350 }
@@ -78,16 +75,20 @@ export async function makeRequestOptions(
7875 : makeUrl ( {
7976 authMethod,
8077 chatCompletion : chatCompletion ?? false ,
81- forceTask,
8278 model,
8379 provider : provider ?? "hf-inference" ,
8480 taskHint,
8581 } ) ;
8682
8783 const headers : Record < string , string > = { } ;
8884 if ( accessToken ) {
89- headers [ "Authorization" ] =
90- provider === "fal-ai" && authMethod === "provider-key" ? `Key ${ accessToken } ` : `Bearer ${ accessToken } ` ;
85+ if ( provider === "fal-ai" && authMethod === "provider-key" ) {
86+ headers [ "Authorization" ] = `Key ${ accessToken } ` ;
87+ } else if ( provider === "black-forest-labs" && authMethod === "provider-key" ) {
88+ headers [ "X-Key" ] = accessToken ;
89+ } else {
90+ headers [ "Authorization" ] = `Bearer ${ accessToken } ` ;
91+ }
9192 }
9293
9394 // e.g. @huggingface /inference/3.1.3
@@ -149,14 +150,19 @@ function makeUrl(params: {
149150 model : string ;
150151 provider : InferenceProvider ;
151152 taskHint : InferenceTask | undefined ;
152- forceTask ?: string | InferenceTask ;
153153} ) : string {
154154 if ( params . authMethod === "none" && params . provider !== "hf-inference" ) {
155155 throw new Error ( "Authentication is required when requesting a third-party provider. Please provide accessToken" ) ;
156156 }
157157
158158 const shouldProxy = params . provider !== "hf-inference" && params . authMethod !== "provider-key" ;
159159 switch ( params . provider ) {
160+ case "black-forest-labs" : {
161+ const baseUrl = shouldProxy
162+ ? HF_HUB_INFERENCE_PROXY_TEMPLATE . replace ( "{{PROVIDER}}" , params . provider )
163+ : BLACKFORESTLABS_AI_API_BASE_URL ;
164+ return `${ baseUrl } /${ params . model } ` ;
165+ }
160166 case "fal-ai" : {
161167 const baseUrl = shouldProxy
162168 ? HF_HUB_INFERENCE_PROXY_TEMPLATE . replace ( "{{PROVIDER}}" , params . provider )
@@ -216,6 +222,7 @@ function makeUrl(params: {
216222 }
217223 return baseUrl ;
218224 }
225+
219226 case "fireworks-ai" : {
220227 const baseUrl = shouldProxy
221228 ? HF_HUB_INFERENCE_PROXY_TEMPLATE . replace ( "{{PROVIDER}}" , params . provider )
@@ -235,15 +242,28 @@ function makeUrl(params: {
235242 }
236243 return `${ baseUrl } /v1/chat/completions` ;
237244 }
245+ case "novita" : {
246+ const baseUrl = shouldProxy
247+ ? HF_HUB_INFERENCE_PROXY_TEMPLATE . replace ( "{{PROVIDER}}" , params . provider )
248+ : NOVITA_API_BASE_URL ;
249+ if ( params . taskHint === "text-generation" ) {
250+ if ( params . chatCompletion ) {
251+ return `${ baseUrl } /chat/completions` ;
252+ }
253+ return `${ baseUrl } /completions` ;
254+ }
255+ return baseUrl ;
256+ }
238257 default : {
239258 const baseUrl = HF_HUB_INFERENCE_PROXY_TEMPLATE . replaceAll ( "{{PROVIDER}}" , "hf-inference" ) ;
240- const url = params . forceTask
241- ? `${ baseUrl } /pipeline/${ params . forceTask } /${ params . model } `
242- : `${ baseUrl } /models/${ params . model } ` ;
259+ if ( params . taskHint && [ "feature-extraction" , "sentence-similarity" ] . includes ( params . taskHint ) ) {
260+ /// when deployed on hf-inference, those two tasks are automatically compatible with one another.
261+ return `${ baseUrl } /pipeline/${ params . taskHint } /${ params . model } ` ;
262+ }
243263 if ( params . taskHint === "text-generation" && params . chatCompletion ) {
244- return url + ` /v1/chat/completions`;
264+ return ` ${ baseUrl } /models/ ${ params . model } /v1/chat/completions`;
245265 }
246- return url ;
266+ return ` ${ baseUrl } /models/ ${ params . model } ` ;
247267 }
248268 }
249269}
0 commit comments