Skip to main content
The k6/net/grpc module provides a gRPC client for making Remote Procedure Calls (RPC) over HTTP/2.

Overview

Use this module to test gRPC services by making unary and streaming RPC calls. The module supports loading protocol buffer definitions, establishing connections, and invoking RPC methods with full support for metadata and parameters.

Importing the Module

API Reference

Client Class

constructor
Creates a new gRPC client for making RPC calls to a gRPC server.

Client Methods

function
Loads and parses protocol buffer definitions to be made available for RPC requests.Parameters:
string | string[]
Paths to search for imported proto files. Use null to load from current directory.
...string
required
One or more proto file paths to load
function
Connects to a gRPC service.Parameters:
string
required
Server address (e.g., grpc.example.com:443)
Params
Connection parameters (TLS, credentials, timeout, etc.)
function
Makes a unary RPC call for the given service/method.Parameters:
string
required
RPC method in format package.Service/Method
object
required
Request message object matching the proto definition
Params
Request-specific parameters (metadata, tags, timeout)
Returns:
Response
gRPC response object
function
Asynchronously makes a unary RPC call for the given service/method.Parameters:
string
required
RPC method in format package.Service/Method
object
required
Request message object matching the proto definition
Params
Request-specific parameters
Returns:
Promise<Response>
Promise that resolves to a gRPC Response
function
Closes the connection to the gRPC service.

Response Object

number
gRPC status code (see Constants below)
object
Response message from the server
object
Response headers/metadata
object
Response trailers/metadata
object
Error information if the call failed

Params Object

object
Custom metadata to send with the request as key-value pairs.
object
Custom metric tags for filtering results and setting thresholds.
string
Request timeout (e.g., "10s", "500ms")
boolean
Use plaintext connection (no TLS). Default: false

Status Constants

The module provides constants to distinguish between gRPC response statuses:

Stream Support

For bidirectional and streaming RPCs:
constructor
Creates a new gRPC stream for bidirectional or streaming calls.
function
Adds an event listener for stream events: data, error, end
function
Writes a message to the stream.
function
Signals to the server that the client has finished sending.

gRPC Metrics

k6 automatically collects gRPC-specific metrics:

Examples

Basic Unary RPC

Async Invocation

Streaming RPC

Status Code Checking

Response Object

gRPC response structure

Stream

Streaming RPC support

gRPC Testing Guide

Learn gRPC testing patterns

Protocol Buffers

Protocol buffer documentation