grafana/k6 · error · errMissingToken

access token not configured

Error message

access token not configured

What it means

errMissingToken is the specific missing-credential error used by checkCloudLoginFor: when conf.Token is not valid (unset or empty string) the returned error chains this message under the command's prefix, followed by the actionable errCloudAuth hint. It means the stack side may be fine but the API token is absent.

Source

Thrown at internal/cmd/cloud.go:39

	"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)
}

func checkCloudLoginFor(conf cloudapi.Config, prefix string) error {
	if !conf.Token.Valid || conf.Token.String == "" {

View on GitHub (pinned to 93accf6570)

Solutions

  1. Export K6_CLOUD_TOKEN with a valid Grafana Cloud API token
  2. Run `k6 cloud login` to store the token persistently
  3. Check the stored state with `k6 cloud login --show` and re-login if the token is '<not set>'

Example fix

# before
export K6_CLOUD_STACK_ID=123456
k6 cloud run script.js   # ERR: access token not configured

# after
export K6_CLOUD_STACK_ID=123456
export K6_CLOUD_TOKEN=eyJr...
k6 cloud run script.js
Defensive patterns

Strategy: validation

Validate before calling

# fail fast on a missing token before running cloud commands
: "${K6_CLOUD_TOKEN:?K6_CLOUD_TOKEN is required for cloud runs (or run 'k6 cloud login')}"

Try / catch

if err := checkCloudLoginFor(conf, prefix); err != nil {
    if strings.Contains(err.Error(), "access token not configured") {
        return errors.New("missing API token: create one in Grafana Cloud and export K6_CLOUD_TOKEN")
    }
    return err
}

Prevention

When it happens

Trigger: A cloud command guarded by checkCloudLogin runs with Token invalid/empty — e.g. only K6_CLOUD_STACK_ID is set, or the stored login config lost its token. Produces '<prefix>: access token not configured.\nRun `k6 cloud login`...'.

Common situations: CI pipelines that export the stack ID but forget K6_CLOUD_TOKEN; `k6 cloud login --reset` followed by attempting a cloud run without re-login; expired token removed from config; token passed via a misspelled env variable.

Related errors


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