Hugging Face Hub 集成四家推理服务商

原标题:Welcome to Inference Providers on the Hub 🔥
48AI 研判分

Hugging Face Hub 正式集成 fal、Replicate、Sambanova 和 Together AI 四家无服务器推理提供商。开发者可通过模型页面或 SDK 直接调用这些服务,且 PRO 用户每月获赠 2 美元跨平台推理额度。

报道正文

本文目录8 个章节

返回文章列表

欢迎使用 Hub 上的推理提供商(Inference Providers)🔥

发布于 2025 年 1 月 28 日 在 GitHub 上更新 点赞 499

Burkay Gur burkaygur fal Zeke Sikelianos zeke replicate Anton McGonnell aton2006 sambanovasystems Hassan El Mghari hassanelmghari togethercomputer Simon Brandeis sbrandeis Bertrand Chevrier kramp Julien Chaumond julien-c

今天,我们正式推出与四个优秀的无服务器推理提供商——fal、Replicate、Sambanova 和 Together AI——的直接集成,这些功能现已上线 Hub 的模型页面。它们也无缝集成到了我们的客户端 SDK(支持 JS 和 Python)中,让您能够更轻松地在首选提供商上探索各种模型的无服务器推理。

推理提供商

我们在 Hub 上托管无服务器推理 API(Inference API)已有相当长的时间(v1 版本于 2020 年夏季发布——哇,时光飞逝 🤯)。虽然这促进了便捷的探索和原型开发,但我们已将核心价值主张转向与社区协作,以及大型数据集和模型的存储、版本管理和分发。与此同时,无服务器提供商蓬勃发展,现在正是 Hugging Face 通过一系列优秀提供商提供统一且便捷的无服务器推理接入的最佳时机。

正如我们与 AWS、Nvidia 等优秀合作伙伴合作,通过模型页面的“部署”按钮提供专用部署选项一样,与下一代无服务器推理提供商合作,以提供以模型为中心的无服务器推理服务也是顺理成章的选择。

以下是这一举措带来的可能性,我们以近期备受关注的 DeepSeek-ai/DeepSeek-R1 为例,该模型在过去几天内迅速走红 🔥:

Rodrigo Liang,SambaNova 联合创始人兼首席执行官:“我们很高兴能与 Hugging Face 合作,加速其 Inference API 的发展。Hugging Face 的开发者现在可以在广泛的最佳开源模型上获得更快的推理速度。”

Zeke Sikelianos,Replicate 创始设计师:“Hugging Face 是开源模型权重的事实上的家园,也是让 AI 更易于全球获取的关键推动者。我们在 Replicate 内部将 Hugging Face 作为首选的权重注册表,并且很荣幸成为首批在此次发布中展示的推理服务提供商之一。”

这仅仅是开始,我们将在接下来的几周内与社区共同在此基础上继续构建!

工作原理

在网站 UI 中

  1. 在您的用户账户设置中,您可以:
  • 为您已注册的提供商设置自己的 API 密钥。否则,您仍然可以使用它们——您的请求将通过 HF 进行路由。
  • 按偏好对提供商进行排序。此设置适用于模型页面中的小部件和代码片段。

Inference Providers

  1. 正如我们提到的,调用 Inference APIs 时有两种模式:
  • 自定义密钥(请求直接发送到推理提供商,使用您对应推理提供商的自有 API 密钥);或
  • 由 HF 路由(在这种情况下,您不需要提供商的令牌,费用将直接计入您的 HF 账户,而非提供商的账户)

Inference Providers

  1. 模型页面展示第三方推理提供商(即与当前模型兼容的提供商,按用户偏好排序)

Inference Providers

从客户端 SDKs

使用 Python 和 huggingface_hub

以下示例展示了如何使用 Together AI 作为推理提供商来调用 DeepSeek-R1。您可以使用 Hugging Face token 通过 Hugging Face 进行自动路由,或者如果您有的话,也可以使用您自己的 Together AI API 密钥。

Install huggingface_hub version v0.28.0 or later (release notes).

PYTHON
from huggingface_hub import InferenceClient

client = InferenceClient(
    provider="together",
    api_key="xxxxxxxxxxxxxxxxxxxxxxxx"
)

messages = [
    {
        "role": "user",
        "content": "What is the capital of France?"
    }
]

completion = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-R1", 
    messages=messages, 
    max_tokens=500
)

print(completion.choices[0].message)

Note: You can also use the OpenAI client library to call the Inference Providers too; see here an example for DeepSeek model.

And here's how to generate an image from a text prompt using FLUX.1-dev running on fal.ai:

PYTHON
from huggingface_hub import InferenceClient

client = InferenceClient(
    provider="fal-ai",
    api_key="xxxxxxxxxxxxxxxxxxxxxxxx"
)

image = client.text_to_image(
    "Labrador in the style of Vermeer",
    model="black-forest-labs/FLUX.1-dev"
)

To move to a different provider, you can simply change the provider name, everything else stays the same:

DIFF
from huggingface_hub import InferenceClient

client = InferenceClient(
-	provider="fal-ai",
+	provider="replicate",
    api_key="xxxxxxxxxxxxxxxxxxxxxxxx"
)

from JS using @huggingface/inference

JAVASCRIPT
import { HfInference } from "@huggingface/inference";

const client = new HfInference("xxxxxxxxxxxxxxxxxxxxxxxx");

const chatCompletion = await client.chatCompletion({
    model: "deepseek-ai/DeepSeek-R1",
    messages: [
        {
            role: "user",
            content: "What is the capital of France?"
        }
    ],
    provider: "together",
    max_tokens: 500
});

console.log(chatCompletion.choices[0].message);

From HTTP calls

We expose the Routing proxy directly under the huggingface.co domain so you can call it directly, it's very useful for OpenAI-compatible APIs for instance. You can just swap the URL as a base URL: https://router.huggingface.co/{:provider}.

Here's how you can call Llama-3.3-70B-Instruct using Sambanova as the inference provider via cURL.

BASH
curl 'https://router.huggingface.co/sambanova/v1/chat/completions' \
-H 'Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxx' \
-H 'Content-Type: application/json' \
--data '{
    "model": "Llama-3.3-70B-Instruct",
    "messages": [
        {
            "role": "user",
            "content": "What is the capital of France?"
        }
    ],
    "max_tokens": 500,
    "stream": false
}'

Billing

For direct requests, i.e. when you use the key from an inference provider, you are billed by the corresponding provider. For instance, if you use a Together AI key you're billed on your Together AI account.

For routed requests, i.e. when you authenticate via the hub, you'll only pay the standard provider API rates. There's no additional markup from us, we just pass through the provider costs directly. (In the future, we may establish revenue-sharing agreements with our provider partners.)

Important Note ‼️ PRO users get $2 worth of Inference credits every month. You can use them across providers. 🔥