> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vers.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Login

# vers login

Login to the Vers platform using your API token.

## Usage

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers login                    # Interactive login (secure input)
vers login --token   # Login with token directly
```

## Options

| Option        | Description                  |
| ------------- | ---------------------------- |
| `--token, -t` | API token for authentication |

## Examples

### Interactive login

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers login
Enter your API key (input will be hidden): 
Validating API key...
API key validated successfully
Successfully authenticated with Vers
```

### Direct token login

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers login --token sk-vers-api01-abc123...
Validating API key...
API key validated successfully
Successfully authenticated with Vers
```

## How it works

The `login` command:

1. **Gets API key**: Either from `--token` flag or secure interactive input
2. **Validates key**: Makes a POST request to `/api/validate` endpoint
3. **Saves locally**: Stores the validated API key securely on your machine
4. **Confirms success**: Shows authentication confirmation

## Getting your API key

You can get your API key from: [https://vers.sh/billing](https://vers.sh/billing)

1. Sign up or log into your Vers account
2. Navigate to the billing page
3. Generate or copy your API key after payment
4. Use it with `vers login`

## Security features

### Hidden input

When using interactive mode, your API key input is completely hidden:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers login
Enter your API key (input will be hidden): [no characters shown]
```

### Server validation

Every API key is validated against the Vers platform before being saved:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
Validating API key...
API key validated successfully
```

### Local storage

The API key is stored securely on your local machine and is not shared with version control systems.

## Error handling

### Invalid API key

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers login --token invalid-key
Validating API key...
Error: invalid API key - please check your key and try again
```

### Empty API key

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers login --token ""
Error: API key cannot be empty
```

### Network issues

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers login
Enter your API key (input will be hidden): 
Validating API key...
Error: could not validate API key: connection refused
```

### Server errors

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers login
Validating API key...
Error: validation failed with status 500 - please try again
```

## Prerequisites

* Network connectivity to reach the Vers platform
* Valid API key from [https://vers.sh/billing](https://vers.sh/billing)

## Common Patterns

### First-time setup on a new machine

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers login
# paste API key from https://vers.sh
vers status   # verifies the credential
```

### Switch between API keys

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers logout
vers login
```

### Set the API key non-interactively (CI)

Drop it into `~/.versrc` directly instead of calling `vers login`:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
mkdir -p ~/.config && printf 'api_key = "%s"\n' "$VERS_API_KEY" > ~/.versrc
```

## See Also

* [vers logout](/cli-reference/logout) - Sign out from current account
* [vers init](/cli-reference/init) - Initialize projects (requires authentication)
