Skip to content

[InferenceClient] Support billTo header #1297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/inference/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const HF_HUB_URL = "https://huggingface.co";
export const HF_ROUTER_URL = "https://router.huggingface.co";
export const HF_HEADER_X_BILL_TO = "X-HF-Bill-To";
7 changes: 5 additions & 2 deletions packages/inference/src/lib/makeRequestOptions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HF_HUB_URL, HF_ROUTER_URL } from "../config";
import { HF_HUB_URL, HF_ROUTER_URL, HF_HEADER_X_BILL_TO } from "../config";
import { BLACK_FOREST_LABS_CONFIG } from "../providers/black-forest-labs";
import { CEREBRAS_CONFIG } from "../providers/cerebras";
import { COHERE_CONFIG } from "../providers/cohere";
Expand Down Expand Up @@ -116,7 +116,7 @@ export function makeRequestOptionsFromResolvedModel(
const provider = maybeProvider ?? "hf-inference";
const providerConfig = providerConfigs[provider];

const { includeCredentials, task, chatCompletion, signal } = options ?? {};
const { includeCredentials, task, chatCompletion, signal, billTo } = options ?? {};

const authMethod = (() => {
if (providerConfig.clientSideRoutingOnly) {
Expand Down Expand Up @@ -157,6 +157,9 @@ export function makeRequestOptionsFromResolvedModel(
accessToken,
authMethod,
});
if (billTo) {
headers[HF_HEADER_X_BILL_TO] = billTo;
}

// Add content-type to headers
if (!binary) {
Expand Down
8 changes: 8 additions & 0 deletions packages/inference/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ export interface Options {
* (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.
*/
includeCredentials?: string | boolean;

/**
* The billing account to use for the requests.
*
* By default the requests are billed on the user's account.
* Requests can only be billed to an organization the user is a member of, and which has subscribed to Enterprise Hub.
*/
billTo?: string;
}

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