Hub documentation

推理服务提供商

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

推理服务提供商

Hugging Face 的模型页面为数千个模型提供按量付费的推理服务,因此您可以直接在浏览器中试用所有这些模型。该服务由 Inference Providers 提供支持,PRO 用户以及 Team & Enterprise 组织每月享有包含的额度。

Inference Providers 为开发者提供简洁、统一的访问方式,可调用数百个机器学习模型,由最佳的无服务器推理合作伙伴提供支持。👉 完整文档请访问 Inference Providers 文档。

Hub 上的推理服务提供商

Inference Providers 与 Hugging Face Hub 深度集成,您可以通过以下几种方式使用它:

  • 交互式小部件 - 通过交互式小部件直接在模型页面上测试模型,其底层使用 Inference Providers。请查看 DeepSeek-R1-0528 模型页面 以获取示例。
  • 推理游乐场 - 轻松使用您的提示词测试和比较聊天补全模型。查看 推理游乐场 以开始使用。
  • 搜索 - 在模型页面上按推理提供商筛选模型,以查找通过特定提供商可用的模型。
  • Data Studio - 使用 AI 探索 Hub 上的数据集。在您的心仪数据集上查看 Data Studio。

使用推理提供商进行构建

您可以使用我们的 SDK 或 HTTP 客户端将 Inference Providers 集成到您自己的应用程序中。以下是使用 Python 和 JavaScript 的快速入门指南,更多详情请参阅 Inference Providers 文档。

python
javascript

您可以使用我们的 Python SDK 与 Inference Providers 进行交互。

from huggingface_hub import InferenceClient

import os

client = InferenceClient(
    api_key=os.environ["HF_TOKEN"],
    provider="auto",   # Automatically selects best provider
)

# Chat completion
completion = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V3-0324",
    messages=[{"role": "user", "content": "A story about hiking in the mountains"}]
)

# Image generation
image = client.text_to_image(
    prompt="A serene lake surrounded by mountains at sunset, photorealistic style",
    model="black-forest-labs/FLUX.1-dev"
)

或者,您可以直接使用兼容 OpenAI API 的客户端。

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://router.huggingface.co/v1",
    api_key=os.environ["HF_TOKEN"],
)

completion = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V3-0324",
    messages=[
        {
            "role": "user",
            "content": "A story about hiking in the mountains"
        }
    ],
)

OpenAI API 兼容客户端不支持图像生成。

您需要一个具有推理权限的 Hugging Face 令牌。请在 Settings > Tokens 中创建一个。

Inference Providers 的工作原理

如需深入了解 Inference Providers,请参阅 Inference Providers 文档。以下是一些关键资源:

HF-Inference API 是什么?

HF-Inference API 是通过 Inference Providers 可用的提供商之一。它此前被称为“Inference API (serverless)”,其底层由 Inference Endpoints 提供支持。

如需了解 HF-Inference 提供商的更多详细信息,请查看其专属页面。

Update on GitHub