

# Pre-check endpoint request and response for tabular data
<a name="clarify-processing-job-data-format-tabular-precheck"></a>

We recommend that you deploy your model to a SageMaker AI real-time inference endpoint, and send requests to the endpoint. Manually examine the requests and responses to make sure that both are compliant with the requirements in the [Endpoint requests for tabular data](clarify-processing-job-data-format-tabular-request.md) section and the [Endpoint response for tabular data](clarify-processing-job-data-format-tabular-response.md) section. If your model container supports batch requests, you can start with a single record request, and then try two or more records.

The following commands show how to request a response using the AWS CLI. The AWS CLI is pre-installed in SageMaker Studio and SageMaker Notebook instances. To install the AWS CLI, follow this [installation guide](https://aws.amazon.com/cli/).

```
aws sagemaker-runtime invoke-endpoint \
  --endpoint-name $ENDPOINT_NAME \
  --content-type $CONTENT_TYPE \
  --accept $ACCEPT_TYPE \
  --body $REQUEST_DATA \
  $CLI_BINARY_FORMAT \
  /dev/stderr 1>/dev/null
```

The parameters are defined, as follows.
+ `$ENDPOINT NAME` – The name of the endpoint.
+ `$CONTENT_TYPE` – The MIME type of the request (model container input).
+ `$ACCEPT_TYPE` – The MIME type of the response (model container output).
+ `$REQUEST_DATA` – The requested payload string.
+ `$CLI_BINARY_FORMAT` – The format of the command line interface (CLI) parameter. For AWS CLI v1, this parameter should remain blank. For v2, this parameter should be set to `--cli-binary-format raw-in-base64-out`.

**Note**  
AWS CLI v2 passes binary parameters as base64-encoded strings [by default](https://docs.aws.amazon.com/cli/latest/userguide/cliv2-migration.html#cliv2-migration-binaryparam).

# AWS CLI v1 examples
<a name="clarify-processing-job-data-format-tabular-precheck-cli-v1-examples"></a>

The example in the preceding section was for AWS CLI v2. The following request and response examples to and from the endpoint use AWS CLI v1.

## Endpoint request and response in CSV format
<a name="clarify-processing-job-data-format-tabular-precheck-csv"></a>

In the following code example, the request consists of a single record and the response is its probability value.

```
aws sagemaker-runtime invoke-endpoint \
  --endpoint-name test-endpoint-sagemaker-xgboost-model \
  --content-type text/csv \
  --accept text/csv \
  --body '1,2,3,4' \
  /dev/stderr 1>/dev/null
```

From the previous code example, the response output follows.

```
0.6
```

In the following code example, the request consists of two records, and the response includes their probabilities, which are separated by a comma.

```
aws sagemaker-runtime invoke-endpoint \
  --endpoint-name test-endpoint-sagemaker-xgboost-model \
  --content-type text/csv \
  --accept text/csv \
  --body $'1,2,3,4\n5,6,7,8' \
  /dev/stderr 1>/dev/null
```

From the previous code example, the `$'content'` expression in the `--body` tells the command to interpret `'\n'` in the content as a line break. The response output follows.

```
0.6,0.3
```

In the following code example, the request consists of two records, the response includes their probabilities, separated with a line break.

```
aws sagemaker-runtime invoke-endpoint \
  --endpoint-name test-endpoint-csv-1 \
  --content-type text/csv \
  --accept text/csv \
  --body $'1,2,3,4\n5,6,7,8' \
  /dev/stderr 1>/dev/null
```

From the previous code example, the response output follows.

```
0.6
0.3
```

In the following code example, the request consists of a single record, and the response is probability values from a multiclass model containing three classes.

```
aws sagemaker-runtime invoke-endpoint \
  --endpoint-name test-endpoint-csv-1 \
  --content-type text/csv \
  --accept text/csv \
  --body '1,2,3,4' \
  /dev/stderr 1>/dev/null
```

From the previous code example, the response output follows.

```
0.1,0.6,0.3
```

In the following code example, the request consists of two records, and the response includes their probability values from a multiclass model containing three classes.

```
aws sagemaker-runtime invoke-endpoint \
  --endpoint-name test-endpoint-csv-1 \
  --content-type text/csv \
  --accept text/csv \
  --body $'1,2,3,4\n5,6,7,8' \
  /dev/stderr 1>/dev/null
```

From the previous code example, the response output follows.

```
0.1,0.6,0.3
0.2,0.5,0.3
```

In the following code example, the request consists of two records, and the response includes predicted label and probability.

```
aws sagemaker-runtime invoke-endpoint \
  --endpoint-name test-endpoint-csv-2 \
  --content-type text/csv \
  --accept text/csv \
  --body $'1,2,3,4\n5,6,7,8' \
  /dev/stderr 1>/dev/null
```

From the previous code example, the response output follows.

```
1,0.6
0,0.3
```

In the following code example, the request consists of two records and the response includes label headers and probabilities.

```
aws sagemaker-runtime invoke-endpoint \
  --endpoint-name test-endpoint-csv-3 \
  --content-type text/csv \
  --accept text/csv \
  --body $'1,2,3,4\n5,6,7,8' \
  /dev/stderr 1>/dev/null
```

From the previous code example, the response output follows.

```
"['cat','dog','fish']","[0.1,0.6,0.3]"
"['cat','dog','fish']","[0.2,0.5,0.3]"
```

## Endpoint request and response in JSON Lines format
<a name="clarify-processing-job-data-format-tabular-precheck-jsonlines"></a>

In the following code example, the request consists of a single record and the response is its probability value.

```
aws sagemaker-runtime invoke-endpoint \
  --endpoint-name test-endpoint-jsonlines \
  --content-type application/jsonlines \
  --accept application/jsonlines \
  --body '{"features":["This is a good product",5]}' \
  /dev/stderr 1>/dev/null
```

From the previous code example, the response output follows.

```
{"score":0.6}
```

In the following code example, the request contains two records, and the response includes predicted label and probability.

```
aws sagemaker-runtime invoke-endpoint \
  --endpoint-name test-endpoint-jsonlines-2 \
  --content-type application/jsonlines \
  --accept application/jsonlines \
  --body $'{"features":[1,2,3,4]}\n{"features":[5,6,7,8]}' \
  /dev/stderr 1>/dev/null
```

From the previous code example, the response output follows.

```
{"predicted_label":1,"probability":0.6}
{"predicted_label":0,"probability":0.3}
```

In the following code example, the request contains two records, and the response includes label headers and probabilities.

```
aws sagemaker-runtime invoke-endpoint \
  --endpoint-name test-endpoint-jsonlines-3 \
  --content-type application/jsonlines \
  --accept application/jsonlines \
  --body $'{"data":{"features":[1,2,3,4]}}\n{"data":{"features":[5,6,7,8]}}' \
  /dev/stderr 1>/dev/null
```

From the previous code example, the response output follows.

```
{"predicted_labels":["cat","dog","fish"],"probabilities":[0.1,0.6,0.3]}
{"predicted_labels":["cat","dog","fish"],"probabilities":[0.2,0.5,0.3]}
```

## Endpoint request and response in mixed formats
<a name="clarify-processing-job-data-format-tabular-precheck-diff"></a>

In the following code example, the request is in CSV format and the response is in JSON Lines format.

```
aws sagemaker-runtime invoke-endpoint \
  --endpoint-name test-endpoint-csv-in-jsonlines-out \
  --content-type text/csv \
  --accept application/jsonlines \
  --body $'1,2,3,4\n5,6,7,8' \
  /dev/stderr 1>/dev/null
```

From the previous code example, the response output follows.

```
{"probability":0.6}
{"probability":0.3}
```

In the following code example, the request is in JSON Lines format and the response is in CSV format.

```
aws sagemaker-runtime invoke-endpoint \
  --endpoint-name test-endpoint-jsonlines-in-csv-out \
  --content-type application/jsonlines \
  --accept text/csv \
  --body $'{"features":[1,2,3,4]}\n{"features":[5,6,7,8]}' \
  /dev/stderr 1>/dev/null
```

From the previous code example, the response output follows.

```
0.6
0.3
```

In the following code example, the request is in CSV format and the response is in JSON format.

```
aws sagemaker-runtime invoke-endpoint \
  --endpoint-name test-endpoint-csv-in-jsonlines-out \
  --content-type text/csv \
  --accept application/jsonlines \
  --body $'1,2,3,4\n5,6,7,8' \
  /dev/stderr 1>/dev/null
```

From the previous code example, the response output follows.

```
{"predictions":[{"label":1,"score":0.6},{"label":0,"score":0.3}]}
```