{"record":{"id":"2fb5169435b4dbd5","repo":"grafana/k6","slug":"access-token-not-configured","errorCode":null,"errorMessage":"access token not configured","messagePattern":"access token not configured","errorType":"validation","errorClass":"errMissingToken","httpStatus":null,"severity":"error","filePath":"internal/cmd/cloud.go","lineNumber":39,"sourceCode":"\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)\n}\n\nfunc checkCloudLoginFor(conf cloudapi.Config, prefix string) error {\n\tif !conf.Token.Valid || conf.Token.String == \"\" {","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/cmd/cloud.go#L21-L57","documentation":"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.","triggerScenarios":"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`...'.","commonSituations":"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.","solutions":["Export K6_CLOUD_TOKEN with a valid Grafana Cloud API token","Run `k6 cloud login` to store the token persistently","Check the stored state with `k6 cloud login --show` and re-login if the token is '<not set>'"],"exampleFix":"# before\nexport K6_CLOUD_STACK_ID=123456\nk6 cloud run script.js   # ERR: access token not configured\n\n# after\nexport K6_CLOUD_STACK_ID=123456\nexport K6_CLOUD_TOKEN=eyJr...\nk6 cloud run script.js","handlingStrategy":"validation","validationCode":"# fail fast on a missing token before running cloud commands\n: \"${K6_CLOUD_TOKEN:?K6_CLOUD_TOKEN is required for cloud runs (or run 'k6 cloud login')}\"","typeGuard":null,"tryCatchPattern":"if err := checkCloudLoginFor(conf, prefix); err != nil {\n    if strings.Contains(err.Error(), \"access token not configured\") {\n        return errors.New(\"missing API token: create one in Grafana Cloud and export K6_CLOUD_TOKEN\")\n    }\n    return err\n}","preventionTips":["Mount the token as a secret and assert it is non-empty in CI before invoking k6","Verify with `k6 cloud login --show` that the token field is not '<not set>'","Remember the flag name K6_CLOUD_TOKEN (not K6_CLOUD_API_TOKEN) to avoid silent misses"],"tags":["cloud","auth","token","cli","configuration"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}