DeepInfra Integration with Hugging Face Inference Providers

DeepInfra Integration with Hugging Face Inference Providers

Hugging Face has integrated DeepInfra as a supported Inference Provider on the Hugging Face Hub. This integration allows developers to access DeepInfra's serverless AI inference platform and its catalog of over 100 models directly through Hugging Face's infrastructure and client SDKs.

Serverless Inference Capabilities

DeepInfra provides cost-effective serverless inference for a wide range of AI capabilities. While the platform supports various model types including text-to-image, text-to-video, and embeddings, the initial integration with Hugging Face focuses on conversational and text-generation tasks.

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.

Integration and Workflow

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

Website UI Configuration

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

  1. Custom API Keys: Users can set their own API keys for providers. In this case, requests are sent directly to the provider.
  2. Provider Preference: Users can order providers by preference, which affects the ordering of widgets and code snippets on model pages.

Request Routing Modes

There are two distinct modes for calling Inference Providers:

  • Custom Key Mode: Calls are sent directly to the inference provider using the user's provider-specific API key.
  • Routed by HF Mode: Requests are routed through Hugging Face. Users do not need a provider-specific token, and charges are applied directly to the Hugging Face account.

Client SDK Support

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 and Credits

Billing depends on the routing method used:

  • Direct Requests: Users are billed by the inference provider (e.g., DeepInfra) using their provider account.
  • Routed Requests: Users pay standard provider API rates through Hugging Face. Hugging Face does not add a markup to these costs.

Hugging Face PRO subscribers receive $2 worth of Inference credits monthly, which can be used across different providers. Signed-in free users are provided with a small free inference quota.

Technical Implementation Example

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."
        }
    ],
)

print(completion.choices[0].message)

Sources