> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/grafana/k6/llms.txt
> Use this file to discover all available pages before exploring further.

# k6 login

> Authenticate with cloud services

# k6 login

Authenticate with cloud services for k6.

## Synopsis

```bash theme={null}
k6 login <service>
k6 cloud login [flags]  # Recommended
```

## Description

The `k6 login` command authenticates k6 with cloud services. Currently, it supports:

* Grafana Cloud k6 (via `k6 cloud login`)
* InfluxDB Cloud (via `k6 login influxdb`)

<Warning>
  The `k6 login` command is deprecated and will be removed in a future release. Use `k6 cloud login` instead.
</Warning>

## Grafana Cloud k6 Login

### Synopsis

```bash theme={null}
k6 cloud login [flags]
```

### Description

Authenticates with Grafana Cloud k6 using an interactive browser flow. This is the recommended method for authentication.

### Examples

```bash theme={null}
# Interactive login (opens browser)
k6 cloud login

# Login with a specific token
k6 cloud login --token YOUR_TOKEN
```

### Flags

<ParamField path="--token" type="string">
  Provide an API token directly instead of using browser authentication
</ParamField>

### Authentication Flow

1. Run `k6 cloud login`
2. Your browser opens to the Grafana Cloud authentication page
3. Log in or sign up for Grafana Cloud
4. Select or create a stack
5. Your credentials are saved locally
6. You can now run `k6 cloud run` without additional authentication

### Token Storage

Authentication tokens are stored in:

* **Linux/macOS**: `~/.config/k6/cloud.json`
* **Windows**: `%APPDATA%\k6\cloud.json`

The configuration file contains:

```json theme={null}
{
  "token": "your-api-token",
  "stackID": 12345,
  "defaultProjectID": 67890
}
```

## Alternative Authentication Methods

### Environment Variable

Set the token via environment variable:

```bash theme={null}
export K6_CLOUD_TOKEN=your-token-here
k6 cloud run script.js
```

### Script Configuration

Embed in your test script:

```javascript theme={null}
export const options = {
  cloud: {
    token: 'your-token-here',
    projectID: 12345,
  },
};
```

<Warning>
  Never commit tokens to version control. Use environment variables or the secure config file instead.
</Warning>

## Obtaining API Tokens

To manually obtain a Grafana Cloud k6 API token:

1. Go to [Grafana Cloud](https://grafana.com/auth/sign-in/)
2. Navigate to your k6 organization
3. Go to Settings → API Tokens
4. Create a new token with appropriate permissions
5. Copy the token and use it with `k6 cloud login --token YOUR_TOKEN`

## Stack and Project Configuration

After logging in, k6 stores:

* **Stack ID**: Your Grafana Cloud k6 instance
* **Default Project ID**: Default project for organizing tests

You can override these per test:

```bash theme={null}
export K6_CLOUD_STACK_ID=12345
export K6_CLOUD_PROJECT_ID=67890
k6 cloud run script.js
```

## InfluxDB Cloud Login (Deprecated)

### Synopsis

```bash theme={null}
k6 login influxdb [flags]
```

<Warning>
  The `k6 login influxdb` command is deprecated. Configure InfluxDB output directly using the `--out` flag or environment variables.
</Warning>

## Troubleshooting

### Authentication Failed

If authentication fails:

1. Clear stored credentials: `rm ~/.config/k6/cloud.json`
2. Try logging in again: `k6 cloud login`
3. Check your internet connection
4. Verify you have access to Grafana Cloud

### Token Not Working

If your token isn't working:

1. Verify the token hasn't expired
2. Check the token has correct permissions
3. Regenerate the token in Grafana Cloud
4. Try logging in again: `k6 cloud login --token NEW_TOKEN`

### Browser Doesn't Open

If the browser doesn't open automatically:

1. Copy the URL from the terminal
2. Open it manually in your browser
3. Complete the authentication
4. The CLI will detect the successful authentication

## Security Best Practices

1. **Never share tokens** - They provide full access to your k6 account
2. **Use environment variables** - Don't hardcode tokens in scripts
3. **Rotate tokens regularly** - Create new tokens periodically
4. **Use project-specific tokens** - Limit token scope when possible
5. **Store securely** - Use secret management tools in CI/CD

## Environment Variables

<ParamField path="K6_CLOUD_TOKEN" type="string">
  Grafana Cloud k6 authentication token
</ParamField>

<ParamField path="K6_CLOUD_HOST" type="string" default="https://ingest.k6.io">
  Grafana Cloud k6 API host
</ParamField>

<ParamField path="K6_CLOUD_STACK_ID" type="int">
  Stack ID for the Grafana Cloud instance
</ParamField>

<ParamField path="K6_CLOUD_PROJECT_ID" type="int">
  Default project ID for organizing tests
</ParamField>

## See Also

* [k6 cloud](/cli/cloud) - Run tests in Grafana Cloud
* [Environment variables](/cli/environment-variables)
* [Grafana Cloud k6 Documentation](https://grafana.com/docs/grafana-cloud/testing/k6/author-run/tokens-and-cli-authentication/)
