Hugging Face
Hugging Face 是领先的开源与开放科学 AI 平台,核心包括模型/数据/Spaces 的 Hugging Face Hub、推理与托管(Inference Providers 与 Inference Endpoints)、以及丰富的开源库(Transformers、Diffusers、Datasets、Tokenizers、Accelerate、PEFT、TRL、Safetensors、Transformers.js、smolagents、TGI 等)。平台支持文本、图像、音频、视频与 3D 等多模态,提供 Python、JavaScript 与 REST/OpenAI 兼容端点的统一接入。
支持模型
API 接口列表
分页返回 Hub 中的模型信息,支持 `search`、`author`、`filter`、`sort`、`direction`、`limit`、`full`、`config` 等查询参数。
OpenAI 兼容聊天补全。`model` 需包含提供商后缀或使用 `:auto`/`:fastest`/`:cheapest` 策略;支持在消息中包含 `image_url`。官方声明当前仅覆盖 Chat Completions。
{
"model": "deepseek-ai/DeepSeek-R1:fastest",
"messages": [
{
"role": "user",
"content": "Hello!"
}
]
}(如适用)OpenAI 兼容 Responses API,用于更高级的事件流、结构化输出与工具调用(例如 gpt-oss 系列)。
{
"model": "openai/gpt-oss-120b:cerebras",
"input": "Tell me a fun fact about the Eiffel Tower."
}无服务器 Inference API 执行指定模型的推理,请求/响应结构取决于任务类型(文本生成、图像生成、ASR 等)。
curl -s -H 'Authorization: Bearer $HF_TOKEN' -H 'Content-Type: application/json' https://api-inference.huggingface.co/models/{model_id}专用 Inference Endpoints(TGI)上的 OpenAI 兼容聊天补全,需使用该端点的 `hf_...` API key。
{
"model": "meta-llama/Meta-Llama-3-8B-Instruct",
"messages": [
{
"role": "user",
"content": "Explain transformers in one sentence."
}
]
}图像生成示例(文本到图像)。请求为文本提示,返回图像二进制或 base64。
{
"inputs": "A steampunk airship in the clouds"
}语音识别示例(ASR)。上传音频或字节流,返回转录文本。
curl -s -H 'Authorization: Bearer $HF_TOKEN' -H 'Content-Type: audio/wav' --data-binary @sample.wav https://api-inference.huggingface.co/models/openai/whisper-large-v3