跳到正文
OpenRouter Announcements·· 2 天前AI 评分58

OpenRouter 为 Hugging Face Inference Providers 提供推理路由

OpenRouter Now Powers Inference on Hugging Face

AI 导读

OpenRouter 宣布 Hugging Face Inference Providers 上的聊天模型改由 OpenRouter 路由,按实时价格、速度和可靠性选择供应商,并支持自动故障转移,现有 Hugging Face token 和代码无需改动。

正文 · AI 翻译

我们构建 OpenRouter,是为了让开发者通过一个 API 就能访问众多模型和提供商,为每项任务选用最合适的模型,并依靠它稳定响应。从今天起,这一能力也扩展到所有在 Hugging Face 上构建应用的人。Hugging Face Inference Providers 上的聊天模型现在通过 OpenRouter 运行,并采用 OpenRouter 客户早已依赖的同一套跨提供商路由。

这一集成也是双向的。OpenRouter 现在可以把每个请求的追踪记录发送到你拥有的 Hugging Face Storage Bucket,这样你真实流量中的提示词和响应就能与你用来评估或微调它们的模型和数据集放在一起。设置指南中有具体步骤。

你在 Hugging Face 上获得的能力

Hugging Face 上的许多聊天模型由不止一个提供商提供服务。OpenRouter 的提供商路由现在为 Hugging Face Inference Providers 上的路由提供支持,它会根据实时价格、速度和可靠性为每个请求选择提供商。你无需进行任何设置,现有的 Hugging Face token 和代码可继续使用。

你还能获得自动故障转移。如果某个提供商变慢或开始失败,请求会转到其他提供商,直到它恢复。如果某个提供商返回错误,请求会在同一次调用中在下一个提供商上重试。

当我们在十月重建这套路由时,一项实时实验测得:遇到容量错误的请求减少了 46%,首个 token 的到达时间快了 16.9%,吞吐量提高了 16.3%,而每个请求的成本增加了 6.0%。现在所有在 Hugging Face 上构建应用的人都能获得同样的路由。

A diagram from Hugging Face showing a request from your app going to router.huggingface.co, where OpenRouter picks one of four providers based on measured price, speed, and reliability, with options for default, cheapest, and fastest routing (light mode)

A diagram from Hugging Face showing a request from your app going to router.huggingface.co, where OpenRouter picks one of four providers based on measured price, speed, and reliability, with options for default, cheapest, and fastest routing (dark mode)

权衡取舍仍由你掌控。在模型 ID 后添加后缀,例如 :fastest、:cheapest 或提供商名称,即可告诉 OpenRouter 优先考虑什么;请求可通过 OpenAI 的 Chat Completions 和 Responses API 或 Anthropic 的 Messages API 工作。对话也会保持在持有其提示词缓存的提供商上。

每个模型页面都有一个新增的 Providers 标签页,显示每个提供商的实时价格、速度和正常运行时间。你可以查看按提供商划分的支出,并关闭任何你不想使用的提供商。

The Providers tab on a Hugging Face model page, listing each provider's input price, output price, speed, and uptime, with a Powered by OpenRouter label (light mode)

The Providers tab on a Hugging Face model page, listing each provider's input price, output price, speed, and uptime, with a Powered by OpenRouter label (dark mode)

目前有来自 38 个实验室的 160 个模型可通过这种方式使用,即 OpenRouter 所服务、且在 Hub 上有页面的每一个模型。其中包括开发者在 OpenRouter 上最常使用的开放权重模型——开放权重模型现在承载了约 70% 的付费 token:

  • DeepSeek V4.1 Flash
  • MoonshotAI Kimi K3.1 Pro 和 Kimi K3
  • Z.ai GLM 5.3 和 GLM 5.3 Flash
  • Qwen3.8 27B
  • MiniMax M3.1 Flash
  • Xiaomi MiMo-V2.6-Flash
  • NVIDIA Nemotron 3 Ultra
  • OpenAI gpt-oss-120b

你的追踪记录可以存放在 Hub 上

将 Hugging Face Storage Buckets 添加为 Broadcast 目标(目前为 beta 版),OpenRouter 就会把每个请求作为 JSON 文件发送到你拥有的 bucket。每个文件包含输入消息、模型输出、token 数量和成本。图像和其他媒体不会包含在内。

这些就是评估集或对开放权重模型进行微调运行的原始素材。你可以按日期或按 API key 来组织这些文件。

The new Hugging Face Storage Buckets destination form in OpenRouter's Observability settings, with fields for namespace, bucket name, access key ID, and secret access key.

开始使用

在 Hugging Face 上:

  1. 在 hf.co/settings/tokens 创建一个 token,并授予“Make calls to Inference Providers”权限。
  2. 在 Hub 上打开任意受支持模型的页面。在那里与它聊天,或点击 View code 获取适用于你的代码或编码代理(包括 Claude Code、Codex、OpenCode、Pi 和 Hermes Agent)的设置步骤。
  3. 要选择哪些提供商可以服务你的请求,请前往 Hugging Face 设置中的 Inference Providers。

要将追踪记录发送到 Storage Bucket:

  1. 在 Hugging Face 上创建一个 Storage Bucket。
  2. 创建一个具有 Write 权限的访问令牌,并据此生成 S3 凭证。
  3. 在 OpenRouter 中,前往 Settings > Observability,开启 Broadcast,然后打开 Hugging Face Storage Buckets。
  4. 输入你的命名空间、存储桶名称、访问密钥 ID 和私有访问密钥。路径模板(例如 {apiKeyName}/{date})为可选项。
  5. 点击 Test Connection,然后保存。

完整设置指南涵盖了路径模板和跟踪文件格式。

在 Hugging Face Playground 中试用模型,或将你的跟踪数据发送到 Storage Bucket。

来源:OpenRouter Announcements · openrouter.ai