Interacting with an online deployment via REST

You can submit predict requests to a version of online deployment via REST. Navigate to the details page of the online deployment you are interested in and select the version of the deployment you wish to interact with.

Copy the URL and the Bearer token printed in the two fields in the bottom of the Run an example section. You need both of these to issue RESTful requests.

In this specific example, we are interacting with a model of the Image Classification type, which accepts image inputs and return the probabilities for each of the classes in the model. We are using the desktop client Postman in this case but you can use any REST client you want. Enter the URL you copied from the page above and paste in the Bearer token under the Authorization tab in Postman. If you are not using Postman, you must manually add a HTTP header to your request with Authorization as the key and Bearer <your_token> as the value. Replace <your_token> with the token you copied. You must also add a Content-Type header with the value application/json.

The body of the request must follow the format required by the model. You can learn more about acceptable input formats on Google's documentation page explaining how to submit predict requests to Google Cloud ML Engine. In this case, the body includes the image we wish to run through the model formatted as a base 64-encoded string and wrapped inside of a dictionary formatted as JSON.

As can be seen in the screenshot, the service returns a meaningful response. It says that the model strongly believes the image to be of the class missing_cap (with a probability of 99.94%), which is indeed the case. See a reproduction of the output below.

{
    "predictions": [
        {
            "failed_cap---good---missing_cap": [
                0.0003469484217930585,
                0.00021559966262429953,
                0.9994373917579651
            ]
        }
    ]
}

This concludes the article on interacting with online deployments via REST.

Still need help? Contact Us Contact Us