grafana/k6 · error
Authentication failed as provided token or stack might not b
Error message
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
What it means
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: '.
Source
Thrown at internal/cmd/cloud_login.go:270
gs *state.GlobalState,
config *cloudapi.Config,
rawConfig json.RawMessage,
token, stack string,
) error {
config.Token = null.StringFrom(token)
consolidatedCurrentConfig, warn, err := cloudapi.GetConsolidatedConfig(
rawConfig, gs.Env, "", nil)
if err != nil {
return err
}
if warn != "" {
gs.Logger.Warn(warn)
}
stackURL, stackID, defaultProjectID, err := validateTokenV6(
gs, consolidatedCurrentConfig, token, stack)
if err != nil {
return fmt.Errorf( //nolint:staticcheck // ST1005: this is a user-facing error
"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",
err)
}
config.StackURL = null.StringFrom(stackURL)
config.StackID = null.IntFrom(stackID)
config.DefaultProjectID = null.IntFrom(defaultProjectID)
return nil
}
// validateTokenV6 validates a token and a stack URL/slug and returns the normalized URL, stack ID,
// and default project ID.
// The stackInput can be either a full URL (e.g., https://my-team.grafana.net)
// or just a slug (e.g., my-team).
func validateTokenV6(View on GitHub (pinned to 93accf6570)
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
Example fix
# before k6 cloud login --token 'eyJr... == ' # stray spaces, truncated # after k6 cloud login --token eyJr...==
Defensive patterns
Strategy: try-catch
Try / catch
if _, _, _, err := validateTokenV6(gs, conf, token, stack); err != nil {
var re cloudapiv6.ResponseError
if errors.As(err, &re) && re.Response.StatusCode == 401 {
// permanent: token or stack wrong — regenerate and retry login once
}
// network-classified errors: retry login after checking connectivity
} Prevention
- 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
When it happens
Trigger: `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.
Common situations: 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.
Understand the failure class
- Authentication and authorization failures — expired tokens, bad credentials, and missing scopes.
Related errors
- token value is required but it was not passed or is empty
- Run `k6 cloud login` to authenticate, or check the docs for
- access token not configured
- stack value is required but it was not passed or is empty
- token cannot be empty
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/cb88caaa7758da56.
Report an issue: GitHub.