This topic describes how to call the API after you publish a service.
API description
POST /api/rec/feedRequest parameters
Parameter | Description | Type | Required | Example |
uid | The user ID. | string | Yes | "1000079" |
size | The number of recommended items to return. | integer | Yes | 10 |
scene_id | The ID of the recommendation scenario. This ID is used to distinguish requests for different scenarios. | String | Yes | home_feed |
features | The context features. | json map | No | {"age":20, "sex":"male"} |
complex_type_features | Context features of complex types. Set this parameter to request the model service with type information. | json array | No | [{"name":"age", "type":"int", "values":20}, {"name":"sex", "values":"male", "type":"string"}] |
item_id | The item ID to use for similarity-based recommendations. | string | No | 248791390 |
item_list | A custom list of items for retrieval. | json array | No | [{"item_id":"1111", "score":1},{"item_id":"222", "score":0.95}] |
debug | Used for debugging. When enabled, more logs are printed. For example, user and item details are printed in the console. If traffic throttling is enabled, the throttling process and changes in some calculated parameters are printed in the results. | bool | No | true |
request_id | The unique ID of the request. If this parameter is empty, the PAI-Rec engine automatically generates an ID. If you provide a value, that value is used as the request ID. | string | No | "c46c3f5e-6b32-4b5c-8aac-59a319941248" |
item_list
If you have a batch of retrieved data to pass through the API, assign it to `item_list`. The `item_list` parameter is an array where each element is a map object. Each element must contain an `item_id` field, which specifies the item ID. All other fields are optional. If an element includes a `score` field, its value is treated as the retrieval score. Other fields are treated as item properties.
complex_type_features
Context features of complex types must be passed as an array. Each element contains the following fields:
Name | Description | Example |
name | The name of the context feature. | age |
type | The type of the context feature. | int |
values | The value of the context feature. You can set values of different types, such as a single value, an array, or a map. | 20 |
Examples:
Pass a single value:
[{"name":"age", "type":"int", "values":20}, {"name":"sex", "values":"male", "type":"string"}]Pass an array:
[{"name":"list_features", "type":"list<int>", "values":[1,2,3]}]Pass a map:
[{"name":"map_features", "type":"map<int,int>", "values":{"1":10,"2":20,"3":30}}], or[{"name":"map_features", "type":"map<int,int>", "values":{"1":"10","2":"20","3":"30"}}],
The `type` field supports the following types: int, int64, float, double, string, list<int>, list<int64>, list<float>, list<double>, list<string>, map<int,int>, map<int,int64>, map<int,float>, map<int,double>, map<int,string>, map<string,int>, map<string,int64>, map<string,float>, map<string,double>, map<string,string>, map<int64,int>, map<int64,int64>, map<int64,float>, map<int64,double>, and map<int64,string>.
Note: You can use `complex_type_features` and `features` at the same time when you pass context data.
Response
Name | Description | Type | Example |
code | The business code returned by the API. | int | 200 |
msg | The business message. | string | success |
request_id | The unique ID of the request. | string | e332fe9c-7d99-45a8-a047-bc7ec33d07f6 |
size | The number of recommended items returned. | int | 10 |
experiment_id | The experiment ID. If A/B testing is not used, this field is empty. | string | ER2_L1#EG1#E2 |
items | A list of recommended items. | json array | [{"item_id":"248791390","score":0.9991594902203332,"retrieve_id":"mock_recall"}] |
The following table describes the fields for each element in the `items` list.
Name | Description | Type | Example |
item_id | The ID of the recommended item. | string | 3v5RE7417j7R |
retrieve_id | The ID of the retrieval source. | string | u2i_recall |
score | The recommendation score. | float | 0.45 |
Error codes
Error code | Description | msg |
200 | The API call is successful. | success |
299 | The number of returned items is insufficient. | items size not enough |
400 | Parameter error. The `msg` varies depending on the specific error. | uid not empty or unexpected end of JSON input |
500 | Server error. Returned as an HTTP status code. |
Configuration and call example
The following example shows how to use context retrieval. In this method, you pass a list of items to the API. The following configuration uses the `home_feed` scenario as an example:
{
"RunMode": "product",
"ListenConf": {
"HttpAddr": "",
"HttpPort": 8000
},
"SortNames": {
"default": ["ItemRankScore"]
},
"FilterNames": {
"default": ["UniqueFilter"]
},
"SceneConfs": {
"home_feed": {
"default": {
"RecallNames": ["ContextItemRecall"]
}
}
}
}The request body is as follows:
{
"uid":"13579",
"size":10,
"scene_id":"home_feed",
"item_list":[{"item_id":"1111", "score":1},{"item_id":"222", "score":0.95}]
}Call the API
Call the API using a curl command
To use a curl command to request the engine service from your local machine, first obtain the request URL and token for the service from the PAI-EAS console, as shown in the following figure:
On the service details page, click View Invocation Method to view the call information.

If you call the service from a local machine, use the public endpoint. The complete request URL is the public endpoint followed by `/api/rec/feed`.
curl -X 'POST' -v \
'http://12*****.vpc.hangzhou.pai-eas.aliyuncs.com/api/predict/test/api/rec/feed' \
-H 'Authorization:YmRjZThkM2Z*****************TU5Mw==' \
-d '{
"uid":"13579",
"size":10,
"scene_id":"home_feed",
"item_list":[{"item_id":"1111", "score":1},{"item_id":"222", "score":0.95}]
}'Response data
{
"code":200,
"msg":"success",
"request_id":"e332fe9c-7d99-45a8-a047-bc7ec33d07f6",
"size":10,
"experiment_id":"",
"items":[
{
"item_id":"1111",
"score":0.9991594902203332,
"retrieve_id":"ContextItemRecall"
}
]
}Call the API using the PAI-Rec diagnostic tool
If you deployed the service from the Service Management page in the PAI-Rec console, you can use the diagnostic tool to debug the recommendation results, as shown in the following figure:

Select the corresponding service and environment, and set the routing information to /api/rec/feed.
Item Table: If you have an item details table, you can select it here. The item details will be associated with the returned data.
Request Data: This section displays the request parameters from recent requests. You can also enter them manually.
As shown in the following figure, select and enter the relevant parameters, and then click Diagnose to obtain the recommendation results.
