{"record":{"id":"cb88caaa7758da56","repo":"grafana/k6","slug":"authentication-failed-as-provided-token-or-stack-m","errorCode":null,"errorMessage":"Authentication failed as provided token or stack might not be valid. Learn more: https://grafana.com/docs/grafana-cloud/testing/k6/author-run/tokens-and-cli-authentication. Server error for details: %w","messagePattern":"Authentication failed as provided token or stack might not be valid\\. Learn more: https://grafana\\.com/docs/grafana-cloud/testing/k6/author-run/tokens-and-cli-authentication\\. Server error for details: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/cloud_login.go","lineNumber":270,"sourceCode":"\tgs *state.GlobalState,\n\tconfig *cloudapi.Config,\n\trawConfig json.RawMessage,\n\ttoken, stack string,\n) error {\n\tconfig.Token = null.StringFrom(token)\n\tconsolidatedCurrentConfig, warn, err := cloudapi.GetConsolidatedConfig(\n\t\trawConfig, gs.Env, \"\", nil)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif warn != \"\" {\n\t\tgs.Logger.Warn(warn)\n\t}\n\n\tstackURL, stackID, defaultProjectID, err := validateTokenV6(\n\t\tgs, consolidatedCurrentConfig, token, stack)\n\tif err != nil {\n\t\treturn fmt.Errorf( //nolint:staticcheck // ST1005: this is a user-facing error\n\t\t\t\"Authentication failed as provided token or stack might not be valid.\"+\n\t\t\t\t\" Learn more: https://grafana.com/docs/grafana-cloud/testing/k6/author-run/tokens-and-cli-authentication.\"+\n\t\t\t\t\" Server error for details: %w\",\n\n\t\t\terr)\n\t}\n\tconfig.StackURL = null.StringFrom(stackURL)\n\tconfig.StackID = null.IntFrom(stackID)\n\tconfig.DefaultProjectID = null.IntFrom(defaultProjectID)\n\n\treturn nil\n}\n\n// validateTokenV6 validates a token and a stack URL/slug and returns the normalized URL, stack ID,\n// and default project ID.\n// The stackInput can be either a full URL (e.g., https://my-team.grafana.net)\n// or just a slug (e.g., my-team).\nfunc validateTokenV6(","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/cmd/cloud_login.go#L252-L288","documentation":"During `k6 cloud login`, validateTokenV6 builds a v6 client and calls ValidateToken against the normalized stack URL; any failure (HTTP 401 for a bad token, wrong stack, or a network error) is wrapped in this user-facing message with a link to the token docs. The '%w' keeps the server's error detail, so the real reason is always appended after 'Server error for details: '.","triggerScenarios":"`k6 cloud login` with a revoked/expired API token, a token from a different org or stack, a mistyped stack slug, no network route to the API host, or a proxy mangling the request.","commonSituations":"Tokens pasted with whitespace or truncated by terminal wrapping; using a Grafana service-account token where a k6 Cloud token is required; wrong stack slug (typos, renamed orgs); corporate proxies blocking the validation endpoint.","solutions":["Read the text after 'Server error for details: ' — 401 means bad token/stack, network errors mean connectivity","Regenerate the API token and re-run `k6 cloud login --token <token>`","Double-check the stack argument: a full URL (https://my-team.grafana.net) or just the slug (my-team)","Verify proxy/firewall allows requests to the stack host"],"exampleFix":"# before\nk6 cloud login --token 'eyJr... == '  # stray spaces, truncated\n# after\nk6 cloud login --token eyJr...==","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if _, _, _, err := validateTokenV6(gs, conf, token, stack); err != nil {\n    var re cloudapiv6.ResponseError\n    if errors.As(err, &re) && re.Response.StatusCode == 401 {\n        // permanent: token or stack wrong — regenerate and retry login once\n    }\n    // network-classified errors: retry login after checking connectivity\n}","preventionTips":["Copy tokens from a secrets manager, never from wrapped terminal output","Verify the stack slug resolves (open https://<slug>.grafana.net) before logging in","Script `k6 cloud login` non-interactively with --token in CI setup steps"],"tags":["auth","cloud","login","token"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}