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.

Next steps