grafana/k6 · error
create or find load test
Error message
create or find load test: %w
What it means
First step of ProvisionLocalExecution failed: c.v6Client.CreateOrFindLoadTest(ctx, projectID, name) could not create or locate the cloud load test. This wraps any failure of the v6 cloud API call (auth, permissions, invalid project, network) under the 'create or find load test' prefix, so the underlying error identifies the real cause.
Solutions
- Run `k6 cloud login` to refresh token and stack, then retry
- Verify projectID: pass --project-id explicitly or set K6_CLOUD_PROJECT_ID to a project your token can see
- Read the wrapped error — a ResponseError with status/body tells you whether it is auth (401), permissions (403), or input (400)
- Retry once for transient network/5xx failures before investigating further
Example fix
// before
res, err := client.ProvisionLocalExecution(ctx, provisioning.ProvisionParams{ProjectID: 0, Name: name})
// after
// resolve and validate the project first
projectID, err := resolveProjectID(gs, &cloudConfig)
if err != nil { return err }
res, err := client.ProvisionLocalExecution(ctx, provisioning.ProvisionParams{ProjectID: projectID, Name: name}) Defensive patterns
Strategy: retry
Validate before calling
if projectID <= 0 {
return fmt.Errorf("projectID must be a positive cloud project ID")
}
if name == "" {
return fmt.Errorf("test name must not be empty")
} Try / catch
loadTestID, err := c.v6Client.CreateOrFindLoadTest(ctx, projectID, name)
if err != nil {
var respErr *cloudapiv6.ResponseError
if errors.As(err, &respErr) && respErr.Response.StatusCode == 401 {
return 0, fmt.Errorf("token expired; re-run `k6 cloud login`: %w", err)
}
if isTransient(err) { /* retry with backoff */ }
return 0, err
} Prevention
- Validate token + project before provisioning (call ListProjects once at startup)
- Refresh login config in CI jobs as a scheduled step so tokens never silently expire
- Wrap project/name resolution with clear errors so the provisioning call gets valid inputs
When it happens
Trigger: Invalid or expired K6_CLOUD_TOKEN (401), projectID the token has no access to (403/404), empty or duplicate-resolving test name rejected by the API, network failure to the /cloud/v6 load-tests endpoint, or a corrupted options payload preventing test creation.
Common situations: Token rotated in Grafana Cloud but not refreshed locally (fix with k6 cloud login), --project-id pointing at a project in another org, CI using a masked/expired token, or a stack mismatch after changing K6_CLOUD_HOST.
Understand the failure class
Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.
Related errors
- notify test run completed
- default stack configured but the default project ID is not…
- invalid stack URL
- : .\n
- start local execution
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/5950f2afbaa92c40.
Report an issue: GitHub.
Appendix: source
Thrown at internal/cloudapi/provisioning/provision.go:59
type ProvisionResult struct {
// TestRunID is the ID of the provisioned test run.
TestRunID int64
// TestRunDetailsPageURL is the URL of the test run details page.
TestRunDetailsPageURL string
// RuntimeConfig carries the metrics, secrets, and token
// configuration returned by the provisioning API.
RuntimeConfig RuntimeConfig
}
// ProvisionLocalExecution orchestrates the full local-execution
// provisioning flow: CreateOrFindLoadTest → StartLocalExecution →
// optional UploadArchive → WaitForTestRunReady.
func (c *Client) ProvisionLocalExecution(ctx context.Context, params ProvisionParams) (*ProvisionResult, error) {
loadTestID, err := c.v6Client.CreateOrFindLoadTest(ctx, params.ProjectID, params.Name)
if err != nil {
return nil, fmt.Errorf("create or find load test: %w", err)
}
// Serialise archive once to get its byte-length for the
// start_local_execution body. The same buffer is reused for
// the S3 upload to avoid a second serialisation.
var (
archiveSize int64
archiveBytes []byte
)
if params.Archive != nil {
var buf bytes.Buffer
if err := params.Archive.Write(&buf); err != nil {
return nil, fmt.Errorf("serialising archive: %w", err)
}
archiveSize = int64(buf.Len())
archiveBytes = buf.Bytes()
}
View on GitHub (pinned to 01ffac6f24)