grafana/k6 · error
http.batch() accepts only an array or an object of requests
Error message
http.batch() accepts only an array or an object of requests
What it means
Batch accepts exactly one argument which must be an array or an object of request specs; more than one variadic argument triggers this error. It's an arity/type check protecting against http.batch(req1, req2) misuse — requests must be collected in a single array or object.
Source
Thrown at js/modules/k6/http/request.go:504
results[key] = c.responseFromHTTPext(resp)
i++
}
return batchReqs, results, nil
}
// Batch makes multiple simultaneous HTTP requests. The provideds reqsV should be an array of request
// objects. Batch returns an array of responses and/or error
func (c *Client) Batch(reqsV ...sobek.Value) (any, error) {
state := c.moduleInstance.vu.State()
if state == nil {
return nil, ErrBatchForbiddenInInitContext
}
if len(reqsV) == 0 {
return nil, fmt.Errorf("no argument was provided to http.batch()")
} else if len(reqsV) > 1 {
return nil, fmt.Errorf("http.batch() accepts only an array or an object of requests")
}
var (
err error
batchReqs []httpext.BatchParsedHTTPRequest
results any // either []*Response or map[string]*Response
)
switch v := reqsV[0].Export().(type) {
case []any:
batchReqs, results, err = c.prepareBatchArray(v)
case map[string]any:
batchReqs, results, err = c.prepareBatchObject(v)
default:
return nil, fmt.Errorf("invalid http.batch() argument type %T", v)
}
if err != nil {
if state.Options.Throw.Bool {View on GitHub (pinned to 01ffac6f24)
Solutions
- Combine all requests into a single array or object argument
- Remove extra arguments
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at js/modules/k6/http/request.go:504 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/3d72e50c427eb51e.
Report an issue: GitHub.