Sub topic 6
Calling the Endpoint: V1 and V2 Protocols
This chapter assumes that you understand Kubernetes Pods, Services, namespaces, and kubectl. You should also know basic HTTP, JSON, and how a trained model accepts input and returns predictions.
A KServe InferenceService exposes a network endpoint for prediction. KServe supports two common request formats:
- V1, the older KServe and TensorFlow-style protocol.
- V2, also called the Open Inference Protocol, a model-serving standard with explicit tensor metadata.
The protocol is separate from the model format. A scikit-learn model can use a KServe runtime that accepts V1 or V2 requests. Check the runtime documentation before choosing a request format.
V1 requests
A V1 prediction request uses the instances field. Each instance contains the values for one prediction.
For a service named sklearn-iris, the usual path is:
/v1/models/sklearn-iris:predictA request with two Iris samples looks like this:
{
"instances": [
[6.8, 2.8, 4.8, 1.4],
[6.0, 3.4, 4.5, 1.6]
]
}The server normally returns a predictions field. The exact prediction values and types depend on the model.
The following command sends the request through an ingress. INGRESS_HOST, INGRESS_PORT, and SERVICE_HOSTNAME must contain values for your cluster.
cat > iris-input.json <<'EOF'
{"instances": [[6.8, 2.8, 4.8, 1.4], [6.0, 3.4, 4.5, 1.6]]}
EOF
curl \
-H "Host: ${SERVICE_HOSTNAME}" \
-H "Content-Type: application/json" \
"http://${INGRESS_HOST}:${INGRESS_PORT}/v1/models/sklearn-iris:predict" \
--data-binary @iris-input.jsonThe Host header matters when the ingress uses the service hostname to route the request. Without it, the request may reach the cluster but not the intended model.
V2 requests
V2 describes each input as a tensor. A tensor is a multidimensional array with a shape and a data type. The request uses the /infer action:
/v2/models/sklearn-iris/inferThe same two samples can be represented as one input tensor:
{
"inputs": [
{
"name": "input-0",
"shape": [2, 4],
"datatype": "FP32",
"data": [
6.8, 2.8, 4.8, 1.4,
6.0, 3.4, 4.5, 1.6
]
}
]
}Here, the shape [2, 4] means two rows with four values each. The datatype tells the server how to interpret the numbers. The input name must match the name expected by the serving runtime.
V2 also provides standard health and metadata paths:
/v2/health/readychecks whether the server is ready./v2/health/livechecks whether the server process is alive./v2/models/sklearn-irisreturns model metadata when supported./v2/models/sklearn-iris/inferperforms inference.
Choosing between V1 and V2
| Concern | V1 | V2 |
|---|---|---|
| Request structure | Simple `instances` or `inputs` JSON | Explicit tensor inputs |
| Shape and type metadata | Often implied | Required in the request |
| Client compatibility | Common in older KServe examples | Better for standard model-serving clients |
| Best use | Simple tabular or legacy integrations | Multiple tensors, strict contracts, and portable clients |
Use the protocol supported by both your client and runtime. Do not assume that changing /v1/models/...:predict to /v2/models/.../infer is enough. The body structure and input names must change too.
Debugging failed requests
A 404 often means that the path, model name, or ingress route is wrong. A 400 usually means that the JSON body does not match the runtime's schema. A 503 can mean that the model is not ready or that no serving pod is available.
Start by checking the resource and its events:
kubectl get inferenceservice sklearn-iris
kubectl describe inferenceservice sklearn-iris
kubectl get podsThen test readiness before sending a prediction. If the service uses an ingress, include the correct Host header for every request.
Exercise
What are the two main changes required when converting a V1 request to a V2 request?
Show answer
Change the URL from the V1 predict path to the V2 infer path, and change the JSON body from an instances-style structure to explicit inputs that include names, shapes, data types, and data.