Hub documentation
推論プロバイダー
推論プロバイダー
Hugging Faceのモデルページでは、数千のモデルに対して従量課金制の推論が利用可能であり、ブラウザ上でそのまま試すことができます。このサービスはInference Providersによって提供されており、PROユーザーおよびTeam & Enterprise組織には月間のクレジットが含まれています。
Inference Providersは、最高のサーバーレス推論パートナーによって提供される、数百の機械学習モデルへの簡素化された統合アクセスを、開発者に提供します。👉 完全なドキュメントについては、Inference Providers Documentationをご覧ください。
Hub上の推論プロバイダー
Inference Providers は Hugging Face Hub と深く統合されており、いくつかの方法で使用できます。
- インタラクティブウィジェット - モデルページ上で、裏側でInference Providersを利用するインタラクティブウィジェットを通じて、モデルを直接テストできます。例として、DeepSeek-R1-0528モデルページをご覧ください。
- Inference Playground - プロンプトを使用して、チャット補完モデルを簡単にテスト・比較できます。まずはInference Playgroundをご覧ください。
- 検索 - モデルページで推論プロバイダーによってモデルを絞り込み、特定のプロバイダーを通じて利用可能なモデルを検索します。
- Data Studio - AI を活用して Hub 上のデータセットを探索します。お気に入りのデータセットで Data Studio を試してみてください。
Inference Providersで構築
Inference Providersは、SDKまたはHTTPクライアントを使用して、ご自身のアプリケーションに統合できます。ここではPythonとJavaScriptでのクイックスタートを説明します。詳細については、Inference Providers Documentationを参照してください。
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://huggingface.co/proxy/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互換クライアントは、画像生成にはサポートされていません。
JavaScript SDK を使用して、Inference Providers とのやり取りを行うことができます。
import { InferenceClient } from "@huggingface/inference";
const client = new InferenceClient(process.env.HF_TOKEN);
const chatCompletion = await client.chatCompletion({
provider: "auto", // Automatically selects best provider
model: "deepseek-ai/DeepSeek-V3-0324",
messages: [{ role: "user", content: "Hello!" }]
});
const imageBlob = await client.textToImage({
model: "black-forest-labs/FLUX.1-dev",
inputs:
"A serene lake surrounded by mountains at sunset, photorealistic style",
});または、OpenAI API互換のクライアントをそのまま使用することもできます。
import { OpenAI } from "openai";
const client = new OpenAI({
baseURL: "https://huggingface.co/proxy/router.huggingface.co/v1",
apiKey: process.env.HF_TOKEN,
});
const completion = await client.chat.completions.create({
model: "meta-llama/Llama-3.1-8B-Instruct",
messages: [{ role: "user", content: "A story about hiking in the mountains" }],
});
OpenAI API互換クライアントは、画像生成にはサポートされていません。
推論権限を持つ Hugging Face トークンが必要です。Settings > Tokens で作成してください。
Inference Providers の仕組み
Inference Providersについてさらに詳しく知りたい場合は、Inference Providers Documentationをご覧ください。主なリソースは以下の通りです:
HF-Inference APIとは何でしたか?
HF-Inference API は、Inference Providers 経由で利用可能なプロバイダーの一つです。以前は「Inference API (serverless)」と呼ばれており、内部では Inference Endpoints によって提供されています。
HF-Inferenceプロバイダーの詳細については、専用ページをご覧ください。
Update on GitHub