{"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":null,"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/94169daab29df52c1ed2ee0549657a577666b855/internal/cmd/cloud.go#L21-L57","documentation":"errMissingToken is the specific leg of the auth check in checkCloudLoginFor: `conf.Token` is either not set or an empty string, so every cloud API call would be rejected. k6 reports it wrapped under the command's auth prefix together with the `k6 cloud login` advisory. No HTTP request is made — the check is purely local config validation.","triggerScenarios":"Any cloud sub-command (cloud run/upload, project list, test list) with no token anywhere in the config precedence chain: no `k6 cloud login` stored token, no K6_CLOUD_TOKEN env var, no token in the config file. Typically after a fresh install, after `k6 cloud login -r` reset, or when a CI job never exported the secret.","commonSituations":"New machines/CI images without login state; the CI secret for K6_CLOUD_TOKEN not configured or misnamed; the token key in the JSON config file deleted by hand; using a K6_CONFIG file that lacks the cloud section.","solutions":["Run `k6 cloud login -t <token> --stack <stack>` to validate and persist the token","In CI, export K6_CLOUD_TOKEN (a Grafana Cloud access policy token with the k6 scope) as a masked secret","Verify what is stored with `k6 cloud login -s`","Check for a trailing typo in the env var name (K6_CLOUD_TOKEN, not K6_CLOUD_API_TOKEN)"],"exampleFix":"# before\nk6 cloud run script.js  # -> access token not configured\n\n# after\nexport K6_CLOUD_TOKEN=\"glc_ey...\"   # or: k6 cloud login -t glc_ey... --stack my-team\nk6 cloud run script.js","handlingStrategy":"validation","validationCode":"# fail fast before running k6 cloud commands\n: \"${K6_CLOUD_TOKEN:?K6_CLOUD_TOKEN must be set (Grafana Cloud access policy token)}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Name the CI secret exactly K6_CLOUD_TOKEN and mark it required","Run `k6 cloud login -s` after setup to confirm the token row is populated","Rotate tokens on a schedule and update the secret before expiry, not after"],"tags":["k6","cloud","authentication","api-token","configuration"],"backgroundTag":"missing-api-token","analyzedSha":"94169daab29df52c1ed2ee0549657a577666b855","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}