@@ -94,30 +94,173 @@ Enterprise Hub organizations receive a pool of free usage credits based on the n
9494 <img class="hidden dark:block" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/inference-providers/enterprise-org-settings-dark.png"/>
9595</div >
9696
97- If you are using the JavaScript ` InferenceClient ` , you can set the ` billTo ` attribute at a client level:
97+
98+
99+ <hfoptions id =" python-clients " >
100+
101+ <hfoption id =" huggingface_hub " >
102+
103+ To bill your organization, use the ` bill_to ` parameter when initializing the client.
104+
105+ ``` python
106+ import os
107+ from huggingface_hub import InferenceClient
108+
109+ client = InferenceClient(bill_to = " my-org-name" )
110+
111+ completion = client.chat.completions.create(
112+ model = " deepseek-ai/DeepSeek-V3-0324" ,
113+ messages = [
114+ {
115+ " role" : " user" ,
116+ " content" : " How many 'G's in 'huggingface'?"
117+ }
118+ ],
119+ )
120+
121+ print (completion.choices[0 ].message)
122+ ```
123+
124+ </hfoption >
125+
126+ <hfoption id =" openai " >
127+
128+ To bill your organization when using OpenAI's Python client, set the ` X-HF-Bill-To ` header using ` extra_headers ` .
129+
130+ ``` python
131+ import os
132+ from openai import OpenAI
133+
134+ client = OpenAI(
135+ base_url = " https://router.huggingface.co/v1" ,
136+ api_key = os.environ[" HF_TOKEN" ],
137+ extra_headers = {" X-HF-Bill-To" : " my-org-name" },
138+ )
139+
140+ completion = client.chat.completions.create(
141+ model = " deepseek-ai/DeepSeek-V3-0324" ,
142+ messages = [
143+ {
144+ " role" : " user" ,
145+ " content" : " How many 'G's in 'huggingface'?"
146+ }
147+ ],
148+ )
149+ ```
150+
151+ </hfoption >
152+
153+ <hfoption id =" requests " >
154+
155+ To bill your organization when making direct HTTP requests, include the ` X-HF-Bill-To ` header.
156+
157+ ``` python
158+ import os
159+ import requests
160+
161+ API_URL = " https://router.huggingface.co/v1/chat/completions"
162+ headers = {" Authorization" : f " Bearer { os.environ[' HF_TOKEN' ]} " , " X-HF-Bill-To" : " my-org-name" }
163+ payload = {
164+ " messages" : [
165+ {
166+ " role" : " user" ,
167+ " content" : " How many 'G's in 'huggingface'?"
168+ }
169+ ],
170+ " model" : " deepseek-ai/DeepSeek-V3-0324" ,
171+ }
172+
173+ response = requests.post(API_URL , headers = headers, json = payload)
174+ print (response.json()[" choices" ][0 ][" message" ])
175+ ```
176+
177+ </hfoption >
178+
179+ </hfoptions >
180+
181+ Similarily in JavaScript:
182+
183+ <hfoptions id =" javascript-clients " >
184+
185+ <hfoption id =" huggingface.js " >
186+
187+ If you are using the JavaScript ` InferenceClient ` , you can set the ` billTo ` attribute at a client level to bill your organization.
98188
99189``` js
100190import { InferenceClient } from " @huggingface/inference" ;
101191
102- const client = new InferenceClient (" hf_token " , { billTo: " my-org-name" });
192+ const client = new InferenceClient (process . env . HF_TOKEN , { billTo: " my-org-name" });
103193
104- const image = await client .textToImage ({
105- model: " black-forest-labs/FLUX.1-schnell" ,
106- inputs: " A majestic lion in a fantasy forest" ,
107- provider: " fal-ai" ,
194+ const completion = await client .chat .completions .create ({
195+ model: " deepseek-ai/DeepSeek-V3-0324" ,
196+ messages: [
197+ {
198+ role: " user" ,
199+ content: " How many 'G's in 'huggingface'?" ,
200+ },
201+ ],
108202});
109- // / Use the generated image (it's a Blob)
110203```
111204
112- And similarly in Python:
205+ </ hfoption >
113206
114- ``` py
115- from huggingface_hub import InferenceClient
116- client = InferenceClient(provider = " fal-ai" , bill_to = " my-org-name" )
117- image = client.text_to_image(
118- " A majestic lion in a fantasy forest" ,
119- model = " black-forest-labs/FLUX.1-schnell" ,
120- )
121- image.save(" lion.png" )
207+ <hfoption id =" openai " >
208+
209+ To bill your organization with the OpenAI JavaScript client, set the ` X-HF-Bill-To ` header using the ` defaultHeaders ` option.
210+
211+ ``` javascript
212+ import OpenAI from " openai" ;
213+
214+ const client = new OpenAI ({
215+ baseURL: " https://router.huggingface.co/v1" ,
216+ apiKey: process .env .HF_TOKEN ,
217+ defaultHeaders: { " X-HF-Bill-To" : " my-org-name" },
218+ });
219+
220+ const completion = await client .chat .completions .create ({
221+ model: " deepseek-ai/DeepSeek-V3-0324" ,
222+ messages: [
223+ {
224+ role: " user" ,
225+ content: " How many 'G's in 'huggingface'?" ,
226+ },
227+ ],
228+ });
229+
230+ console .log (completion .choices [0 ].message .content );
231+ ```
232+
233+ </hfoption >
234+
235+ <hfoption id =" fetch " >
236+
237+ When using ` fetch ` , include the ` X-HF-Bill-To ` header to bill your organization.
238+
239+ ``` js
240+ import fetch from " node-fetch" ;
241+
242+ const response = await fetch (
243+ " https://router.huggingface.co/v1/chat/completions" ,
244+ {
245+ method: " POST" ,
246+ headers: {
247+ Authorization: ` Bearer ${ process .env .HF_TOKEN } ` ,
248+ " Content-Type" : " application/json" ,
249+ " X-HF-Bill-To" : " my-org-name" ,
250+ },
251+ body: JSON .stringify ({
252+ model: " deepseek-ai/DeepSeek-V3-0324" ,
253+ messages: [
254+ {
255+ role: " user" ,
256+ content: " How many 'G's in 'huggingface'?" ,
257+ },
258+ ],
259+ }),
260+ }
261+ );
262+ console .log (await response .json ());
122263```
264+ </hfoption >
123265
266+ </hfoptions >
0 commit comments