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.

Prerequisites

1. Deploy the model

The following command uses the fine-tuned custom model qwen3-8b-ft-202511132025-0260 to create a dedicated service named qwen3-8b-ft-202511132025-0260. To obtain the custom model ID, go to the Model Studio console - model finetuning page. Click the Task Name of the model you want to deploy, click Outputs, and then click the blue model name. This opens the My Models page, where you can find the Model ID in the basic information section. Use the Model IDas the input for the model_name parameter to deploy the model by using the API.
  • Provisioned Throughput (PTU)
  • Model unit
  • 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.
The provisioned throughput billing method charges based on usage duration. This method is suitable for scenarios that require stable throughput, high concurrency, low latency, and predictable traffic. In this mode, the platform provisions both throughput/concurrency and generation speed, which you cannot adjust.
curl "https://dashscope-intl.aliyuncs.com/api/v1/deployments" \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
    "name": "my_qwen_flash",
    "model_name": "qwen-flash-2025-07-28",
    "plan": "ptu",
    "ptu_capacity": {
        "input_tpm": 10000,
	"output_tpm": 1000
    }
}'
On success, the command returns the following result (using a LoRA 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": "***"
    }
}
Where deployed_model is the unique ID of the dedicated service.

2. Query service status

Run the following command to query the details of a specific dedicated service:
curl "https://dashscope-intl.aliyuncs.com/api/v1/deployments/qwen3-8b-ft-202511132025-0260" \
    --header "Authorization: Bearer $DASHSCOPE_API_KEY" \
    --header 'Content-Type: application/json'
On success, 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, the service deployment is complete.

3. Make inference requests

If this is your first time using the DashScope SDK, see Install the SDK.Ensure the API Key's workspace matches the model's deployment workspace.
When calling a deployed dedicated service, the model parameter should be set to the model code returned after successful deployment. Obtain it from the Dedicated Deployment console.
import os
import dashscope

messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Who are you?"},
]
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
response = dashscope.Generation.call(
    # If you have not configured environment variables, replace the next line with your Bailian API Key: api_key="sk-xxx",
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    model="qwen3-max-xxx-xxx",  # Please replace with the code returned after the model is successfully deployed
    messages=messages,
    result_format="message",
    enable_thinking=False,
)
print(response)

Inference parameter alignment

The default values of the Model Studio inference engine parameters may differ from those of your local inference framework. To align with vLLM defaults, refer to the table below when calling the API; if you use SGLang or other frameworks, refer to the corresponding documentation.

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 the dedicated service

Running the delete command immediately takes the deployment service offline. This action is irreversible and has the following effects:
  1. You can no longer call the model.
  2. Billing for the service stops.
If you no longer need a dedicated service, you can delete it by using the following command:
curl --request DELETE 'https://dashscope-intl.aliyuncs.com/api/v1/deployments/qwen3-8b-ft-202511132025-0260' \
    --header "Authorization: Bearer $DASHSCOPE_API_KEY" \
    --header 'Content-Type: application/json'
On success, the command returns the following result:
{
    "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 deleting the service, you can no longer query its status using the method described in 2. Query service status.

Permission troubleshooting

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

Console deployment

  1. If "Missing permission for this module" is displayed, ensure that your account has the Model Deployment - Operation permission on the permission management page of the business space. If you cannot operate normally, contact your organization or IT administrator to add the relevant permissions or check the permission issues on your behalf.
  2. If the error "xx business space does not have permission to deploy the xx model" is reported during deployment, go to the Business Space Management page of Model Studio to add the deployment permission of the corresponding model for the corresponding business space.
    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, contact your organization or IT administrator to add the relevant permissions or operate on your behalf.

API deployment

When deploying a model by using an API, ensure the following:
  1. The API Key's Workspace must have permission to manage the model. Go to the Business Space Management page in Model Studio and check the model deployment permission settings for the corresponding workspace.
    API call error: Workspace xxx does not have deployment privilege for model xxxx.
    In the Actions column for the corresponding workspace, click Model Permission and Flow Control Settings. In the Model List, find the target model and check the authorization status in the Model Deployment column. If it shows Not Authorized, click Edit in the Actions column to grant permission. 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.
  2. The Owner Account that owns the API Key has the required permissions in the Workspace. Go to the Model Studio console, click the workspace in the lower-left corner, switch to the correct workspace, and then click image to check the model deployment permission settings.
    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 details on the API calls, see API details.
Token Plan
Model Playground
  • Audio generation
  • Music generation
Statistics and Monitoring
Asset Center
Support