All Products
Search
Document Center

VPC Calling Method

Last Updated: Jun 01, 2020

Prerequisites

The server that is used to call an online model service and the online model service must be in the same region. For example, if the online model service is deployed in the China (Shanghai) region, then the service call must be initiated from the same region.

Benefits

  • Avoids public network overheads
  • Saves network traffic costs

Call methods

  • You can send HTTP requests to call an online model service. The following table shows the regions that support online model deployment and the corresponding domain names. You can use a domain name and model name to concatenate a service endpoint for service calls initiated from VPC networks as follows:

url = ‘pai-eas-vpc.cn-shanghai.aliyuncs.com’ + ‘/api/predict/‘ + model_name

Region Domain name
China (Beijing) pai-eas-vpc.cn-beijing.aliyuncs.com
China (Shanghai) pai-eas-vpc.cn-shanghai.aliyuncs.com

An HTTP request sent to the service contains the model_name, request_data, and authorization variables.

Sample request:

  1. import requests
  2. # The China (Shanghai) region is specified in this example
  3. url = 'pai-eas-vpc.cn-shanghai.aliyuncs.com' + '/api/predict/' + model_name
  4. headers = {"Authorization": authorization}
  5. resp = requests.post(url, data=data, headers=headers)
  6. if resp.status_code ! = 200:
  7. print resp.content
  8. else:
  9. response = predict_pb2.PredictResponse()
  10. response.ParseFromString(content)
  11. print(response)