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
int
default:"1"
Number of virtual users to run concurrently
duration
Test duration limit (e.g.,
10s, 5m, 1h30m)int
Script total iteration limit (among all VUs)
string[]
Add a stage in the format
[duration]:[target] (e.g., 10s:100). Can be specified multiple times.boolean
Start the test in a paused state
string
Limit execution to a specified segment (e.g.,
10%, 1/3, 0.2:2/3)string
The execution segment sequence for distributed execution
Test Lifecycle
boolean
Skip running the
setup() functionboolean
Skip running the
teardown() functionboolean
Keep the API server alive past test end
HTTP Options
int
default:"10"
Follow at most n redirects
int
default:"20"
Maximum parallel batch requests
int
default:"6"
Maximum parallel batch requests per host
int
Limit requests per second (0 = unlimited)
string
User agent string for HTTP requests
string
Log all HTTP requests and responses. Use
--http-debug=full to include body.boolean
Skip verification of TLS certificates
boolean
Disable keep-alive connections
boolean
Don’t reuse connections between iterations
duration
Minimum amount of time k6 will take executing a single iteration
boolean
Throw warnings (like failed HTTP requests) as errors
boolean
Read but don’t process or save HTTP response bodies
Network Configuration
string[]
Blacklist an IP range from being called
string[]
Block a case-insensitive hostname pattern (with optional leading wildcard)
string
Client IP ranges and/or CIDRs from which each VU will make requests
string
DNS resolver configuration. Format:
ttl=VALUE,select=VALUE,policy=VALUERuntime Options
string[]
Add/override environment variable with
VAR=valueboolean
Pass the real system environment variables to the runtime
string
default:"extended"
JavaScript compatibility mode:
extended or basestring
Override test type:
js or archiveOutput and Metrics
string[]
URI for an external metrics database (can be specified multiple times)
string
default:"compact"
Summary display mode:
compact, full, or disabledstring
Output the end-of-test summary report to a JSON file
string[]
Define stats for trend metrics (e.g.,
avg,p(95),p(99))string
Time unit for displaying trend stats:
s, ms, or usstring[]
Only include these system tags in metrics
string[]
Add a tag to be applied to all samples in the format
[name]=[value]boolean
Don’t run thresholds
string
Redirect console logging to the provided output file
Other Options
string
Path to config file (default:
./k6.json)boolean
Don’t send anonymous usage statistics
string
default:"none"
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