Skip to main content

API deployment guide

This topic uses the Qwen model as an example to walk you through the full lifecycle of model deployment on Alibaba Cloud Model Studio by using API (HTTP) calls, including deploying, querying, inference, deletion, and permission troubleshooting.

This document applies only to the China (Beijing) region.

Prerequisites

1. Deploy a model

The following commands show how to create a dedicated service. Among them, the token-based billing example uses the fine-tuned custom model qwen3-8b-ft-202511132025-0260 to create a dedicated service qwen3-8b-ft-202511132025-0260; the model unit example uses a preset model. To obtain a custom model ID: Go to Model Studio console - Model fine-tuning, click Task Name -> Output -> click the model name in blue to enter the My Models page, where you can view the model ID in the model basic information area. Use the Model IDas the input for the model_name parameter to deploy the model by using the API.
  • Model unit
  • Billed by model token usage
  • dashscope CLI
  • After you run the deployment command, billing starts as soon as the service is successfully deployed, even if you do not use it. Before proceeding, we recommend you review the service billing rules.
  • Computing resources for the post-paid model unit plan are allocated on a first-come, first-served basis. If the purchase is unsuccessful, a full refund will be issued.
The model unit billing method charges you based on usage duration. This billing method is ideal for large-scale inference tasks after model finetuning, offering dedicated resources with flexible performance and cost adjustments. You can customize both throughput/concurrency and generation speed.
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 the following additional settings:

Configuration item

Configuration details

Service name

Custom name for the deployment service.

Select model

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

Model unit type

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

Model Units per Replica

The number of model units required per replica is jointly determined by the deployment template and model unit type, and cannot be modified. For example, qwen3-32b requires 16 model units per replica. Total Model Units = Deployed Replicas × Model Units per Replica, which determines how many resources the deployed service uses. Increasing the number of deployed replicas consumes more model units and delivers better model performance.

Deployment replica count

Set the initial number of deployment replicas, which affects the concurrency capacity of the service.

Deployment template

Select a deployment template (such as "single-node deployment"). Different templates correspond to different resource configuration schemes. Available only under the model unit billing mode.

Configure model inference mode

For some models deployed in Model Unit mode, you can configure the inference mode, maximum context length, and more.

  • Instruct - After deployment, the model performs inference in non-thinking mode.

  • Thinking - After deployment, the model performs inference in thinking mode.

Maximum context length

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

Service rate limiting

The Model Unit deployment mode of some models supports this setting. You can limit the RPM and TPM of model invocations.

For how to configure the above via API, see Create a deployment using the API.
After the command executes successfully, the following result is returned: (taking a 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"
    }
}
Among them, deployed_model is the unique ID of the dedicated service; use this deployed_model value as the identifier in the path of subsequent APIs such as query and deletion (not the name in the request parameters).

2. Query the service status

Use the following command to query the detailed information of a specified 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 the command executes successfully, the following result is returned:
{
    "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, the service deployment is complete.

3. Send inference requests

If this is your first time using the DashScope SDK, see Install the SDK.Make sure the workspace of your API Key is the same as the workspace where the model deployment resides.
When calling a deployed dedicated service, the model parameter should be set to the model code obtained after a successful model deployment; go to the dedicated deployment console (Beijing) to obtain it.
import os
import dashscope

# If the environment variable is not configured, replace the following line with your Model Studio 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",  # Please replace with the code returned after the model is successfully deployed
    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, refer to the corresponding documentation for adjustments.

Parameter Name

Recommended value (corresponding to the vLLM default)

temperature

Value range [0, 2); setting it to 1.0 is equivalent to the vLLM engine default.

top_p

Value range (0, 1.0]; setting it to 1.0 is equivalent to the vLLM engine default.

top_k

When the value is None or greater than 100, the top_k policy is not enabled and only top_p takes effect; setting it to 99 does not support full sampling, which is close to the vLLM default of 0 (full sampling).

presence_penalty

Value range [-2.0, 2.0]; setting it to 0 is equivalent to the vLLM engine default.

repetition_penalty (DashScope protocol)

Increasing this value reduces repetition in generation; 1.0 means no penalty; the value range is greater than 0, and setting it to 1.0 is equivalent to the vLLM engine default.

4. Delete the dedicated service

After you run the following deletion command, the model deployment service will immediately start going offline, and this cannot be undone. You will:
  1. No longer be able to call the model.
  2. Stop being billed for the deployment service.
You can delete dedicated services that are 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, calling the 2. Query service status API will no longer return 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, make sure your account has the Model Deployment-Actions permission on the permission management page of the workspace. If you cannot perform operations, contact your organization or IT administrator to add the required permissions or check the permission issues for you.
  2. If the error "Workspace xx does not have permission to deploy model xx" is reported 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 you are prompted about insufficient permissions, contact your organization or IT administrator to add the relevant permissions or perform the operation on your behalf.

API deployment

When deploying models via API, you need to 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 an insufficient-permission message appears, contact your organization or IT administrator to add the required permissions or perform the operations for you.
  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, 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 left-side navigation pane, click Permission Management and confirm that the user list includes the API Key's owner account (with type primary account). If you are prompted about insufficient permissions, contact your organization or IT administrator to add the relevant permissions or perform the operation on your behalf.

API reference

For detailed API calls, see API details and Complete deployment API reference.