整合指南

Cursor

設定 Cursor 透過 TokenHub 中轉模型請求。

Cursor 可以透過 TokenHub 的 OpenAI compatible 相容 API 中轉模型請求。本文保留官方安裝方式,並只替換 API key、Base URL 和模型 ID。

Use https://us-api.tokenhub.com/v1 as the OpenAI Base URL override. Depending on the Cursor version and selected model, Cursor may use Chat Completions or Responses-style requests, so do not assume a single endpoint path.

何時使用

適合先在小型倉庫或測試專案中驗證。先讓工具讀檔、解釋程式碼或產生方案,再逐步開啟修改和自動化任務。

安裝或開啟工具

先依照 Cursor 官方文件 安裝或開啟工具。版本不同時,請以官方文件目前的入口為準。

對於 CLI 工具,先確認可執行檔可用,再加入 TokenHub 憑證:

# open the tool, then open its model or provider settings

準備 TokenHub 憑證

建立 TokenHub API key,並在 TokenHub 模型列表中選擇一個適合這個工具的模型。

export TOKENHUB_API_KEY="sk-..."

請將金鑰保存在本機 shell、IDE 的密鑰儲存或工具的安全 API key 欄位中,不要提交到程式碼倉庫。

設定 TokenHub 服務商

在工具的模型、供應商、API Keys 或 OpenAI Compatible 設定頁面中填入下列值。

服務商填寫值

Cursor officially supports BYOK for specific providers and standard chat models. A custom OpenAI-compatible endpoint is currently a limited Base URL override, not a first-class custom provider.

欄位填寫值
SettingsCursor Settings → Models → API Keys
API key fieldOpenAI API Key
Base URL optionOverride OpenAI Base URL
Base URLhttps://us-api.tokenhub.com/v1
模型A TokenHub model compatible with the request format Cursor sends

設定檔位置

欄位填寫值
macOS~/Library/Application Support/Cursor/User/settings.json
Windows%APPDATA%\Cursor\User\settings.json
Linux~/.config/Cursor/User/settings.json

外掛擁有自己的設定 schema 時,優先使用設定 UI。UI 會把同樣的值寫入使用者設定檔,也能避免猜測不同版本可能變動的私有 key。

Custom keys apply only to standard chat models. Tab Completion and Cursor-owned models continue through Cursor. Some current Cursor versions can also send a Responses-shaped body to a Chat Completions path through the override, so verify a read-only chat before relying on Agent mode. If the Base URL override is absent or the request format is rejected, that Cursor version cannot connect to TokenHub reliably.

Do not map Chat, Agent, Composer, Apply, Fast, or Tab as if they were equivalent custom-provider slots. Start with one standard chat model and treat every other feature as unsupported until its requests appear successfully in TokenHub logs.

臨時環境變數只用於排錯

外掛擁有自己的設定 schema 時,優先使用設定 UI。UI 會把同樣的值寫入使用者設定檔,也能避免猜測不同版本可能變動的私有 key。

臨時變數適合確認 Key、網路和模型名。驗證通過後,請把同樣的值寫回上方的持久設定。

驗證連線

先使用唯讀提示測試,確認模型能讀取上下文且不會改動檔案。成功後再測試編輯、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 等所有模型欄位。

最後更新於