grafana/k6 · error
: .\n
Error message
%s: %w.\n%w
What it means
checkCloudLoginFor found no usable access token: conf.Token is invalid/null or an empty string, so `k6 cloud` (and other cloud commands sharing the check) abort before any API call. The message composes the command-specific prefix ('Running cloud tests requires auth settings'), the 'access token not configured' sentinel, and the errCloudAuth hint pointing at `k6 cloud login`.
Solutions
- Run `k6 cloud login` to store token and stack together
- Or export K6_CLOUD_TOKEN=<api-token> (service accounts in CI) alongside K6_CLOUD_STACK_ID
- Or pass --token on the command line for one-off runs
- Verify afterwards with `k6 cloud login show` (or inspect the config file) that the token is populated
Example fix
# before k6 cloud run script.js # ERR: access token not configured # after export K6_CLOUD_TOKEN="$K6_TOKEN" k6 cloud run script.js
Defensive patterns
Strategy: validation
Validate before calling
if !conf.Token.Valid || conf.Token.String == "" {
return fmt.Errorf("no token: set K6_CLOUD_TOKEN or run `k6 cloud login`")
} Prevention
- Run `k6 cloud login` as the first step on any new machine/CI image
- Assert required secrets exist in CI before invoking k6
- After `k6 cloud logout`, grep your pipelines for stale cloud invocations
When it happens
Trigger: Fresh machine with no login, K6_CLOUD_TOKEN unset or set to empty in the environment, --token flag omitted, or a partially deleted config file (token cleared but stack ID left).
Common situations: New CI pipelines that copied the k6 invocation but not the token secret, local config at ~/.config/loadimpact/k6/config (or K6_CONFIG_PATH) truncated or reset, or token removed by `k6 cloud logout` while scripts still run cloud tests.
Related errors
- default stack configured but the default project ID is not…
- token is required to create cloud API client
- create or find load test
- invalid stack URL
- invalid stack URL
AI-assisted analysis of grafana/k6@94169daab2 (2026-08-18).
Data as JSON: /api/errors/ce21d20ede13e616.
Report an issue: GitHub.
Appendix: source
Thrown at internal/cmd/cloud.go:58
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)
}
func checkCloudLoginFor(conf cloudapi.Config, prefix string) error {
if !conf.Token.Valid || conf.Token.String == "" {
return fmt.Errorf("%s: %w.\n%w", prefix, errMissingToken, errCloudAuth)
}
if !conf.StackID.Valid || conf.StackID.Int64 == 0 {
return fmt.Errorf("%s: %w.\n%w", prefix, errMissingStackID, errCloudAuth)
}
return nil
}
// newCloudV6ClientFromConfig builds a v6 cloud API client from the on-disk and
// environment configuration. It verifies that a complete login is configured
// (using authPrefix in the error message) and wires the resolved stack ID into
// the client. It returns the client alongside the consolidated cloud config.
func newCloudV6ClientFromConfig(
gs *state.GlobalState, authPrefix string,
) (*cloudapiv6.Client, cloudapi.Config, error) {
currentDiskConf, err := readDiskConfig(gs)
if err != nil {
return nil, cloudapi.Config{}, err
}View on GitHub (pinned to 94169daab2)