Grafana Cloud

Author k6 scripts

Use k6 Script Authoring mode when you want the Assistant to help create or improve performance test scripts. The mode focuses on k6 workflows, including script generation, script review, conversion from other formats, and k6 Cloud test context.

Before you begin

Use k6 Script Authoring mode from Grafana Cloud. This mode is not available in self-managed deployments.

To work with existing k6 Cloud tests or open generated scripts in the k6 editor, make sure the k6 app and k6 data source are configured in your Grafana Cloud stack. To generate scripts from repository code, configure an MCP server for your repository provider.

Start script authoring

Open the Assistant and switch the mode to k6 Script Authoring. On a new conversation, the Assistant offers options for writing a new test, discovering endpoints from your environment, or working with an existing script.

Generate a new script

Describe the service, target URL, endpoints, and load profile you want to test. The Assistant returns a complete k6 script in a copyable JavaScript code block and applies k6 best practices such as URL grouping, checks, thresholds, and realistic scenarios.

Create a load test for https://api.example.com with login, list orders, and create order endpoints.

Generate a smoke test for the checkout API with 5 virtual users for 2 minutes.

When the Assistant has to infer values, it marks them with // TODO comments so you can review the script before running it.

Generate from telemetry, specs, or repositories

The Assistant can use observability data, API specifications, and repository context to make generated scripts more accurate.

For example, you can ask the Assistant to discover real endpoints from Prometheus, Tempo, or Loki before generating a script:

Build a k6 script for the checkout service using recent traffic patterns from our metrics and traces.

You can also provide an OpenAPI or Swagger URL, or a GitHub repository URL when a GitHub MCP server is configured:

Generate a k6 test for the payments API using this OpenAPI spec: https://api.example.com/openapi.json.

Generate a script for the checkout service from https://github.com/example/checkout.

When endpoint discovery is involved, the Assistant asks you to confirm the endpoints before it generates the script.

Work with existing scripts

Use k6 Script Authoring mode to analyze, improve, fetch, or convert scripts.

Analyze this k6 script and tell me what might fail in k6 Cloud.

Improve this script to add thresholds and reduce high-cardinality metrics.

Convert this curl command to a k6 script.

Fetch the script for test ID 12345 and suggest improvements.

If the Assistant produces an updated script, it can help open the result in the k6 script editor. If you are already on a k6 editor page, the Assistant can place the generated script into the editor.

Review generated scripts

Review generated scripts before running them. Pay attention to // TODO comments, authentication placeholders, test data, and environment-specific values. For sensitive values such as API keys or tokens, prefer k6 secrets when you are ready to run the script in production workflows.

Generated scripts can include Tempo tracing and Pyroscope profiling instrumentation so you can correlate load test results with traces and profiles in Grafana.

Author browser and hybrid scripts

Use browser script authoring when you need the Assistant to help write k6/browser scripts that measure frontend user experience, not only backend response time. For load tests against a web application, Assistant can include Core Web Vitals thresholds and screenshots in generated browser scripts.

For browser and hybrid scripts, Assistant authors the script directly instead of using the standard protocol-script template.

Browser load tests use check assertions and include thresholds for browser_web_vital_lcp, browser_web_vital_inp, and browser_web_vital_cls by default. Functional browser tests use expect assertions for fail-loud, auto-retrying web checks. If your request doesn’t make clear whether the test should be functional or load/performance-focused, Assistant asks you to choose before it generates the script.

You can also ask for a hybrid test that combines protocol-level HTTP load with a small browser scenario. The HTTP scenario generates load, while the browser scenario measures Core Web Vitals under that load.

Generated browser scripts use asynchronous browser APIs. Review the script for missing await statements before running it, especially after you edit generated steps by hand.

Create a browser load test for https://shop.example.com and include Core Web Vitals thresholds.

Create a hybrid k6 test for checkout: 100 HTTP users for load and 3 browser users for the checkout journey.

Next steps