Access a model deployed on Platform for AI (PAI) through AI Gateway.
Prerequisites
-
A model is deployed on PAI. Deploy a model with one click.
-
An AI gateway instance is created. Create an AI gateway instance.
When using a private endpoint, the AI gateway instance and PAI-deployed model must be in the same VPC.
Procedure
Step 1: Create an AI service
Log on to the AI Gateway console.
In the navigation pane on the left, choose Instance. In the top menu bar, select a region.
On the Instance page, click the target instance ID.
In the navigation pane on the left, choose Service, then click the Services tab.
-
Click Create Service. In the Create Service panel, configure the following parameters:
Parameter
Description
Service Source
Select AI service.
Service Name
Enter a service name, such as pai.
Large Model Supplier
Select the model provider. In this example, select PAI-EAS. If you haven't deployed a model with PAI-EAS, complete Deploy a model with one click first.
Workspace
The PAI workspace, such as
pai_xqrj0u0t******.EAS Service
Select the PAI-deployed model, such as
Qwen3-32B.ConnectionType
Select the network type (public or private). This example uses private network.
API key
Automatically retrieved by the AI gateway for the PAI-deployed model.
NoteThis key authenticates communication between the AI gateway and PAI-EAS.
HealthyCheck
Enable or disable health checks for the service.
Step 2: Create a Model API
Log on to the AI Gateway console.
In the navigation pane on the left, choose Instance. In the top menu bar, select a region.
On the Instance page, click the target instance ID.
In the navigation pane on the left, choose Model API, then click Create Model API.
-
In the Create Model API panel, configure the following:
-
Base Path: Specify the base path for the API.
-
Services: Select the AI service that you created in Step 1: Create an AI service.
-
-
Click OK to create the Model API.
Step 3: Debug the Model API
-
In the Actions column of the target Model API, click Debug.
-
In the Debug panel, under Select Model, select your PAI-deployed model and interact with it on the Model Returned tab.
ImportantOn the Model Response tab, the
/v1/chat/completionsAPI is used by default. To use other APIs, select cURL command or Raw Output to debug with curl or an SDK. -
[Example] Call the
completionsendpoint with a cURL command:-
On the cURL command tab, copy the code sample provided by the AI gateway.
-
Replace the
urlin the code sample with/v1/completions. -
Modify the
data(body)section to match the/v1/completionsformat:
curl --location 'http://env-cxxx-cn-wulanchabu.alicloudapi.com/v1/completions' \ --header 'Content-Type: application/json' \ --data '{"model": "DeepSeek-R1-Distill-Qwen-1.5B","prompt": "can you help me with"}' {"id":"cmpl-d057e88b-ebb0-456f-89d6-79d431ed0ed9","object":"text_completion","created":1739929451,"model":"DeepSeek-R1-Distill-Qwen-1.5B","choices":[{"index":0,"text":" this math problem?\n\nI think about the idea of moving the focus point of the","logprobs":null,"finish_reason":"length","stop_reason":null,"prompt_logprobs":null}],"usage":{"prompt_tokens":6,"total_tokens":22,"completion_tokens":16,"prompt_tokens_details":null}} -