KServe compatible RESTful API#
Introduction#
In addition with gRPC APIs OpenVINO™ model server also supports RESTful APIs which follows the documentation from KServe REST API. REST API is recommended when the primary goal is in reducing the number of client-side python dependencies and simpler application code.
This document covers the following API:
Server Live API#
Description
Get information about server liveness.
URL
GET http://${REST_URL}:${REST_PORT}/v2/health/live
Response format
The information about server liveness is provided in the response status code. If server is alive, status code is 200. Otherwise it’s 4xx. Response does not have any content in the body.
Usage Example
$ curl -i http://localhost:8000/v2/health/live
HTTP/1.1 200 OK
Content-Type: application/json
Date: Tue, 09 Aug 2022 09:20:24 GMT
Content-Length: 2
See also code samples for getting server liveness with KServe API on HTTP Server Live endpoint.
Server Ready API#
Description
Get information about server readiness.
URL
GET http://${REST_URL}:${REST_PORT}/v2/health/ready
Response format
The information about server readiness is provided in the response status code. If server is ready, status code is 200. Otherwise it’s 4xx. Response does not have any content in the body.
Usage Example
$ curl -i http://localhost:8000/v2/health/ready
HTTP/1.1 200 OK
Content-Type: application/json
Date: Tue, 09 Aug 2022 09:22:14 GMT
Content-Length: 2
See also code samples for getting server readiness with KServe API on HTTP Server Ready endpoint.
Server Metadata API#
Description
Get information about the server.
URL
GET http://${REST_URL}:${REST_PORT}/v2
Response format
If successful:
{
"name" : $string,
"version" : $string,
"extensions" : [ $string, ... ]
}
Else:
{
"error": $string
}
Usage Example
$ curl http://localhost:8000/v2
{"name":"OpenVINO Model Server","version":"2022.2.0.fd742507"}
For detailed description of the response contents see KServe API docs.
See also code samples for getting server metadata with KServe API on HTTP Server Metadata endpoint.
Model Ready API#
Description
Get information about model readiness.
URL
GET http://${REST_URL}:${REST_PORT}/v2/models/${MODEL_NAME}[/versions/${MODEL_VERSION}]/ready
Response format
The information about model readiness is provided in the response status code. If model is ready for inference, status code is 200. Otherwise it’s 4xx. Response does not have any content in the body.
Usage Example
$ curl -i http://localhost:8000/v2/models/resnet/ready
HTTP/1.1 200 OK
Content-Type: application/json
Date: Tue, 09 Aug 2022 09:25:31 GMT
Content-Length: 2
See also code samples for getting model readiness with KServe API on HTTP Model Ready endpoint.
Model Metadata API#
Description
Get information about the model.
URL
GET http://${REST_URL}:${REST_PORT}/v2/models/${MODEL_NAME}[/versions/${MODEL_VERSION}]
Note :Including ${MODEL_VERSION} is optional. If omitted the model metadata for the latest version is returned in the response. ???
Response format
If successful:
{
"name" : $string,
"versions" : [ $string, ... ] #optional,
"platform" : $string,
"inputs" : [ $metadata_tensor, ... ],
"outputs" : [ $metadata_tensor, ... ],
"rt_info" : { $model_info}
}
where:
$metadata_tensor =
{
"name" : $string,
"datatype" : $string,
"shape" : [ $number, ... ]
}
rt_info is an optional response returned for the models in IR format which got an auxiliary metadata added during the export commands. For example the following code can include info about classification model labels:
import openvino as ov
core = ov.Core()
model = core.read_model(model="model.xml")
model.set_rt_info(["cat", "dog"],["model_info","labels"])
ov.save_model(model,"new_model.xml")
Such deployed models will report:
{
"rt_info": {
"model_info": {
"labels": "cat dog"
}
}
}
Else:
{
"error": $string
}
Usage example
$ curl http://localhost:8000/v2/models/resnet
{"name":"resnet","versions":["1"],"platform":"OpenVINO","inputs":[{"name":"image","datatype":"FP32","shape":[1,224,224,3]}],"outputs":[{"name":"output","datatype":"FP32","shape":[1,1000]}]}
For detailed description of the response contents see KServe API docs.
See also code samples for running getting model metadata with KServe API on HTTP Model Metadata endpoint.
Model Configuration API#
This read-only Triton-compatible extension provides the tensor configuration used
by clients such as NVIDIA perf_analyzer. It is not part of the core KServe V2
API and does not expose OVMS plugin configuration or allow configuration changes.
URLs
GET http://${REST_URL}:8000/v2/models/resnet/config
GET http://${REST_URL}:8000/v2/models/resnet/versions/1/config
When the version is omitted, the same version selection as the Model Metadata API is used. Missing models, unavailable versions, and model loading errors use the same error handling as metadata requests.
Response Example
{
"name": "resnet",
"max_batch_size": 0,
"input": [
{"name": "image", "data_type": "TYPE_FP32", "dims": [1, 224, 224, 3]}
],
"output": [
{"name": "output", "data_type": "TYPE_FP32", "dims": [1, 1000]}
]
}
The dimensions are the full KServe tensor shapes, including any explicit batch
dimension. max_batch_size is always 0 because this configuration does not add
Triton’s implicit leading batch dimension; it does not mean the model cannot
accept an explicit batch dimension. Dynamic dimensions remain -1, and scalar
tensors have an empty dims array. Datatypes use Triton’s TYPE_ prefix, with
KServe BYTES represented as TYPE_STRING.
Usage Example
curl -f http://localhost:8000/v2/models/resnet/config
See the KServe benchmark demo for
perf_analyzer REST commands and verification results. This extension is available
over REST only; it does not implement the gRPC ModelConfig RPC.
Inference API#
Description
Endpoint for running inference with individual classic models or Mediapipe pipelines.
URL
POST http://${REST_URL}:${REST_PORT}/v2/models/${MODEL_NAME}[/versions/${MODEL_VERSION}]/infer
Standard JSON Input Format#
Request Body Format
{
"id" : $string #optional,
"parameters" : $parameters #optional,
"inputs" : [ $request_input, ... ],
"outputs" : [ $request_output, ... ] #optional
}
where:
$request_input =
{
"name" : $string,
"shape" : [ $number, ... ],
"datatype" : $string,
"parameters" : $parameters #optional,
"data" : $tensor_data
}
$request_output =
{
"name" : $string,
"parameters" : $parameters #optional,
}
For example, send a [1, 2] FP32 tensor as JSON with requests:
import requests
request_body = {
"inputs": [{
"name": "model_input",
"shape": [1, 2],
"datatype": "FP32",
"data": [[1.0, 2.0]],
}],
}
response = requests.post(
"http://localhost:8000/v2/models/my_model/infer",
json=request_body,
)
response.raise_for_status()
print(response.json())
Note: In
tensor_dataelements may be presented in their multi-dimensional representation, or as a flattened one-dimensional representation. Before inference execution tensor data is flattened, and only elements count intensor_datais validated.
Binary Data Extension#
The binary data extension sends tensor buffers after the JSON request instead of encoding their values in JSON. Set Inference-Header-Content-Length to the JSON length in bytes and Content-Length to the entire body length. Binary buffers follow the JSON immediately in input order; an input’s parameters.binary_data_size gives its buffer length in bytes.
Encoded images#
For encoded JPEG or PNG images, use BYTES and prefix each image with its four-byte little-endian length. OVMS decodes these inputs for compatible models.
Content-Type: application/octet-stream
Inference-Header-Content-Length: <xx>
Content-Length: <xx+9476>
{
"model_name" : "my_model",
"inputs" : [
{
"name" : "model_input",
"shape" : [ 1 ],
"datatype" : "BYTES"
}
]
}
<0x00250000 (9472 as four bytes little endian)><9472 bytes of data for model_input tensor>
Here is a REST client example using requests:
import json
import struct
import requests
with open("image.jpg", "rb") as image_file:
image = image_file.read()
binary_data = struct.pack("<I", len(image)) + image
request_header = json.dumps({
"inputs": [{
"name": "image",
"shape": [1],
"datatype": "BYTES",
"parameters": {"binary_data_size": len(binary_data)},
}],
}).encode("utf-8")
response = requests.post(
"http://localhost:8000/v2/models/resnet/infer",
data=request_header + binary_data,
headers={
"Content-Type": "application/octet-stream",
"Inference-Header-Content-Length": str(len(request_header)),
},
)
response.raise_for_status()
print(response.json())
requests sets the full Content-Length from the body. Inference-Header-Content-Length gives the JSON header length only. See the encoded image guide for model requirements and gRPC and REST client examples.
Raw Numeric Tensors#
Raw numeric tensors are different from encoded image files: the binary buffer contains the entire array in the specified numeric datatype and shape, with no per-element length prefixes or image decoding. The shape, datatype, and memory layout must match the model’s effective input. Model-configured preprocessing may still apply. The buffer size is the number of elements multiplied by the datatype size; for numeric inputs OVMS can calculate it when binary_data_size is omitted.
Content-Type: application/octet-stream
Inference-Header-Content-Length: <xx>
Content-Length: <xx+(3 x 1080000)>
{
"model_name" : "my_model",
"inputs" : [
{
"name" : "model_input",
"shape" : [ 3, 300, 300, 3 ],
"datatype" : "FP32"
},
]
}
<3240000 bytes of the whole data batch for model_input tensor>
For example, this sends a [1, 2] FP32 tensor to a model named my_model with input model_input using requests and numpy:
import json
import numpy as np
import requests
tensor = np.array([[1.0, 2.0]], dtype="<f4")
data = tensor.tobytes(order="C")
header = json.dumps({
"inputs": [{
"name": "model_input",
"shape": list(tensor.shape),
"datatype": "FP32",
"parameters": {"binary_data_size": len(data)},
}],
}).encode("utf-8")
response = requests.post(
"http://localhost:8000/v2/models/my_model/infer",
data=header + data,
headers={
"Content-Type": "application/octet-stream",
"Inference-Header-Content-Length": str(len(header)),
},
)
response.raise_for_status()
print(response.json())
Response Format
If successful:
{
"model_name" : $string,
"model_version" : $string #optional,
"id" : $string,
"parameters" : $parameters #optional,
"outputs" : [ $response_output, ... ]
}
where:
$response_output =
{
"name" : $string,
"shape" : [ $number, ... ],
"datatype" : $string,
"parameters" : $parameters #optional,
"data" : $tensor_data
}
Else:
{
"error": <error message string>
}
Outputs of response can be send in binary format using Binary Data extension. To force a output to be sent in binary format you need to use “binary_data” : true parameter in request JSON. For example:
{
"model_name" : "mymodel",
"inputs" : [...],
"outputs" : [
{
"name" : "output0",
"parameters" : {
"binary_data" : true
}
}
]
}
Assuming the output datatype is FP32 and shape is [ 2, 2 ] response to this request would be:
HTTP/1.1 200 OK
Content-Type: application/octet-stream
Inference-Header-Content-Length: <yy>
Content-Length: <yy+16>
{
"outputs" : [
{
"name" : "output0",
"shape" : [ 2, 2 ],
"datatype" : "FP32",
"parameters" : {
"binary_data_size" : 16
}
}
]
}
<16 bytes of data for output0 tensor>
For detailed description of request and response contents see KServe API docs.
Note: Sending data outside the JSON object using the binary data extension can reduce request size and processing overhead.
Note: Using //.. at the end of request URI results in truncated path, which might result in different response than expected.
See also code samples for running inference with KServe API on HTTP Inference endpoint.