H繁中版
文件核心功能provider routing
<!-- Source: https://hermesbible.com/docs/user-guide/features/provider-routing -->

Section: Core Features · URL: https://hermesbible.com/docs/user-guide/features/provider-routing

供應商路由

當使用 OpenRouter 作為你的 LLM 供應商時,Hermes Agent 支援供應商路由(Provider Routing)— 可以精細控制哪些底層 AI 供應商處理你的請求,以及它們的優先順序。

OpenRouter 會將請求路由到多個供應商(例如 Anthropic、Google、AWS Bedrock、Together AI)。供應商路由讓你最佳化成本、速度、品質,或強制要求使用特定供應商。

提示

經由 Nous Portal 路由的流量仍然遵循每個模型的路由和優先順序設定 — 而且 Portal 訂閱者可享有 Token 計費供應商 10% 的折扣。

設定方式

~/.hermes/config.yaml 中加入 provider_routing 區塊:

provider_routing:
  sort: "price"           # 供應商排名方式
  only: []                # 白名單:僅使用這些供應商
  ignore: []              # 黑名單:永不使用這些供應商
  order: []               # 明確的供應商優先順序
  require_parameters: false  # 僅使用支援所有參數的供應商
  data_collection: null   # 控制資料收集("allow" 或 "deny")

資訊

供應商路由僅在使用 OpenRouter 時生效。直接連接供應商(例如直接連接 Anthropic API)時不會有任何作用。

選項說明

sort

控制 OpenRouter 如何為你的請求排列可用的供應商。

說明
"price"最便宜的供應商優先
"throughput"每秒 Token 輸出量最快者優先
"latency"首個 Token 延遲最低者優先
provider_routing:
  sort: "price"

only

供應商名稱白名單。設定後會使用這些供應商,其他供應商都會被排除。

provider_routing:
  only:
    - "Anthropic"
    - "Google"

ignore

供應商名稱黑名單。這些供應商永遠不會被使用,即使它們提供最便宜或最快的选择。

provider_routing:
  ignore:
    - "Together"
    - "DeepInfra"

order

明確的優先順序。排在前面的供應商會被優先使用,未列出的供應商則作為備用方案。

provider_routing:
  order:
    - "Anthropic"
    - "Google"
    - "AWS Bedrock"

require_parameters

設為 true 時,OpenRouter 只會路由到支援你請求中所有參數(如 temperaturetop_ptools 等)的供應商。這可以避免參數被靜默忽略。

provider_routing:
  require_parameters: true

data_collection

控制供應商是否可以使用你的 Prompt 進行訓練。可選值為 "allow""deny"

provider_routing:
  data_collection: "deny"

實際範例

以成本為導向

路由到最便宜的可用供應商。適合大量使用和開發階段:

provider_routing:
  sort: "price"

以速度為導向

優先選擇低延遲的供應商,適合互動式使用:

provider_routing:
  sort: "latency"

以吞吐量為導向

最適合需要大量生成內容的場景,重視每秒 Token 輸出量:

provider_routing:
  sort: "throughput"

鎖定特定供應商

確保所有請求都透過特定供應商處理,以保持一致性:

provider_routing:
  only:
    - "Anthropic"

排除特定供應商

排除你不想使用的供應商(例如基於資料隱私考量):

provider_routing:
  ignore:
    - "Together"
    - "Lepton"
  data_collection: "deny"

帶有備用方案的優先順序

優先使用你偏好的供應商,若無法使用則切換到其他供應商:

provider_routing:
  order:
    - "Anthropic"
    - "Google"
  require_parameters: true

運作原理

供應商路由的偏好設定會透過每次 API 呼叫中的 extra_body.provider 欄位傳遞給 OpenRouter API。這同時適用於:

  • CLI 模式 — 在 ~/.hermes/config.yaml 中設定,啟動時載入
  • Gateway 模式 — 使用相同的設定檔,Gateway 啟動時載入

路由設定會從 config.yaml 讀取,並在建立 AIAgent 時作為參數傳入:

providers_allowed  ← 來自 provider_routing.only
providers_ignored  ← 來自 provider_routing.ignore
providers_order    ← 來自 provider_routing.order
provider_sort      ← 來自 provider_routing.sort
provider_require_parameters ← 來自 provider_routing.require_parameters
provider_data_collection    ← 來自 provider_routing.data_collection

提示

你可以組合使用多個選項。例如,按價格排序但排除特定供應商並要求參數支援:

provider_routing:
  sort: "price"
  ignore: ["Together"]
  require_parameters: true
  data_collection: "deny"

預設行為

當沒有設定 provider_routing 區塊時(即預設狀態),OpenRouter 會使用其內建的預設路由邏輯,通常會自動平衡成本和可用性。

提示 — 供應商路由與備用模型

供應商路由控制的是 OpenRouter 內部的子供應商如何處理你的請求。如果你的主模型失敗後需要自動切換到完全不同的供應商,請參閱備用供應商



備用供應商