Skip to content

k6 Cloud Output Authentication Error Fix

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about k6 cloud output authentication error fix. We cover key concepts, practical examples, and best practices.

Your k6 test fails with could not authenticate to k6 Cloud when using --out cloud — the API token is missing, expired, or the project ID is incorrect. The k6 Cloud output requires valid credentials and network access to api.k6.io.

The Problem

k6 run --out cloud script.js
ERRO[0000] failed to authenticate with k6 Cloud:
  could not authenticate to k6 Cloud: invalid token

The K6_CLOUD_TOKEN environment variable is not set or contains an invalid or expired token.

Step-by-Step Fix

1. Set the cloud token

# Set token from k6 Cloud dashboard
export K6_CLOUD_TOKEN="your_api_token_here"

# Or pass inline
k6 run --out cloud -e K6_CLOUD_TOKEN="your_token" script.js

2. Verify the token

# Test the token
curl -H "Authorization: Token your_token" https://api.k6.io/v1/me

# Expected output: {"email": "you@example.com", "name": "Your Name"}

3. Set project ID (for organization environments)

# Find your project ID in k6 Cloud dashboard
export K6_CLOUD_PROJECT_ID="12345"

# Or pass inline
k6 run --out cloud -e K6_CLOUD_PROJECT_ID="12345" script.js

4. Configure test run details

import http from 'k6/http';

export const options = {
  ext: {
    loadimpact: {
      name: 'Production Smoke Test',
      projectID: parseInt(__ENV.K6_CLOUD_PROJECT_ID) || 0,
      distribution: {
        'amazon:us-east-1': { loadZone: 'amazon:us-east-1', percent: 50 },
        'amazon:eu-west-1': { loadZone: 'amazon:eu-west-1', percent: 50 },
      },
    },
  },
  thresholds: {
    http_req_duration: ['p(95)<2000'],
  },
};

export default function () {
  http.get('https://api.example.com/health');
}

5. Handle network/proxy issues

# Check network connectivity
curl -I https://api.k6.io/v1/me

# Use a proxy if needed
export HTTP_PROXY=http://proxy.company.com:8080
export HTTPS_PROXY=http://proxy.company.com:8080

Expected output:

     ✓ Test run started in k6 Cloud
     ✓ Run ID: 123456
     ✓ View results at: https://app.k6.io/runs/123456

Prevention Tips

  • Set K6_CLOUD_TOKEN in your CI/CD environment secrets
  • Use K6_CLOUD_PROJECT_ID for multi-project organizations
  • Use the ext.loadimpact option to name and configure test runs
  • Verify network access to api.k6.io before running
  • Test with --out cloud on a short script first

Common Mistakes with cloud output

  1. Misunderstanding that String is [Char] with poor performance for large text operations
  2. Using foldl instead of foldl' causing stack overflow on large lists
  3. Forgetting deriving (Show, Eq) on custom data types needed for debugging

These mistakes appear frequently in real-world K6 code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Where do I find my k6 Cloud token?

Log in to app.k6.io, go to Settings > API Tokens. Generate a new token with the appropriate permissions. Copy the token value — it is shown only once at creation.

Can I run cloud tests without uploading the script?

Yes, use k6 cloud run script.js instead of k6 run --out cloud script.js. The k6 cloud command uploads and runs the test on k6's infrastructure. k6 run --out cloud runs locally and streams results to the cloud.

How do I set up multi-region distribution?

Use the distribution field in ext.loadimpact. Each entry specifies a load zone and percentage of total traffic. Supported zones include amazon:us-east-1, amazon:eu-west-1, amazon:ap-southeast-1, and more.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro