<commit_before># RESTful API

In addition to
[gRPC APIs](https://github.com/tensorflow/serving/blob/master/tensorflow_serving/apis/prediction_service.proto)
TensorFlow ModelServer also supports RESTful APIs. This page describes these API
endpoints and an end-to-end [example](#example) on usage.

The request and response is a JSON object. The composition of this object
depends on the request type or verb. See the API specific sections below for
details.

In case of error, all APIs will return a JSON object in the response body with
`error` as key and the error message as the value:

```javascript
{
  "error": <error message string>
}
```

## Model status API

This API closely follows the
[`ModelService.GetModelStatus`](https://github.com/tensorflow/serving/blob/5369880e9143aa00d586ee536c12b04e945a977c/tensorflow_serving/apis/model_service.proto#L17)
gRPC API. It returns the status of a model in the ModelServer.

### URL

```
GET http://host:port/v1/models/${MODEL_NAME}[/versions/${VERSION}|/labels/${LABEL}]
```

Including `/versions/${VERSION}` or `/labels/${LABEL}` is optional. If omitted
status for all versions is returned in the response.

### Response format

If successful, returns a JSON representation of
[`GetModelStatusResponse`](https://github.com/tensorflow/serving/blob/5369880e9143aa00d586ee536c12b04e945a977c/tensorflow_serving/apis/get_model_status.proto#L64)
protobuf.

## Model Metadata API

This API closely follows the
[`PredictionService.GetModelMetadata`](https://github.com/tensorflow/serving/blob/5369880e9143aa00d586ee536c12b04e945a977c/tensorflow_serving/apis/prediction_service.proto#L29)
gRPC API. It returns the metadata of a model in the ModelServer.

### URL

```
GET http://host:port/v1/models/${MODEL_NAME}[/versions/${VERSION}|/labels/${LABEL}]/metadata
```

Including `/versions/${VERSION}` or `/labels/${LABEL}` is optional. If omitted
the model metadata for the latest version is returned in the response.

### Response format

If successful, returns a JSON representation of
[`GetModelMetadataResponse`](https://github.com/tensorflow/serving/blob/5369880e9143aa00d586ee536c12b04e945a977c/tensorflow_serving/apis/get_model_metadata.proto#L23)
protobuf.

## Classify and Regress API

This API closely follows the `Classify` and `Regress` methods of
[`PredictionService`](https://github.com/tensorflow/serving/blob/5369880e9143aa00d586ee536c12b04e945a977c/tensorflow_serving/apis/prediction_service.proto#L15)
gRPC API.

### URL

```
POST http://host:port/v1/models/${MODEL_NAME}[/versions/${VERSION}|/labels/${LABEL}]:(classify|regress)
```

Including `/versions/${VERSION}` or `/labels/${LABEL}` is optional. If omitted
the latest version is used.

### Request format

The request body for the `classify` and `regress` APIs must be a JSON object
formatted as follows:

```javascript
{
  // Optional: serving signature to use.
  // If unspecifed default serving signature is used.
  "signature_name": <string>,

  // Optional: Common context shared by all examples.
  // Features that appear here MUST NOT appear in examples (below).
  "context": {
    "<feature_name3>": <value>|<list>
    "<feature_name4>": <value>|<list>
  },

  // List of Example objects
  "examples": [
    {
      // Example 1
      "<feature_name1>": <value>|<list>,
      "<feature_name2>": <value>|<list>,
      ...
    },
    {
      // Example 2
      "<feature_name1>": <value>|<list>,
      "<feature_name2>": <value>|<list>,
      ...
    }
    ...
  ]
}
```

`<value>` is a JSON number (whole or decimal) or string, and `<list>` is a list
of such values. See [Encoding binary values](#encoding-binary-values) section
below for details on how to represent a binary (stream of bytes) value. This
format is similar to gRPC's `ClassificationRequest` and `RegressionRequest`
protos. Both versions accept list of
[`Example`](https://github.com/tensorflow/tensorflow/blob/92e6c3e4f5c1cabfda1e61547a6a1b268ef95fa5/tensorflow/core/example/example.proto#L13)
objects.

### Response format

A `classify` request returns a JSON object in the response body, formatted as
follows:

```javascript
{
  "result": [
    // List of class label/score pairs for first Example (in request)
    [ [<label1>, <score1>], [<label2>, <score2>], ... ],

    // List of class label/score pairs for next Example (in request)
    [ [<label1>, <score1>], [<label2>, <score2>], ... ],
    ...<commit_msg>Clarifying object values in REST requests to include B64 encoding and similar key:value pair objects.<commit_after># RESTful API

In addition to
[gRPC APIs](https://github.com/tensorflow/serving/blob/master/tensorflow_serving/apis/prediction_service.proto)
TensorFlow ModelServer also supports RESTful APIs. This page describes these API
endpoints and an end-to-end [example](#example) on usage.

The request and response is a JSON object. The composition of this object
depends on the request type or verb. See the API specific sections below for
details.

In case of error, all APIs will return a JSON object in the response body with
`error` as key and the error message as the value:

```javascript
{
  "error": <error message string>
}
```

## Model status API

This API closely follows the
[`ModelService.GetModelStatus`](https://github.com/tensorflow/serving/blob/5369880e9143aa00d586ee536c12b04e945a977c/tensorflow_serving/apis/model_service.proto#L17)
gRPC API. It returns the status of a model in the ModelServer.

### URL

```
GET http://host:port/v1/models/${MODEL_NAME}[/versions/${VERSION}|/labels/${LABEL}]
```

Including `/versions/${VERSION}` or `/labels/${LABEL}` is optional. If omitted
status for all versions is returned in the response.

### Response format

If successful, returns a JSON representation of
[`GetModelStatusResponse`](https://github.com/tensorflow/serving/blob/5369880e9143aa00d586ee536c12b04e945a977c/tensorflow_serving/apis/get_model_status.proto#L64)
protobuf.

## Model Metadata API

This API closely follows the
[`PredictionService.GetModelMetadata`](https://github.com/tensorflow/serving/blob/5369880e9143aa00d586ee536c12b04e945a977c/tensorflow_serving/apis/prediction_service.proto#L29)
gRPC API. It returns the metadata of a model in the ModelServer.

### URL

```
GET http://host:port/v1/models/${MODEL_NAME}[/versions/${VERSION}|/labels/${LABEL}]/metadata
```

Including `/versions/${VERSION}` or `/labels/${LABEL}` is optional. If omitted
the model metadata for the latest version is returned in the response.

### Response format

If successful, returns a JSON representation of
[`GetModelMetadataResponse`](https://github.com/tensorflow/serving/blob/5369880e9143aa00d586ee536c12b04e945a977c/tensorflow_serving/apis/get_model_metadata.proto#L23)
protobuf.

## Classify and Regress API

This API closely follows the `Classify` and `Regress` methods of
[`PredictionService`](https://github.com/tensorflow/serving/blob/5369880e9143aa00d586ee536c12b04e945a977c/tensorflow_serving/apis/prediction_service.proto#L15)
gRPC API.

### URL

```
POST http://host:port/v1/models/${MODEL_NAME}[/versions/${VERSION}|/labels/${LABEL}]:(classify|regress)
```

Including `/versions/${VERSION}` or `/labels/${LABEL}` is optional. If omitted
the latest version is used.

### Request format

The request body for the `classify` and `regress` APIs must be a JSON object
formatted as follows:

```javascript
{
  // Optional: serving signature to use.
  // If unspecifed default serving signature is used.
  "signature_name": <string>,

  // Optional: Common context shared by all examples.
  // Features that appear here MUST NOT appear in examples (below).
  "context": {
    "<feature_name3>": <value>|<list>
    "<feature_name4>": <value>|<list>
  },

  // List of Example objects
  "examples": [
    {
      // Example 1
      "<feature_name1>": <value>|<list>,
      "<feature_name2>": <value>|<list>,
      ...
    },
    {
      // Example 2
      "<feature_name1>": <value>|<list>,
      "<feature_name2>": <value>|<list>,
      ...
    }
    ...
  ]
}
```

`<value>` is a JSON number (whole or decimal), JSON string, or a JSON object
that represents binary data (see the [Encoding binary values](#encoding-binary-values)
section below for details). `<list>` is a list of such values. This
format is similar to gRPC's `ClassificationRequest` and `RegressionRequest`
protos. Both versions accept list of
[`Example`](https://github.com/tensorflow/tensorflow/blob/92e6c3e4f5c1cabfda1e61547a6a1b268ef95fa5/tensorflow/core/example/example.proto#L13)
objects.

### Response format

A `classify` request returns a JSON object in the response body, formatted as
follows:

```javascript
{
  "result": [
    // List of class label/score pairs for first Example (in request)
    [ [<label1>, <score1>], [<label2>, <score2>], ... ],

    // List of class label/score pairs for next Example (in request)
    [ [<label1>, <score1>], [<label2>, <score2>], ... ],
    ...
{'fraction_non_alphanumeric': 0.12936945037653141, 'fraction_numerical': 0.04450938518601776, 'mean_word_length': 4.59622641509434, 'pattern_counts': {'":': 22, '<': 63, '<?xml version=': 0, '>': 63, 'https://': 14, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4922143', 'n_tokens_mistral': 3062, 'n_tokens_neox': 2828, 'n_words': 806}