Cursor CLI 支援兩種驗證方式:瀏覽器登入(建議)與 API 金鑰。 使用瀏覽器流程,享有最簡單的驗證體驗:
# 使用瀏覽器流程登入
cursor-agent login

# 檢查驗證狀態
cursor-agent status

# 登出並清除已儲存的驗證
cursor-agent logout
登入指令會開啟你的預設瀏覽器,並引導你用 Cursor 帳號進行驗證。完成後,你的憑證會安全地儲存在本機。

API 金鑰驗證

在自動化、腳本或 CI/CD 環境中,使用 API 金鑰驗證:

步驟 1:建立 API 金鑰

在你的 Cursor 控制台的 Integrations > User API Keys 中建立一組 API 金鑰。

步驟 2:設定 API 金鑰

你可以用兩種方式提供 API 金鑰: 選項 1:環境變數(推薦)
export CURSOR_API_KEY=your_api_key_here
cursor-agent "implement user authentication"
選項 2:命令列參數
cursor-agent --api-key your_api_key_here "implement user authentication"

驗證狀態

查看你目前的驗證狀態:
cursor-agent status
這個指令會顯示:
  • 你是否已完成驗證
  • 你的帳戶資訊
  • 目前的端點設定

疑難排解

  • 「Not authenticated」錯誤:執行 cursor-agent login,或確認你的 API key 已正確設定
  • SSL 憑證錯誤:在開發環境使用 --insecure 參數
  • 端點問題:使用 --endpoint 參數來指定自訂 API 端點