Skip to main content

API deployment guide

This document uses Qwen model deployment as an example to demonstrate the full workflow of deploying models in Alibaba Cloud Model Studio via API (HTTP), including deployment, status query, inference, deletion, and permission troubleshooting.

This topic is applicable only to the China (Beijing) region.

Prerequisites

1. Deploy a model

The following commands show how to create a dedicated service. Among them, the example billed by Token uses the fine-tuned custom model qwen3-8b-ft-202511132025-0260 to create a dedicated service qwen3-8b-ft-202511132025-0260; the example billed by model unit uses a preset model. To obtain a custom model ID, go to the Model Studio console – Model fine-tuning, click the Task Name you want to deploy → Outputs → click the blue model name to open the My Models page. The model ID appears in the basic model information section. Use the model ID as the value for the model_name parameter to deploy the model via API.
  • Billing by model unit usage duration
  • Billing by token usage
  • dashscope CLI
  • After running the deployment command below, billing starts immediately upon successful deployment—even if you have not yet called the model. Confirm the billing rules before deploying.
  • Model unit pay-as-you-go computing resources are allocated on a first-come, first-served basis. If purchase fails, you receive a full refund.
Select the model unit billing method. This mode charges based on model unit usage duration and suits large-scale inference workloads after model fine-tuning. Resources are dedicated, and performance and cost are flexible. Throughput/concurrency and generation speed are customizable.
curl "https://dashscope.aliyuncs.com/api/v1/deployments" \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
    "name": "my_qwen_plus",
    "model_name": "qwen-plus-2025-12-01",
    "plan": "mu",
    "deploy_spec": "MU1",
    "enable_thinking": true,
    "capacity": 4,
    "max_context_length": 10000,
    "rpm_limit": 500,
    "tpm_limit": 1000
}'
The model unit deployment mode supports additional settings:

Configuration item

Configuration details

Service name

A custom name for the deployment service.

Model

Select the model to deploy, including platform preset models and fine-tuned models.

Model unit type

Select the deployment specification. Different specifications correspond to different computing power and performance.

Model units per replica

The number of model units required for a single replica, determined jointly by the deployment template and the model unit type, and cannot be modified. For example, qwen3-32b requires 16 model units per replica. Total model units = replica count × model units per replica, which determines how many resources the deployment service uses. Increasing the replica count uses more model units and delivers better model performance.

Replica count

Set the initial number of deployment replicas, which affects the concurrent processing capability of the service.

Deployment template

Select a deployment template (for example, "single-node deployment"). Different templates correspond to different resource configuration schemes. Available only in the model unit billing mode.

Model inference mode

For some models, when deployed in model unit mode, you can configure the inference mode, maximum context, and more.

  • Instruct - The model performs inference in non-thinking mode after deployment.

  • Thinking - The model performs inference in thinking mode after deployment.

Maximum context

The model unit deployment mode of some models supports this setting. The maximum context length depends on the model type.

Service throttling

The model unit deployment mode of some models supports this setting, which can limit the RPM and TPM of model calls.

For details on setting these options via API, see Create a model deployment task using the API.
After successful execution, the command returns the following result (using model unit deployment as an example):
{
    "request_id": "83b173ab-2b2f-41aa-8c57-b173e8be934e",
    "output":
    {
        "deployed_model": "qwen3-8b-ft-202511132025-0260",
        "gmt_create": "2025-11-20T20:06:46.405",
        "gmt_modified": "2025-11-20T20:06:46.405",
        "status": "PENDING",
        "model_name": "qwen3-8b-ft-202511132025-0260",
        "base_model": "qwen3-8b",
        "workspace_id": "llm-8v*****",
        "charge_type": "post_paid",
        "creator": "16542*****",
        "modifier": "16542*****",
        "plan": "mu",
        "model_unit_spec": "MU1"
    }
}
The deployed_model field is the unique ID of the dedicated service. In subsequent query and delete API paths, use this deployed_model value (not the name request parameter).

2. Check service status

Use the following command to query details for a specific dedicated service:
curl "https://dashscope.aliyuncs.com/api/v1/deployments/qwen3-8b-ft-202511132025-0260" \
    --header "Authorization: Bearer $DASHSCOPE_API_KEY" \
    --header 'Content-Type: application/json'
After successful execution, the command returns the following result:
{
    "request_id": "ca36952d-9136-426e-ab08-68a97ad72719",
    "output":
    {
        "deployed_model": "qwen3-8b-ft-202511132025-0260",
        "gmt_create": "2025-11-20T20:32:08",
        "gmt_modified": "2025-11-20T20:42:25",
        "status": "RUNNING",
        "model_name": "qwen3-8b-ft-202511132025-0260",
        "base_model": "qwen3-8b",
        "base_capacity": 2,
        "capacity": 2,
        "ready_capacity": 2,
        "workspace_id": "llm-8v53etv3hwb8orx1",
        "charge_type": "post_paid",
        "creator": "1654290265984853",
        "modifier": "1654290265984853",
        "plan": "mu",
        "model_unit_spec": "MU1"
    }
}
When the service status is RUNNING, deployment is complete.

3. Make an inference request

If you are using the DashScope SDK for the first time, see Install the SDK.Ensure the workspace of your API key matches the workspace where the model is deployed.
When calling a successfully deployed model, the value of model should be the model code generated after successful deployment. Go to the Dedicated Deployment console (Beijing) to obtain it.
import os
import dashscope

# 若没有配置环境变量,请用百炼API Key将下一行替换为:api_key="sk-xxx",
client = dashscope.Client(api_key=os.getenv("DASHSCOPE_API_KEY"))

messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "你是谁?"},
]
response = client.chat.completions.create(
    model="qwen3-14b-xxx-xxx",  # 请替换为模型部署成功后的code
    messages=messages,
    enable_thinking=False,
)
print(response)

Inference parameter alignment

The default parameter values of the Model Studio inference engine may differ from those of local inference frameworks. To align with vLLM defaults, refer to the table below when setting parameters; if you use other frameworks such as SGLang, see the corresponding documentation for adjustments.

Parameter name

Recommended value (matches vLLM defaults)

temperature

Range: [0, 2). Set to 1.0 to match vLLM's default.

top_p

Range: (0, 1.0]. Set to 1.0 to match vLLM's default.

top_k

Set to None or a value greater than 100 to disable top_k sampling (only top_p applies). Setting to 99 approximates vLLM's default value of 0 (full sampling).

presence_penalty

Range: [-2.0, 2.0]. Set to 0 to match vLLM's default.

repetition_penalty (DashScope protocol)

Increasing repetition_penalty reduces repetition in generated text. A value of 1.0 means no penalty. Range: greater than 0. Set to 1.0 to match vLLM's default.

4. Delete a dedicated service

After you run the deletion command, the model deployment service will immediately start to go offline, and this process is irreversible. You will:
  1. Be unable to call the model.
  2. No longer be billed for the deployment service.
You can delete a dedicated service that is no longer in use with the following command:
curl --request DELETE 'https://dashscope.aliyuncs.com/api/v1/deployments/qwen3-8b-ft-202511132025-0260' \
    --header "Authorization: Bearer $DASHSCOPE_API_KEY" \
    --header 'Content-Type: application/json'
After the command runs successfully, the following result is returned:
{
    "request_id": "8f726017-6042-420e-a465-0d366a3aba59",
    "output":
    {
        "deployed_model": "qwen3-8b-ft-202511132025-0260",
        "gmt_create": "2025-11-20T20:32:08",
        "gmt_modified": "2025-11-27T16:35:31.591",
        "status": "DELETING",
        "model_name": "qwen3-8b-ft-202511132025-0260",
        "base_model": "qwen3-8b",
        "base_capacity": 2,
        "capacity": 2,
        "ready_capacity": 2,
        "workspace_id": "llm-8v53etv3hwb8orx1",
        "charge_type": "post_paid",
        "creator": "1654290265984853",
        "modifier": "1654290265984853",
        "plan": "mu",
        "model_unit_spec": "MU1"
    }
}
After the deletion succeeds, the 2. Query service status API can no longer query the status of the deployed model.

Troubleshooting insufficient permissions

If you encounter insufficient permission errors during model deployment, there are two troubleshooting paths depending on the deployment method:

Console deployment

  1. If "Lack permissions for this module" is displayed, ensure that your account has the Model Deployment-Actions permission on the permission management page of the workspace. If you cannot perform operations properly, contact your organization or IT administrator to add the required permissions or check permission issues on your behalf.
  2. If the error "workspace xx does not have permission to deploy model xx" occurs during deployment, go to the Workspaces page in Bailian, and add the deployment permission for the corresponding model to the corresponding workspace.
    API call error: Workspace xxx does not have deployment privilege for model xxxx.
    PixPin_2025-11-27_15-03-57
    PixPin_2025-11-27_15-06-41
    If insufficient permissions are prompted, please contact your organization or IT administrator to add the relevant permissions or operate on your behalf.

API deployment

When deploying models through the API, make sure that:
  1. The Workspace that the API Key belongs to has permission to manage the model. Go to the Workspaces page in Bailian, and check the model deployment permission settings of the corresponding workspace.
    API call error: Workspace xxx does not have deployment privilege for model xxxx.
    In the Actions column of the corresponding workspace, click Authorization & Throttling Settings. Find the target model in the Models list, and check the authorization status in the Model Deployment column. If Unauthorized is displayed, click Modify in the Actions column to grant authorization. If a message indicating insufficient permissions appears, contact your organization or IT administrator to add the required permissions or perform operations on your behalf.
  2. The Owner Account of the API Key has operation permissions in the Workspace it belongs to. Go to the Bailian console, click the workspace in the lower-left corner to switch to the corresponding workspace, and then clickimageCheck the model deployment permission settings of the corresponding workspace.
    API call error: Workspace access denied.
    In the navigation pane on the left, click Permission Management and confirm that the user list includes the API key’s associated account (type: Alibaba Cloud account). If insufficient permissions are prompted, please contact your organization or IT administrator to add the relevant permissions or operate on your behalf.

API reference

For detailed API usage, see API details and the Model Deployment API Reference.