Deploy a trained text model as an online API service.
Prerequisites
- Applicable regions: The regions where the Model Deployment API is available vary by deployment method—Model Unit (MU) and Dedicated Throughput (DTU) support China (Beijing). If the corresponding deployment method is not available in your region, complete model deployment operations in the Bailian console of that region.
- Enable account permissions: If you use an Alibaba Cloud sub-account (RAM user), you must grant the sub-account permissions for model invocation, training, and deployment.
- Configure environment variables: You have successfully obtained an API Key and configured it as an environment variable.
- Read the deployment documentation: We recommend that you first read Dedicated Deployment Overview and Create a Model Deployment Task via API to understand how to use Model Deployment and its basic steps.
Create a deployment
- China (Beijing)
- Singapore
POST https://dashscope.aliyuncs.com/api/v1/deploymentsThe request domain varies by region: usedashscope.aliyuncs.comfor the China (Beijing) region anddashscope-intl.aliyuncs.comfor the Singapore region. The workspace-specific domain ({WorkspaceId}.{region}.maas.aliyuncs.com) is available in all regions. For the complete regional domain information, see Regional access information.
For Windows CMD, replace$DASHSCOPE_API_KEYwith%DASHSCOPE_API_KEY%. For PowerShell, replace it with$env:DASHSCOPE_API_KEY
Request parameters
Headers
Parameter | Type | Required | Description |
|---|---|---|---|
Content-Type | String | Yes | Fixed value: |
Authorization | String | Yes | API key authentication, in the format |
Request Body
Request body parameters vary by deployment plan (plan). The complete request body parameters and deployment examples for each billing mode are as follows:- DTU dedicated compute billing
- Model unit billing
- Token-based billing
API requests for DTU deployments must use the workspace-scopedmaas.aliyuncs.comdomain of the region and workspace where the deployment resides (for example,ws-vxxx.cn-beijing.maas.aliyuncs.com) together with the API key of that workspace. Querysku_code,template_code, and the capacity range through the deployable models list API withplan=dtu. For the complete parameters and APIs such as scaling, rate limit modification, and model updates, see Model Deployment API Reference.
Parameter | Type | Required | Description |
|---|---|---|---|
model_name | String | Yes | Name of the model to deploy, corresponding to the Model ID in My Models. You can also obtain it from the output of the Create a tuning job API. |
plan | String | Yes | Deployment plan, which determines the billing method: |
display_name | String | Yes | Service display name, up to 50 characters (other deployment plans use |
suffix | String | No | Suffix of the deployment identifier, up to 24 characters. The generated full deployment identifier must not exceed 100 characters. Omitted means auto-generated. |
sku_code | String | Yes | Pre-paid SKU available for the current model. Query it through the deployable models list API with |
template_code | String | Yes | Deployment template that matches the model and SKU. Obtained from the same query as |
charge_type | String | Yes | Billing method. For DTU, always set to |
dtu_capacity | Object | Yes | DTU capacity to purchase. You must provide both |
dtu_capacity.input_tpm | Integer | Yes | Purchased input TPM (tokens/min). Non-negative integer, maximum 2147483647, and must be an integer multiple of the queried step. |
dtu_capacity.output_tpm | Integer | Yes | Purchased output TPM (tokens/min). Non-negative integer, maximum 2147483647, and must use the same multiple as the input TPM. |
pre_paid_info | Object | Yes | Pre-paid purchase and auto-renewal settings. Fields: |
Deployment troubleshooting and performance tuning
max-num-seqs parameter is not configurable
Under the two billing methods of Bailian Model Deployment—Throughput Reservation (a separate product; see its API documentation) and By Model Unit—throughput, concurrency, and generation speed are all preset by the platform. Directly adjusting inference engine parameters inside vLLM such as max-num-seqs is not supported, and this parameter does not exist in the request parameters of this API.
Under the model unit billing plan, you can indirectly control throughput by selecting the model unit type (corresponding to the request parameter template_id) and adjusting the number of deployment replicas (corresponding to the request parameter capacity).
Deployment template and resource isolation
Currently, the deployment template only supports single-machine deployment (Single-machine deployment - Enhanced general inference) and does not support multi-GPU instance isolation. For resource isolation, use the model unit billing plan, which provides dedicated computing resources for your workload.
Throttling error handling
When concurrent requests exceed the throttling threshold, the API returns HTTP 429 with error code Throttling.RateQuota and error message Requests rate limit exceeded, please try again later. You can handle this as follows:
- Throughput Reservation (a separate product; see its API documentation): Adjust
input_tpmandoutput_tpminptu_capacity(corresponding to Input kTPM and Output kTPM in the console), or reduce the request frequency. Under this method, the overflow policy can be auto overflow (switch to pay-as-you-go) or reserved capacity only (requests exceeding the capacity directly return429). - By Model Unit: Adjust
rpm_limitandtpm_limit, or reduce the request frequency.
Context length tuning
Under the model unit billing plan, you can configure the maximum context length via the request parameter max_context_length, with a value range of 1 to 262144 (the actual upper limit depends on the capabilities of the deployed model). This parameter limits the context size per request, thereby limiting the memory usage per request and reducing the risk of OOM errors.
When processing tasks with a large number of images, set this parameter based on the image dimensions and the number of images per request.
Response parameters
Parameter | Type | Description |
|---|---|---|
request_id | String | Unique identifier of the request. |
output | Object | Task details. |
output.deployed_model | String | Unique identifier of the deployed model. Used to query the deployment status and invoke the model. |
output.name | String | Display name of the deployment. |
output.model_name | String | Model identifier name. |
output.base_model | String | Base model used. |
output.status | String | Deployment status: |
output.workspace_id | String | ID of the workspace to which the API key belongs. See Obtain the workspace ID. |
output.charge_type | String | Billing method: |
output.creator | String | Alibaba Cloud account ID of the creator. |
output.modifier | String | Alibaba Cloud account ID of the user who last modified the deployment. |
output.plan | String | Deployment mode. |
output.gmt_create | String | Time when the deployment task was created. |
output.gmt_modified | String | Time when the deployment task was last updated. |
Returned only for model unit (mu) deployments | ||
output.base_capacity | Number | Minimum number of resource units required to run the base model. |
output.ready_capacity | Number | Number of resource units that are ready and can immediately process requests. |
output.capacity | Number | Number of resource units used by the deployment. |
output.model_unit_spec | String | Model unit spec. |
output.enable_thinking | Boolean | Whether thinking mode is enabled. |
output.max_context_length | Number | Maximum context length limit. |
output.rpm_limit | Number | Requests per Minute. |
output.tpm_limit | Number | Token usage per minute. |
Only returned by the preset throughput (ptu_v2) deployment method | ||
output.ptu_capacity | Object | Preset throughput configuration, including |
Only returned by the DTU (dtu) deployment method | ||
output.dtu_capacity | Object | The purchased input/output TPM capacity, including |
output.pre_paid_info | Object | Upfront and auto-renewal information. |
For the complete DTU response field descriptions, see Model Deployment API Reference | ||
Returned when the call fails | ||
code | String | Error code. Returned when the call fails. |
message | String | Error details description. Returned when the call fails. |
- Success response example
- Error response example
output.deployed_model (unique identifier of the deployed model) and output.status (deployment status).