Cursor CLI supports two authentication methods: browser-based login (recommended) and API keys. Use the browser flow for the easiest authentication experience:
# Log in using browser flow
cursor-agent login

# Check authentication status
cursor-agent status

# Log out and clear stored authentication
cursor-agent logout
The login command will open your default browser and prompt you to authenticate with your Cursor account. Once completed, your credentials are securely stored locally.

API key authentication

For automation, scripts, or CI/CD environments, use API key authentication:

Step 1: Generate an API key

Generate an API key in your Cursor dashboard.

Step 2: Set the API key

You can provide the API key in two ways: Option 1: Environment variable (recommended)
export CURSOR_API_KEY=your_api_key_here
cursor-agent "implement user authentication"
Option 2: Command line flag
cursor-agent --api-key your_api_key_here "implement user authentication"

Authentication status

Check your current authentication status:
cursor-agent status
This command will display:
  • Whether you’re authenticated
  • Your account information
  • Current endpoint configuration

Troubleshooting

  • “Not authenticated” errors: Run cursor-agent login or ensure your API key is correctly set
  • SSL certificate errors: Use the --insecure flag for development environments
  • Endpoint issues: Use the --endpoint flag to specify a custom API endpoint