From 7879a9e4196a1cacc0a65fc70672514d9a547935 Mon Sep 17 00:00:00 2001 From: Celina Hanouti Date: Mon, 7 Jul 2025 16:22:49 +0200 Subject: [PATCH 1/7] update billing snippets --- docs/inference-providers/pricing.md | 175 +++++++++++++++++++++++++--- 1 file changed, 159 insertions(+), 16 deletions(-) diff --git a/docs/inference-providers/pricing.md b/docs/inference-providers/pricing.md index ab06bf5a7b..979ca9fd5f 100644 --- a/docs/inference-providers/pricing.md +++ b/docs/inference-providers/pricing.md @@ -94,30 +94,173 @@ Enterprise Hub organizations receive a pool of free usage credits based on the n -If you are using the JavaScript `InferenceClient`, you can set the `billTo` attribute at a client level: + + + + + + +To bill your organization, use the `bill_to` parameter when initializing the client. + +```python +import os +from huggingface_hub import InferenceClient + +client = InferenceClient(bill_to="my-org-name") + +completion = client.chat.completions.create( + model="deepseek-ai/DeepSeek-V3-0324", + messages=[ + { + "role": "user", + "content": "How many 'G's in 'huggingface'?" + } + ], +) + +print(completion.choices[0].message) +``` + + + + + +To bill your organization when using OpenAI's Python client, set the `X-HF-Bill-To` header using `extra_headers`. + +```python +import os +from openai import OpenAI + +client = OpenAI( + base_url="https://router.huggingface.co/v1", + api_key=os.environ["HF_TOKEN"], + extra_headers={"X-HF-Bill-To": "my-org-name"}, +) + +completion = client.chat.completions.create( + model="deepseek-ai/DeepSeek-V3-0324", + messages=[ + { + "role": "user", + "content": "How many 'G's in 'huggingface'?" + } + ], +) +``` + + + + + +To bill your organization when making direct HTTP requests, include the `X-HF-Bill-To` header. + +```python +import os +import requests + +API_URL = "https://router.huggingface.co/v1/chat/completions" +headers = {"Authorization": f"Bearer {os.environ['HF_TOKEN']}", "X-HF-Bill-To": "my-org-name"} +payload = { + "messages": [ + { + "role": "user", + "content": "How many 'G's in 'huggingface'?" + } + ], + "model": "deepseek-ai/DeepSeek-V3-0324", +} + +response = requests.post(API_URL, headers=headers, json=payload) +print(response.json()["choices"][0]["message"]) +``` + + + + + +Similarily in JavaScript: + + + + + +If you are using the JavaScript `InferenceClient`, you can set the `billTo` attribute at a client level to bill your organization. ```js import { InferenceClient } from "@huggingface/inference"; -const client = new InferenceClient("hf_token", { billTo: "my-org-name" }); +const client = new InferenceClient(process.env.HF_TOKEN, { billTo: "my-org-name" }); -const image = await client.textToImage({ - model: "black-forest-labs/FLUX.1-schnell", - inputs: "A majestic lion in a fantasy forest", - provider: "fal-ai", +const completion = await client.chat.completions.create({ + model: "deepseek-ai/DeepSeek-V3-0324", + messages: [ + { + role: "user", + content: "How many 'G's in 'huggingface'?", + }, + ], }); -/// Use the generated image (it's a Blob) ``` -And similarly in Python: + -```py -from huggingface_hub import InferenceClient -client = InferenceClient(provider="fal-ai", bill_to="my-org-name") -image = client.text_to_image( - "A majestic lion in a fantasy forest", - model="black-forest-labs/FLUX.1-schnell", -) -image.save("lion.png") + + +To bill your organization with the OpenAI JavaScript client, set the `X-HF-Bill-To` header using the `defaultHeaders` option. + +```javascript +import OpenAI from "openai"; + +const client = new OpenAI({ + baseURL: "https://router.huggingface.co/v1", + apiKey: process.env.HF_TOKEN, + defaultHeaders: { "X-HF-Bill-To": "my-org-name" }, +}); + +const completion = await client.chat.completions.create({ + model: "deepseek-ai/DeepSeek-V3-0324", + messages: [ + { + role: "user", + content: "How many 'G's in 'huggingface'?", + }, + ], +}); + +console.log(completion.choices[0].message.content); +``` + + + + + +When using `fetch`, include the `X-HF-Bill-To` header to bill your organization. + +```js +import fetch from "node-fetch"; + +const response = await fetch( + "https://router.huggingface.co/v1/chat/completions", + { + method: "POST", + headers: { + Authorization: `Bearer ${process.env.HF_TOKEN}`, + "Content-Type": "application/json", + "X-HF-Bill-To": "my-org-name", + }, + body: JSON.stringify({ + model: "deepseek-ai/DeepSeek-V3-0324", + messages: [ + { + role: "user", + content: "How many 'G's in 'huggingface'?", + }, + ], + }), + } +); +console.log(await response.json()); ``` + + From 5fc2594ff775daab72013ef10d7ff87c94065268 Mon Sep 17 00:00:00 2001 From: Celina Hanouti Date: Mon, 7 Jul 2025 16:30:41 +0200 Subject: [PATCH 2/7] nit --- docs/inference-providers/pricing.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/inference-providers/pricing.md b/docs/inference-providers/pricing.md index 979ca9fd5f..cfb59e2efc 100644 --- a/docs/inference-providers/pricing.md +++ b/docs/inference-providers/pricing.md @@ -146,6 +146,8 @@ completion = client.chat.completions.create( } ], ) + +print(completion.choices[0].message) ``` @@ -200,6 +202,8 @@ const completion = await client.chat.completions.create({ }, ], }); + +console.log(completion.choices[0].message.content); ``` From 01be74622823407d9194ee69558e992af6f88099 Mon Sep 17 00:00:00 2001 From: Celina Hanouti Date: Mon, 7 Jul 2025 16:46:39 +0200 Subject: [PATCH 3/7] fix snippet --- docs/inference-providers/pricing.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/inference-providers/pricing.md b/docs/inference-providers/pricing.md index cfb59e2efc..81e1f391df 100644 --- a/docs/inference-providers/pricing.md +++ b/docs/inference-providers/pricing.md @@ -134,7 +134,7 @@ from openai import OpenAI client = OpenAI( base_url="https://router.huggingface.co/v1", api_key=os.environ["HF_TOKEN"], - extra_headers={"X-HF-Bill-To": "my-org-name"}, + ) completion = client.chat.completions.create( @@ -145,6 +145,7 @@ completion = client.chat.completions.create( "content": "How many 'G's in 'huggingface'?" } ], + extra_headers={"X-HF-Bill-To": "my-org-name"}, ) print(completion.choices[0].message) From 433c79f8b6cb8c61d7f31ad60d9ff4f12d69de46 Mon Sep 17 00:00:00 2001 From: Celina Hanouti Date: Mon, 7 Jul 2025 16:47:11 +0200 Subject: [PATCH 4/7] extra space --- docs/inference-providers/pricing.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/inference-providers/pricing.md b/docs/inference-providers/pricing.md index 81e1f391df..da8624b822 100644 --- a/docs/inference-providers/pricing.md +++ b/docs/inference-providers/pricing.md @@ -134,7 +134,6 @@ from openai import OpenAI client = OpenAI( base_url="https://router.huggingface.co/v1", api_key=os.environ["HF_TOKEN"], - ) completion = client.chat.completions.create( From c6af77ff34f9470d83889097ee32cc9c1b95a782 Mon Sep 17 00:00:00 2001 From: Celina Hanouti Date: Mon, 7 Jul 2025 16:49:21 +0200 Subject: [PATCH 5/7] better openai js snippet --- docs/inference-providers/pricing.md | 30 +++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/docs/inference-providers/pricing.md b/docs/inference-providers/pricing.md index da8624b822..85c850d262 100644 --- a/docs/inference-providers/pricing.md +++ b/docs/inference-providers/pricing.md @@ -216,20 +216,26 @@ To bill your organization with the OpenAI JavaScript client, set the `X-HF-Bill- import OpenAI from "openai"; const client = new OpenAI({ - baseURL: "https://router.huggingface.co/v1", - apiKey: process.env.HF_TOKEN, - defaultHeaders: { "X-HF-Bill-To": "my-org-name" }, + baseURL: "https://router.huggingface.co/v1", + apiKey: process.env.HF_TOKEN, }); -const completion = await client.chat.completions.create({ - model: "deepseek-ai/DeepSeek-V3-0324", - messages: [ - { - role: "user", - content: "How many 'G's in 'huggingface'?", - }, - ], -}); +const completion = await client.chat.completions.create( + { + model: "deepseek-ai/DeepSeek-V3-0324", + messages: [ + { + role: "user", + content: "How many 'G's in 'huggingface'?", + }, + ], + }, + { + headers: { + "X-HF-Bill-To": "my-org-name", + }, + } +); console.log(completion.choices[0].message.content); ``` From ab71d310c0c333b13a59530c92e3e88f81198361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?c=C3=A9lina?= Date: Mon, 7 Jul 2025 17:31:29 +0200 Subject: [PATCH 6/7] Apply suggestions from code review Co-authored-by: Simon Brandeis <33657802+SBrandeis@users.noreply.github.com> --- docs/inference-providers/pricing.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/inference-providers/pricing.md b/docs/inference-providers/pricing.md index 85c850d262..be1952f9ae 100644 --- a/docs/inference-providers/pricing.md +++ b/docs/inference-providers/pricing.md @@ -103,7 +103,6 @@ Enterprise Hub organizations receive a pool of free usage credits based on the n To bill your organization, use the `bill_to` parameter when initializing the client. ```python -import os from huggingface_hub import InferenceClient client = InferenceClient(bill_to="my-org-name") From 21f56495aed26a9e083ff83c24718b9867e2c7bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?c=C3=A9lina?= Date: Tue, 8 Jul 2025 13:34:09 +0200 Subject: [PATCH 7/7] Apply suggestions from code review Co-authored-by: Julien Chaumond --- docs/inference-providers/pricing.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/inference-providers/pricing.md b/docs/inference-providers/pricing.md index be1952f9ae..2da96e9538 100644 --- a/docs/inference-providers/pricing.md +++ b/docs/inference-providers/pricing.md @@ -124,7 +124,7 @@ print(completion.choices[0].message) -To bill your organization when using OpenAI's Python client, set the `X-HF-Bill-To` header using `extra_headers`. +To bill your organization when using OpenAI's Python client, set the `X-HF-Bill-To` header using `extra_headers` on the `completions.create` method call. ```python import os @@ -209,7 +209,7 @@ console.log(completion.choices[0].message.content); -To bill your organization with the OpenAI JavaScript client, set the `X-HF-Bill-To` header using the `defaultHeaders` option. +To bill your organization with the OpenAI JavaScript client, set the `X-HF-Bill-To` header using the `defaultHeaders` option on the `completions.create` method call. ```javascript import OpenAI from "openai";