{"record":{"id":"58440907cf8e726c","repo":"grafana/k6","slug":"failed-to-get-a-reference-id","errorCode":null,"errorMessage":"failed to get a reference ID","messagePattern":"failed to get a reference ID","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cloudapi/api.go","lineNumber":111,"sourceCode":"func (c *Client) CreateTestRun(testRun *TestRun) (*CreateTestRunResponse, error) {\n\turl := fmt.Sprintf(\"%s/tests\", c.baseURL)\n\n\t// Because the kind of request we make can vary depending on the test run configuration, we delegate\n\t// its creation to a helper.\n\trequest, err := c.makeCreateTestRunRequest(url, testRun)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tresponse := CreateTestRunResponse{}\n\terr = c.Do(request, &response)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tc.handleLogEntriesFromCloud(response)\n\tif response.ReferenceID == \"\" {\n\t\treturn nil, fmt.Errorf(\"failed to get a reference ID\")\n\t}\n\n\treturn &response, nil\n}\n\n// makeCreateTestRunRequest creates a new HTTP request for creating a test run.\n//\n// If the test run archive isn't set, the request will be a regular JSON request with the test run information.\n// Otherwise, the request will be a multipart form request containing the test run information and the archive file.\nfunc (c *Client) makeCreateTestRunRequest(url string, testRun *TestRun) (*http.Request, error) {\n\t// If the test run archive isn't set, we are not uploading an archive and can use the regular request JSON format.\n\tif testRun.Archive == nil {\n\t\treturn c.NewRequest(http.MethodPost, url, testRun)\n\t}\n\n\t// Otherwise, we need to create a multipart form request containing the test run information as\n\t// well as the archive file.\n\tfields := [][2]string{","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/cloudapi/api.go#L93-L129","documentation":"cloudapi.Client.CreateTestRun (cloudapi/api.go) submits the test-run creation request; the call itself succeeded (2xx, JSON decoded), but the response contained no reference_id, so there is no cloud test run identifier to associate metrics with, and the client refuses to continue. It means the endpoint answered with an unexpected success payload - not that the request was rejected.","triggerScenarios":"POST to the create-test-run endpoint under K6_CLOUD_HOST returning 2xx JSON without reference_id: a token valid for a different cloud environment than the configured host, a backend API version the k6 build does not speak, or an intermediary (proxy, gateway) returning its own 2xx page for the request.","commonSituations":"K6_CLOUD_HOST mismatched with the token (e.g. pointing at a legacy loadImpact host with a Grafana Cloud token or vice versa); a very old k6 binary against a newer backend; a reverse proxy or mock server in front of the API that swallows the real response body.","solutions":["Make sure K6_CLOUD_HOST matches the environment the token belongs to (Grafana Cloud k6 uses the host printed by 'k6 cloud login' - re-run it)","Update k6 to the latest release so the create-test-run request/response contract matches the backend","Reproduce the call with curl -v against the same host and inspect the response body for reference_id","Check HTTP(S)_PROXY settings - an intercepting proxy may be returning its own 2xx response"],"exampleFix":"# before - host/token from different environments\nexport K6_CLOUD_HOST=https://api.old-cloud.example\nk6 cloud run script.js   # fails: failed to get a reference ID\n\n# after - log in so host and token are consistent\nk6 cloud login -t $K6_CLOUD_TOKEN   # or set the token via env\nk6 cloud run script.js","handlingStrategy":"validation","validationCode":"# before a cloud run, confirm the host/token pair yields a test run with an ID\ncurl -sS -X POST \"$K6_CLOUD_HOST/v1/test-runs\" \\\n  -H \"Authorization: Token $K6_CLOUD_TOKEN\" \\\n  -H 'Content-Type: application/json' \\\n  -d '{\"name\":\"probe\"}' | grep -q reference_id \\\n  || echo 'host/token mismatch: response has no reference_id'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use 'k6 cloud login' to keep K6_CLOUD_HOST and the token in sync instead of setting them independently","Re-validate host/token after environment migrations (e.g. moving to a different cloud region or product)","Keep k6 updated so the create-test-run contract matches the backend"],"tags":["cloud","configuration","authentication","http"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}