Cursor CLI 支持两种身份验证方式:浏览器登录(推荐)和 API 密钥。 使用浏览器流程即可获得最便捷的身份验证体验:
# 通过浏览器流程登录
cursor-agent login

# 查看身份验证状态
cursor-agent status

# 退出并清除已存储的身份验证信息
cursor-agent logout
login 命令会打开你的默认浏览器,并提示你使用 Cursor 账号进行身份验证。完成后,你的凭证会被安全地保存在本地。

API key 身份验证

在自动化、脚本或 CI/CD 环境中,请使用 API key 身份验证:

步骤 1:生成 API key

在你的 Cursor 控制台中,进入 Integrations > User API Keys 生成一个 API key。

步骤 2:设置 API key

你可以通过两种方式提供 API key: 选项 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 问题: 使用 --endpoint 选项指定自定义 API 端点