Skip to main content

k6 login

Authenticate with cloud services for k6.

Synopsis

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)
The k6 login command is deprecated and will be removed in a future release. Use k6 cloud login instead.

Grafana Cloud k6 Login

Synopsis

k6 cloud login [flags]

Description

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

Examples

# Interactive login (opens browser)
k6 cloud login

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

Flags

--token
string
Provide an API token directly instead of using browser authentication

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:
{
  "token": "your-api-token",
  "stackID": 12345,
  "defaultProjectID": 67890
}

Alternative Authentication Methods

Environment Variable

Set the token via environment variable:
export K6_CLOUD_TOKEN=your-token-here
k6 cloud run script.js

Script Configuration

Embed in your test script:
export const options = {
  cloud: {
    token: 'your-token-here',
    projectID: 12345,
  },
};
Never commit tokens to version control. Use environment variables or the secure config file instead.

Obtaining API Tokens

To manually obtain a Grafana Cloud k6 API token:
  1. Go to Grafana Cloud
  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:
export K6_CLOUD_STACK_ID=12345
export K6_CLOUD_PROJECT_ID=67890
k6 cloud run script.js

InfluxDB Cloud Login (Deprecated)

Synopsis

k6 login influxdb [flags]
The k6 login influxdb command is deprecated. Configure InfluxDB output directly using the --out flag or environment variables.

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

K6_CLOUD_TOKEN
string
Grafana Cloud k6 authentication token
K6_CLOUD_HOST
string
default:"https://ingest.k6.io"
Grafana Cloud k6 API host
K6_CLOUD_STACK_ID
int
Stack ID for the Grafana Cloud instance
K6_CLOUD_PROJECT_ID
int
Default project ID for organizing tests

See Also

Build docs developers (and LLMs) love