k6 run
Run a load test script. This is the primary command for executing k6 tests.Synopsis
Description
Thek6 run command starts a test and exposes a REST API to interact with it. The command loads a test script, initializes virtual users (VUs), and executes the test according to the configured options.
The script argument can be:
- A path to a JavaScript test file
- A path to a k6 archive (
.tarfile) -to read the script from stdin
Examples
Flags
Test Execution
Number of virtual users to run concurrently
Test duration limit (e.g.,
10s, 5m, 1h30m)Script total iteration limit (among all VUs)
Add a stage in the format
[duration]:[target] (e.g., 10s:100). Can be specified multiple times.Start the test in a paused state
Limit execution to a specified segment (e.g.,
10%, 1/3, 0.2:2/3)The execution segment sequence for distributed execution
Test Lifecycle
Skip running the
setup() functionSkip running the
teardown() functionKeep the API server alive past test end
HTTP Options
Follow at most n redirects
Maximum parallel batch requests
Maximum parallel batch requests per host
Limit requests per second (0 = unlimited)
User agent string for HTTP requests
Log all HTTP requests and responses. Use
--http-debug=full to include body.Skip verification of TLS certificates
Disable keep-alive connections
Don’t reuse connections between iterations
Minimum amount of time k6 will take executing a single iteration
Throw warnings (like failed HTTP requests) as errors
Read but don’t process or save HTTP response bodies
Network Configuration
Blacklist an IP range from being called
Block a case-insensitive hostname pattern (with optional leading wildcard)
Client IP ranges and/or CIDRs from which each VU will make requests
DNS resolver configuration. Format:
ttl=VALUE,select=VALUE,policy=VALUERuntime Options
Add/override environment variable with
VAR=valuePass the real system environment variables to the runtime
JavaScript compatibility mode:
extended or baseOverride test type:
js or archiveOutput and Metrics
URI for an external metrics database (can be specified multiple times)
Summary display mode:
compact, full, or disabledOutput the end-of-test summary report to a JSON file
Define stats for trend metrics (e.g.,
avg,p(95),p(99))Time unit for displaying trend stats:
s, ms, or usOnly include these system tags in metrics
Add a tag to be applied to all samples in the format
[name]=[value]Don’t run thresholds
Redirect console logging to the provided output file
Other Options
Path to config file (default:
./k6.json)Don’t send anonymous usage statistics
Output for k6 traces:
none or otel[=host:port]Exit Codes
k6 uses specific exit codes to indicate different error conditions:0- Test passed successfully99- Test failed due to threshold violations108- Test marked as failed viaexec.test.status- Other non-zero codes indicate various errors
REST API
When running a test, k6 exposes a REST API (by default onlocalhost:6565) that can be used to:
- Get test status
- Pause/resume execution
- Scale VUs dynamically
- Retrieve metrics
--address flag to configure the API server address.
See Also
- k6 archive - Create an archive of your test
- k6 cloud - Run tests in Grafana Cloud
- CLI options reference