grafana/k6 · error · errCloudAuth

Run `k6 cloud login` to authenticate, or check the docs for

Error message

Run `k6 cloud login` to authenticate, or check the docs for other options at https://grafana.com/docs/grafana-cloud/testing/k6/author-run/tokens-and-cli-authentication

What it means

errCloudAuth is k6's consolidated guidance error for cloud commands run without a complete Grafana Cloud login. checkCloudLoginFor wraps the specific missing credential (errMissingToken or errMissingStackID) together with this error, so the final message both names what is missing and tells you how to fix it (login, token docs link).

Source

Thrown at internal/cmd/cloud.go:35

	"go.k6.io/k6/v2/cloudapi"
	"go.k6.io/k6/v2/cmd/state"
	"go.k6.io/k6/v2/errext"
	"go.k6.io/k6/v2/errext/exitcodes"
	"go.k6.io/k6/v2/internal/build"
	cloudapiv6 "go.k6.io/k6/v2/internal/cloudapi/v6"
	"go.k6.io/k6/v2/internal/ui/pb"
	"go.k6.io/k6/v2/lib"

	"github.com/fatih/color"
	"github.com/spf13/cobra"
	"github.com/spf13/pflag"
)

const cloudRunAuthPrefix = "Running cloud tests requires auth settings"

var (
	errCloudAuth = errors.New( //nolint:staticcheck // user-facing error message, capitalization is intentional
		"Run `k6 cloud login` to authenticate, or check the docs for other options at" +
			" https://grafana.com/docs/grafana-cloud/testing/k6/author-run/tokens-and-cli-authentication",
	)
	errMissingToken   = errors.New("access token not configured")
	errMissingStackID = errors.New("stack ID not configured")

	// errNoProjectConfigured is returned by cloud sub-commands that require a
	// concrete project to operate on when none can be resolved from the flags,
	// the environment, or the logged-in configuration.
	errNoProjectConfigured = errors.New(
		"no project specified. Use --project-id, set K6_CLOUD_PROJECT_ID, or run `k6 cloud login` to set a default project",
	)
)

// checkCloudLogin verifies that both a token and a stack are configured.
// Together they represent a complete Grafana Cloud login.
func checkCloudLogin(conf cloudapi.Config) error {
	return checkCloudLoginFor(conf, cloudRunAuthPrefix)

View on GitHub (pinned to 93accf6570)

Solutions

  1. Run `k6 cloud login` and follow the interactive prompts (stores token, stack ID, stack URL, default project)
  2. For CI/headless use, export K6_CLOUD_TOKEN and K6_CLOUD_STACK_ID instead of logging in
  3. Verify the stored config with `k6 cloud login --show` (token is masked)
  4. Reset a broken stored state with `k6 cloud login --reset`, then log in again

Example fix

# before
k6 cloud run script.js   # ERR: Running cloud tests requires auth settings

# after (interactive)
k6 cloud login
k6 cloud run script.js

# after (headless/CI)
export K6_CLOUD_TOKEN=eyJr...
export K6_CLOUD_STACK_ID=123456
k6 cloud run script.js
Defensive patterns

Strategy: validation

Validate before calling

# before any k6 cloud command in CI
k6 cloud login --show >/dev/null 2>&1 || true
if [ -z "${K6_CLOUD_TOKEN:-}" ] && ! grep -q token ~/.config/loadimpact/k6/config.json 2>/dev/null; then
  echo "k6 auth missing: run 'k6 cloud login' or set K6_CLOUD_TOKEN/K6_CLOUD_STACK_ID" >&2
  exit 1
fi

Try / catch

if err := checkCloudLogin(cloudConf); err != nil {
    // err chains errMissingToken/errMissingStackID plus the login hint;
    // print as-is for the user and abort before uploading anything
    return err
}

Prevention

When it happens

Trigger: Running `k6 cloud run` (or another cloud subcommand guarded by checkCloudLoginFor) when conf.Token is invalid/empty or the stack ID is unset. Example final message: 'Running cloud tests requires auth settings: access token not configured.\nRun `k6 cloud login` to authenticate...'.

Common situations: Fresh machine or CI container that never ran `k6 cloud login`; K6_CLOUD_TOKEN/K6_CLOUD_STACK_ID not exported in CI; token removed from the config file; switching between accounts without re-login.

Understand the failure class

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/b0aa8e806f8fd761. Report an issue: GitHub.