grafana/k6 · error

could not create the cloud test run: %w

Error message

could not create the cloud test run: %w

What it means

Thrown by the `k6 cloud run --local-execution` code path when createCloudTest() fails to create the test run in Grafana Cloud (k6 Cloud) before executing it locally. Authentication errors (errCloudAuth) are passed through unwrapped, so this message wraps non-auth failures: API request errors, HTTP error responses, invalid project references, or quota issues returned by the cloud service.

Source

Thrown at internal/cmd/cloud_run.go:160

		)
	}

	return c.deprecatedCloudCmd.preRun(cmd, args)
}

func (c *cmdCloudRun) run(cmd *cobra.Command, args []string) error {
	if c.localExecution {
		c.runCmd.loadConfiguredTest = func(*cobra.Command, []string) (*loadedAndConfiguredTest, execution.Controller, error) {
			test, err := loadAndConfigureLocalTest(c.runCmd.gs, cmd, args, getCloudRunLocalExecutionConfig)
			if err != nil {
				return nil, nil, fmt.Errorf("could not load and configure the test: %w", err)
			}

			if err := createCloudTest(c.runCmd.gs, test); err != nil {
				if errors.Is(err, errCloudAuth) {
					return nil, nil, err
				}
				return nil, nil, fmt.Errorf("could not create the cloud test run: %w", err)
			}

			return test, local.NewController(), nil
		}
		return c.runCmd.run(cmd, args)
	}

	// When running the `k6 cloud run` command explicitly disable the usage report.
	c.noUsageReport = true

	return c.deprecatedCloudCmd.run(cmd, args)
}

func (c *cmdCloudRun) flagSet() *pflag.FlagSet {
	flags := pflag.NewFlagSet("", pflag.ContinueOnError)
	flags.SortFlags = false

	flags.BoolVar(&c.localExecution, "local-execution", c.localExecution,

View on GitHub (pinned to 93accf6570)

Solutions

  1. Verify the cloud token: check K6_CLOUD_TOKEN / config `collectors.cloud.token` is set, valid, and not expired (`k6 cloud login status` or a direct API call)
  2. Confirm the project ID/instance the token belongs to matches what the command expects (project ID in script options `ext: { loadimpact: { projectID } }` or config)
  3. Run with `--log-level debug` (or K6_LOG_LEVEL=debug) to see the wrapped cloud API error body and HTTP status
  4. Check network reachability of the configured cloud API host (proxy, TLS, DNS) from the machine running k6
  5. Retry after ruling out a Grafana Cloud incident (status.grafana.com) if the error is a 5xx

Example fix

# before
k6 cloud run --local-execution script.js
# error: could not create the cloud test run: ...

# after (verify token & project first)
k6 cloud login status  # or inspect collectors.cloud.token
K6_CLOUD_TOKEN=$TOKEN k6 cloud run --local-execution --log-level debug script.js
Defensive patterns

Strategy: validation

Validate before calling

# Before k6 cloud run --local-execution: verify token & project are usable
[ -n "$K6_CLOUD_TOKEN" ] || { echo 'K6_CLOUD_TOKEN is empty'; exit 1; }
k6 cloud login status || exit 1   # confirms the token authenticates
curl -sf -H "Authorization: Bearer $K6_CLOUD_TOKEN" \
  "https://grafana.com/api/cloud/v4/projects" >/dev/null || echo 'warn: cloud API unreachable/misconfigured'

Try / catch

#!/usr/bin/env bash
set -o pipefail
if ! k6 cloud run --local-execution script.js 2>err.log; then
  if grep -q 'could not create the cloud test run' err.log; then
    echo "cloud test creation failed — inspect err.log for the wrapped API error"
  fi
fi

Prevention

When it happens

Trigger: Running `k6 cloud run --local-execution script.js` (or the equivalent config that sets local execution) where createCloudTest fails for a non-auth reason: the cloud API returns 4xx/5xx (bad project ID, expired token lacking permissions, org mismatch, quota exceeded), the network/proxy to the cloud endpoint is broken, or the token's project context is wrong.

Common situations: K6_CLOUD_TOKEN or `collectors.cloud.token` points at a different project/org than the one addressed by the script's project ID; a corporate proxy blocks the cloud API; the token was rotated and the old one lacks the required scope; the k6 version talks to a deprecated cloud endpoint.

Related errors


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