OpenClaw
設定 OpenClaw 透過 TokenHub 中轉模型請求。
OpenClaw 可以透過 TokenHub 的 OpenAI compatible 相容 API 中轉模型請求。本文保留官方安裝方式,並只替換 API key、Base URL 和模型 ID。
本指南使用的 TokenHub endpoint 是 https://us-api.tokenhub.com/v1/chat/completions。
何時使用
適合先在小型倉庫或測試專案中驗證。先讓工具讀檔、解釋程式碼或產生方案,再逐步開啟修改和自動化任務。
安裝或開啟工具
先依照 OpenClaw 官方文件 安裝或開啟工具。版本不同時,請以官方文件目前的入口為準。
對於 CLI 工具,先確認可執行檔可用,再加入 TokenHub 憑證:
openclaw --version準備 TokenHub 憑證
建立 TokenHub API key,並在 TokenHub 模型列表中選擇一個適合這個工具的模型。
export TOKENHUB_API_KEY="sk-..."請將金鑰保存在本機 shell、IDE 的密鑰儲存或工具的安全 API key 欄位中,不要提交到程式碼倉庫。
設定 TokenHub 服務商
在工具的模型、供應商、API Keys 或 OpenAI Compatible 設定頁面中填入下列值。
服務商填寫值
Use the official custom provider guide for the current models.providers schema and OpenAI-compatible adapter behavior.
| 欄位 | 填寫值 |
|---|---|
| Provider ID | tokenhub |
| Base URL | https://us-api.tokenhub.com/v1 |
| API Key | TOKENHUB_API_KEY 的值 |
| API adapter | openai-completions |
| Model reference | tokenhub/gpt-4.1 |
設定檔位置
| 欄位 | 填寫值 |
|---|---|
| Gateway environment | ~/.openclaw/.env |
| Main config | ~/.openclaw/openclaw.json |
Store the key where the managed Gateway can read it:
TOKENHUB_API_KEY=your-local-tokenhub-keyAdd the custom provider to ~/.openclaw/openclaw.json:
{
models: {
mode: 'merge',
providers: {
tokenhub: {
baseUrl: '__API_BASE_URL__/v1',
apiKey: '${TOKENHUB_API_KEY}',
api: 'openai-completions',
models: [
{
id: 'gpt-4.1',
name: 'TokenHub / gpt-4.1',
reasoning: false,
input: ['text'],
contextWindow: 128000,
maxTokens: 8192,
},
],
},
},
},
agents: {
defaults: {
model: {
primary: 'tokenhub/gpt-4.1',
},
},
},
}Replace the example model metadata with the actual limits and capabilities of the TokenHub model you selected. Keep the catalog id bare, then add the provider prefix only when selecting it as tokenhub/gpt-4.1.
Restart the Gateway and verify the custom provider:
openclaw gateway restart
openclaw models list --provider tokenhub
openclaw models set "tokenhub/gpt-4.1"The API key remains in ~/.openclaw/.env so launchd, systemd, Docker, and other managed Gateway processes can read it.
如果工具將 chat、edit、apply 和 fast model 分開,第一次測試先全部使用同一個 TokenHub 模型。確認可用後,再依成本、延遲和推理能力拆分。
臨時環境變數只用於排錯
臨時變數適合確認 Key、網路和模型名。驗證通過後,請把同樣的值寫回上方的持久設定。
export TOKENHUB_API_KEY="sk-..."驗證連線
先使用唯讀提示測試,確認模型能讀取上下文且不會改動檔案。成功後再測試編輯、Apply 或 Agent 任務。
閱讀目前專案的 README,請用三句話總結。不要修改任何檔案。提示成功後,回到 TokenHub 請求記錄確認模型名稱、endpoint、token 用量和計費分組。
常見問題
| 現象 | 處理方式 |
|---|---|
| 401 或驗證失敗 | 確認 TOKENHUB_API_KEY 有效,且保存在同一個 terminal、IDE 或用戶端設定檔中。 |
| 404 或找不到模型 | 使用 TokenHub 工作區中存在,且符合所選協議的模型 ID。 |
| endpoint 不正確 | Base URL 必須與上方一致。OpenAI 相容工具通常需要 /v1;Claude 相容工具通常不需要。 |
| 請求逾時 | 檢查到 https://us-api.tokenhub.com 的網路、代理設定,以及工作區 allowlist。 |
| 工具使用了其他模型 | 重新檢查 chat、edit、apply、fast 或 autocomplete 等所有模型欄位。 |
最後更新於