Skip to content

Commit a74e4ee

Browse files
authored
[InferenceClient] Support billTo header (#1297)
Related to huggingface/huggingface_hub#2940. Discussed in [DMs](https://huggingface.slack.com/archives/C07KX53FZTK/p1741882879007139) (private link) Basically adds a parameter allowing a user to be charge all their requests on their organization account instead of personal account. PR to merge only once `"X-HF-Bill-To"` header is supported server side cc @SBrandeis ```ts import { InferenceClient } from "@huggingface/inference"; const client = new InferenceClient("hf_token", { billTo: "huggingface" }); const image = await client.textToImage({ model: "black-forest-labs/FLUX.1-schnell", inputs: "A majestic lion in a fantasy forest", provider: "fal-ai", }); /// Use the generated image (it's a Blob) ```
1 parent c925df8 commit a74e4ee

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

packages/inference/src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export const HF_HUB_URL = "https://huggingface.co";
22
export const HF_ROUTER_URL = "https://router.huggingface.co";
3+
export const HF_HEADER_X_BILL_TO = "X-HF-Bill-To";

packages/inference/src/lib/makeRequestOptions.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HF_HUB_URL, HF_ROUTER_URL } from "../config";
1+
import { HF_HUB_URL, HF_ROUTER_URL, HF_HEADER_X_BILL_TO } from "../config";
22
import { BLACK_FOREST_LABS_CONFIG } from "../providers/black-forest-labs";
33
import { CEREBRAS_CONFIG } from "../providers/cerebras";
44
import { COHERE_CONFIG } from "../providers/cohere";
@@ -117,7 +117,7 @@ export function makeRequestOptionsFromResolvedModel(
117117
const provider = maybeProvider ?? "hf-inference";
118118
const providerConfig = providerConfigs[provider];
119119

120-
const { includeCredentials, task, chatCompletion, signal } = options ?? {};
120+
const { includeCredentials, task, chatCompletion, signal, billTo } = options ?? {};
121121

122122
const authMethod = (() => {
123123
if (providerConfig.clientSideRoutingOnly) {
@@ -159,6 +159,9 @@ export function makeRequestOptionsFromResolvedModel(
159159
accessToken,
160160
authMethod,
161161
});
162+
if (billTo) {
163+
headers[HF_HEADER_X_BILL_TO] = billTo;
164+
}
162165

163166
// Add content-type to headers
164167
if (!binary) {

packages/inference/src/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ export interface Options {
2424
* (Default: "same-origin"). String | Boolean. Credentials to use for the request. If this is a string, it will be passed straight on. If it's a boolean, true will be "include" and false will not send credentials at all.
2525
*/
2626
includeCredentials?: string | boolean;
27+
28+
/**
29+
* The billing account to use for the requests.
30+
*
31+
* By default the requests are billed on the user's account.
32+
* Requests can only be billed to an organization the user is a member of, and which has subscribed to Enterprise Hub.
33+
*/
34+
billTo?: string;
2735
}
2836

2937
export type InferenceTask = Exclude<PipelineType, "other">;

0 commit comments

Comments
 (0)