{"record":{"id":"b0aa8e806f8fd761","repo":"grafana/k6","slug":"run-k6-cloud-login-to-authenticate-or-check-the","errorCode":null,"errorMessage":"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","messagePattern":"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","errorType":"validation","errorClass":"errCloudAuth","httpStatus":null,"severity":"error","filePath":"internal/cmd/cloud.go","lineNumber":35,"sourceCode":"\n\t\"go.k6.io/k6/v2/cloudapi\"\n\t\"go.k6.io/k6/v2/cmd/state\"\n\t\"go.k6.io/k6/v2/errext\"\n\t\"go.k6.io/k6/v2/errext/exitcodes\"\n\t\"go.k6.io/k6/v2/internal/build\"\n\tcloudapiv6 \"go.k6.io/k6/v2/internal/cloudapi/v6\"\n\t\"go.k6.io/k6/v2/internal/ui/pb\"\n\t\"go.k6.io/k6/v2/lib\"\n\n\t\"github.com/fatih/color\"\n\t\"github.com/spf13/cobra\"\n\t\"github.com/spf13/pflag\"\n)\n\nconst cloudRunAuthPrefix = \"Running cloud tests requires auth settings\"\n\nvar (\n\terrCloudAuth = errors.New( //nolint:staticcheck // user-facing error message, capitalization is intentional\n\t\t\"Run `k6 cloud login` to authenticate, or check the docs for other options at\" +\n\t\t\t\" https://grafana.com/docs/grafana-cloud/testing/k6/author-run/tokens-and-cli-authentication\",\n\t)\n\terrMissingToken   = errors.New(\"access token not configured\")\n\terrMissingStackID = errors.New(\"stack ID not configured\")\n\n\t// errNoProjectConfigured is returned by cloud sub-commands that require a\n\t// concrete project to operate on when none can be resolved from the flags,\n\t// the environment, or the logged-in configuration.\n\terrNoProjectConfigured = errors.New(\n\t\t\"no project specified. Use --project-id, set K6_CLOUD_PROJECT_ID, or run `k6 cloud login` to set a default project\",\n\t)\n)\n\n// checkCloudLogin verifies that both a token and a stack are configured.\n// Together they represent a complete Grafana Cloud login.\nfunc checkCloudLogin(conf cloudapi.Config) error {\n\treturn checkCloudLoginFor(conf, cloudRunAuthPrefix)","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/cmd/cloud.go#L17-L53","documentation":"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).","triggerScenarios":"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...'.","commonSituations":"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.","solutions":["Run `k6 cloud login` and follow the interactive prompts (stores token, stack ID, stack URL, default project)","For CI/headless use, export K6_CLOUD_TOKEN and K6_CLOUD_STACK_ID instead of logging in","Verify the stored config with `k6 cloud login --show` (token is masked)","Reset a broken stored state with `k6 cloud login --reset`, then log in again"],"exampleFix":"# before\nk6 cloud run script.js   # ERR: Running cloud tests requires auth settings\n\n# after (interactive)\nk6 cloud login\nk6 cloud run script.js\n\n# after (headless/CI)\nexport K6_CLOUD_TOKEN=eyJr...\nexport K6_CLOUD_STACK_ID=123456\nk6 cloud run script.js","handlingStrategy":"validation","validationCode":"# before any k6 cloud command in CI\nk6 cloud login --show >/dev/null 2>&1 || true\nif [ -z \"${K6_CLOUD_TOKEN:-}\" ] && ! grep -q token ~/.config/loadimpact/k6/config.json 2>/dev/null; then\n  echo \"k6 auth missing: run 'k6 cloud login' or set K6_CLOUD_TOKEN/K6_CLOUD_STACK_ID\" >&2\n  exit 1\nfi","typeGuard":null,"tryCatchPattern":"if err := checkCloudLogin(cloudConf); err != nil {\n    // err chains errMissingToken/errMissingStackID plus the login hint;\n    // print as-is for the user and abort before uploading anything\n    return err\n}","preventionTips":["Standardize one auth mechanism per environment: stored login on dev machines, env vars in CI","Add a preflight step in pipelines that fails fast on missing K6_CLOUD_TOKEN/K6_CLOUD_STACK_ID","After `k6 cloud login --reset`, always re-login before the next cloud run"],"tags":["cloud","auth","cli","configuration","login"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}