DeepInfra 与 Hugging Face 推理提供商集成

DeepInfra 与 Hugging Face 推理提供商集成

Hugging Face 已将 DeepInfra 集成为 Hugging Face Hub 上支持的推理提供商。此集成使开发者能够直接通过 Hugging Face 的基础设施和客户端 SDK 访问 DeepInfra 的无服务器 AI 推理平台及其超过 100 种模型的目录。

无服务器推理能力

DeepInfra 为广泛的 AI 能力提供具成本效益的无服务器推理。虽然该平台支持多种模型类型,包括文本到图像、文本到视频和嵌入,但与 Hugging Face 的初始集成侧重于 对话和文本生成任务

Supported open-weight LLMs available through this integration include:

  • DeepSeek V4
  • Kimi-K2.6
  • GLM-5.1

Support for additional tasks such as embeddings, text-to-video, and text-to-image is scheduled to roll out in the future.

集成与工作流程

Users can access DeepInfra-hosted models through the Hugging Face website UI or via client SDKs.

网站 UI 配置

In the user account settings, users can manage their inference experience in two ways:

  1. 自定义 API 密钥:用户可以为提供商设置自己的 API 密钥。在这种情况下,请求将直接发送到提供商。
  2. 提供商偏好:用户可以按偏好顺序排列提供商,这会影响模型页面上小部件和代码片段的顺序。

请求路由模式

There are two distinct modes for calling Inference Providers:

  • 自定义密钥模式:使用用户特定于提供商的 API 密钥,调用将直接发送到推理提供商。
  • 由 HF 路由模式:请求通过 Hugging Face 路由。用户不需要提供商特定的令牌,费用将直接应用于 Hugging Face 账户。

客户端 SDK 支持

DeepInfra is accessible via the huggingface_hub (version 1.11.2 or higher) for Python and @huggingface/inference for JavaScript. The integration also extends to various Agent Harnesses, including OpenClaw, Hermes Agents, OpenCode, and Pi, allowing models to be plugged into these tools without additional glue code.

计费与积分

Billing depends on the routing method used:

  • 直接请求:用户由推理提供商(例如 DeepInfra)根据其提供商账户进行计费。
  • 路由请求:用户通过 Hugging Face 支付标准提供商 API 费用。Hugging Face 不会在这些费用上加价。

Hugging Face PRO 订阅者每月可获得价值 2 美元的推理积分,可跨不同提供商使用。已登录的免费用户将获得少量免费推理额度。

技术实现示例

To use a DeepInfra-hosted model (such as DeepSeek V4 Pro) via Python, the OpenAI-compatible client can be used with the Hugging Face router:

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-V4-Pro:deepinfra",
    messages=[
        {
            "role": "user",
            "content": "Write a Python function that returns the nth Fibonacci number using memoization."n        }
    ],
)

print(completion.choices[0].message)

Sources