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
這個指令會顯示:
  • 你是否已通過身份驗證
  • 你的帳戶資訊
  • 目前的端點配置

疑難排解

  • 「未驗證」錯誤: 執行 cursor-agent login 或確保你的 API 金鑰設定正確
  • SSL 憑證錯誤: 在開發環境中使用 --insecure 參數
  • 端點問題: 使用 --endpoint 參數來指定自訂 API 端點