/k6:generating-api-load-testsfrom k6
Generates k6 load test scripts for HTTP REST APIs, gRPC services, and WebSocket connections with authentication, data parameterization, checks, and thresholds. Handles version-specific syntax for v2.x and v1.x.
Ships in k6. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Generate k6 load test scripts for protocol-level APIs. Covers HTTP/REST, gRPC, and WebSocket protocols with authentication, data parameterization, checks, and thresholds.
Written for k6 v2.3.0 (current stable). The v1.8.x maintenance line is supported where noted; differences are marked v1.x: inline. Before generating, determine the version of the environment that will run the test:
k6 version where the test will execute (prints k6 v2.3.0 (...)). For Docker, CI, or k6-operator, read the pinned image tag, the setup-k6-action k6-version input, or spec.runner.image instead.// Target: k6 v2.3.0.Version notes for this skill:
Params.auth: 'basic' has no effect on any supported version. Basic auth is applied automatically when the URL carries credentials (https://user:pass@host/) or set the Authorization header yourself. Only 'digest' and 'ntlm' are meaningful values.async default function that awaits a Promise resolved on end; event handlers only run when the call stack is empty (all versions).http.query() (HTTP QUERY, RFC 10008) is documented for v2.3.x. tlsAIAFetch (fetch missing intermediate CA certificates) and the WebSocket.OPEN-style ready-state constants need v2.3.0+.TextEncoder/TextDecoder globals need v2.2.0+. v1.x: use k6/encoding.k6/experimental/redis was removed in v2.0.0; import k6/x/redis (auto-resolved). v1.x: community extensions also need K6_ENABLE_COMMUNITY_EXTENSIONS=true.k6 inspect script.js, then k6 run --once script.js (v2.3.0+; v1.x: --vus 1 --iterations 1).For the full feature/version matrix see /k6:operating-k6-in-ci-cd (reference/version-compatibility.md).
// Target: k6 v2.3.0
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
vus: 10,
duration: '30s',
thresholds: {
http_req_duration: ['p(95)<500'],
http_req_failed: ['rate<0.01'],
},
};
export default function () {
const res = http.get('https://quickpizza.grafana.com/api/json');
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
'body is JSON': (r) => r.headers['Content-Type'].includes('application/json'),
});
sleep(1);
}
https://quickpizza.grafana.com is the public k6 demo service (/api/json, /api/post, /api/users/token/login, /api/ratings). The older test.k6.io and test-api.k6.io hosts redirect there.
Every k6 script follows a 4-stage lifecycle:
1. init — Runs once per VU. Import modules, load files, define options.
Cannot make HTTP requests.
2. setup() — Runs once before VU stage. Prepare test data, authenticate.
Can make HTTP requests. Return value passed to default() and teardown().
3. default — Runs repeatedly per VU. The main test logic.
Each iteration resets cookies and tears down connections.
4. teardown — Runs once after all VUs finish. Cleanup resources.
import http from 'k6/http';
export const options = { vus: 5, duration: '10s' };
export function setup() {
const loginRes = http.post('https://api.example.com/login', JSON.stringify({
username: 'testuser', password: 'testpass',
}), { headers: { 'Content-Type': 'application/json' } });
return { token: loginRes.json('token') };
}
export default function (data) {
http.get('https://api.example.com/items', {
headers: { Authorization: `Bearer ${data.token}` },
});
}
export function teardown(data) {
http.post('https://api.example.com/logout', null, {
headers: { Authorization: `Bearer ${data.token}` },
});
}
Choose the protocol matching your API:
k6/x/tcp extension (auto-resolved on import) offers a Node-style Socket with connect(), write(), on('data'), TLS, and tcp_* metrics for non-HTTP protocols. See /k6:operating-k6-in-ci-cd (reference/extensions.md) for the extension tableFor loading test data from external files and generating dynamic data:
See reference/data-parameterization.md — SharedArray, CSV/JSON loading, per-VU data, environment variables, secrets (k6/secrets), binary/text encoding, dynamic data generation
Checks are assertions that do not stop execution on failure. They track pass/fail rates as metrics.
import { check } from 'k6';
check(res, {
'status is 200': (r) => r.status === 200,
'body contains expected': (r) => r.body.includes('success'),
'response is JSON': (r) => r.headers['Content-Type'].includes('application/json'),
'has required field': (r) => r.json('data.id') !== undefined,
});
Combine checks with thresholds to enforce pass/fail:
export const options = {
thresholds: {
checks: ['rate>0.99'], // 99% of checks must pass
},
};
export const options = {
thresholds: {
http_req_duration: ['p(95)<500', 'p(99)<1000'], // 95th percentile < 500ms
http_req_failed: ['rate<0.01'], // Error rate < 1%
http_reqs: ['rate>100'], // At least 100 RPS
checks: ['rate>0.99'], // 99% checks pass
},
};
const res = http.get('https://api.example.com/users', {
tags: { name: 'GetUsers', type: 'api' },
});
import { group } from 'k6';
export default function () {
group('User API', function () {
http.get('https://api.example.com/users');
http.get('https://api.example.com/users/1');
});
group('Product API', function () {
http.get('https://api.example.com/products');
});
}
import { sleep } from 'k6';
export default function () {
// test logic...
sleep(Math.random() * 3 + 1); // Random 1-4 second pause (realistic user think time)
}
import { Trend, Counter, Rate } from 'k6/metrics';
const apiLatency = new Trend('api_latency');
const apiErrors = new Counter('api_errors');
const apiSuccessRate = new Rate('api_success_rate');
export default function () {
const res = http.get('https://api.example.com/data');
apiLatency.add(res.timings.duration);
apiSuccessRate.add(res.status === 200);
if (res.status !== 200) apiErrors.add(1);
}
When generating a k6 test script, follow this process:
k6 inspect script.js parses the script and prints the resolved options; k6 run --once script.js (v2.3.0+) runs one iteration without touching the scenario definition. v1.x: k6 run --vus 1 --iterations 1 script.js/k6:designing-test-scenarios/k6:analyzing-test-results/k6:generating-tests-from-code/k6:generating-tests-from-openapi/k6:operating-k6-in-ci-cdWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
8 skills in this plugin
/analyzing-test-resultsUse when interpreting k6 test output, analyzing performance metrics, identifying bottlenecks, tuning thresholds, or optimizing k6 test scripts. Use when the user has k6 test results and needs to understand response times, error rates, percentiles (p95, p99), or performance degradation patterns./designing-test-scenariosUse when designing k6 load profiles, choosing executors, configuring VU patterns, setting thresholds, or planning test scenarios. Use when the user asks about stress test, spike test, soak test, breakpoint test, load model, executor selection, or pass/fail criteria./generating-browser-testsUse when creating k6 browser-based performance tests, testing frontend performance, measuring Web Vitals (LCP, FCP, CLS, INP, TTFB), or automating browser interactions for load testing. Use when the user mentions browser testing, page load testing, E2E performance, or Chromium-based testing with k6./generating-tests-from-codeUse when analyzing an existing API codebase to auto-generate k6 load test scripts. Use when the user wants to create k6 tests from source code, route definitions, controllers, or middleware in frameworks like Express, NestJS, Spring Boot, FastAPI, or Django./generating-tests-from-openapiUse when generating k6 load test scripts from OpenAPI specification files (YAML or JSON). Use when the user has an OpenAPI spec, API specification, or wants to create k6 tests from API documentation defined in OpenAPI 3.0 or 3.1 format./operating-k6-in-ci-cdUse when setting up k6 in CI/CD pipelines (GitHub Actions, GitLab CI, Jenkins), configuring distributed testing with k6-operator on Kubernetes, managing k6 extensions (xk6), or checking which k6 version an environment runs and what that version supports. Use when the user wants to automate performance tests in a pipeline, run distributed load tests, pin or upgrade a k6 version, or asks whether a k6 feature exists in their version.npx claudepluginhub kimdoubleb/grafana-k6-skills --plugin k6Other plugins' skills for the same job