Skip to main content
Options configure how your k6 test runs. They control aspects like virtual users, duration, thresholds, tags, and many other test behaviors.

What are options?

Options determine test execution parameters such as:
  • Number of virtual users (VUs)
  • Test duration or iterations
  • Thresholds for pass/fail criteria
  • Tags for organizing metrics
  • Scenarios for complex workload patterns
  • Network settings and timeouts
Options provide the configuration layer that controls your test execution, separate from the test logic itself.

Where to set options

k6 provides multiple places to define options, each suited for different use cases:
Set options in your test script using the options object. This is the recommended approach for most cases.
Benefits:
  • Version controlled with your test
  • Easy to reuse and share
  • Self-documenting

Order of precedence

When options are set in multiple places, k6 uses this precedence order (highest to lowest):
1

CLI flags (highest)

Command-line flags override everything else
2

Environment variables

K6_ prefixed environment variables
3

Script options

Options exported in the test script
4

Config file

Options from —config file
5

Defaults (lowest)

k6’s built-in default values
CLI flags have the highest precedence. They override all other option sources.

Common options

Here are the most frequently used options:

Virtual users and duration

Thresholds

Define pass/fail criteria:

Tags

Add tags to all metrics:

Scenarios

Define complex workload patterns:

Complete example

Here’s a comprehensive example showing various options:

Using environment variables in options

Reference environment variables in your script options:
Run with custom values:

Accessing options at runtime

Access the resolved option values during test execution:

Override examples

Using config files

Create a reusable config file:
options.json
Use it with your test:
Or load it in your script:

Best practices

Use script options

Keep options in your script for version control and easy reuse.

CLI for overrides

Use CLI flags to quickly test variations without editing the script.

Environment variables for CI/CD

Use env vars to configure tests differently across environments.

Document your options

Add comments explaining why you chose specific option values.

Next steps

Options Reference

See the complete list of all available options with detailed descriptions