Model compression
Compress models using techniques like quantization to reduce inference costs.
Overview
The Model Compression API compresses custom full-parameter fine-tuned models through techniques such as quantization, reducing inference memory footprint and improving throughput. Currently, the compression feature only supports quantization and covers the complete lifecycle from querying templates, creating tasks, polling status, retrieving logs, to canceling/deleting tasks.
Typical flow:
- List quantizable models and configuration templates → obtain the
template_idand the quantizablemodel - Create a compression task → obtain the
job_id - Poll Query compression task / Get compression task logs → until
SUCCEEDED/FAILED/CANCELED - After
SUCCEEDED, usequantized_outputto create a deployment; when no longer needed, Cancel compression task / Delete compression task
Domain for all API endpoints: https://dashscope.aliyuncs.com. Authentication uniformly uses Authorization: Bearer ${YOUR_API_KEY}, and POST requests must include Content-Type: application/json.
For the meanings of task object fields and the state machine, see Compression task object; for unified error codes, see Error codes at the end of the document.
Quick Start
The model compression API is currently available only in the Beijing Region. If you use another Region, complete model compression operations through the Bailian console of that Region.
The model compression API provides a complete set of RESTful interfaces covering query templates, creating jobs, polling status, obtaining logs, and canceling/deleting jobs. This document is intended for developers to integrate compression capabilities via OpenAPI or SDK. For console introductions, see related documents.
Prerequisites
Before calling the interfaces in this document, please complete the following:
- Activated Alibaba Cloud Bailian service and completed real-name verification.
- The current workspace has at least one custom full-parameter fine-tuned model based on
qwen3.5-flash-2026-02-23(completed via the fine-tuning job interface). The current compression feature only supports this model; LoRA models and already-quantized models are not supported. - Obtained an API Key (see Obtain API Key).
The deployment unit specifications supported by the compressed output model are determined by the selected quantization template, and the deployment quantity is configured under Dedicated Deployment in the Bailian console. The current compression feature is free for a limited time.
Interface List
All interface domains: https://dashscope.aliyuncs.com
# | Method | Path | Description |
|---|---|---|---|
1 | GET |
| List quantizable models and configuration templates |
2 | POST |
| Create compression job |
3 | GET |
| List compression jobs |
4 | GET |
| Query compression job details |
5 | GET |
| Get compression job logs |
6 | POST |
| Cancel compression job |
7 | DELETE |
| Delete compression job |
Authentication
All interfaces carry the API Key via HTTP Header:
Authorization: Bearer ${YOUR_API_KEY}
Content-Type: application/json applies to POST request body scenarios.
Get Started in 5 Minutes
HTTP
Install the requests library:
pip install requests
Complete example of creating a job, polling, and obtaining the output model:
import requests, time
API_KEY = "YOUR_API_KEY"
BASE = "https://dashscope.aliyuncs.com/api/v1/fine-tunes/compress"
HEADERS = {"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"}
# 1. Create compression job
resp = requests.post(f"{BASE}/jobs", headers=HEADERS, json={
"model": "qwen3.5-flash-2026-02-23-ft-***", # Custom fine-tuned model ID
"template_id": "quant-flash-nvfp4-mlp-nomtp", # Obtain via GET /templates
"output_model_suffix": "test", # Max 8 characters, lowercase letters and digits only
}).json()
job_id = resp["output"]["job_id"]
print("Job:", job_id)
# 2. Poll until terminal state
status = resp["output"]["status"]
while status not in ("SUCCEEDED", "FAILED", "CANCELED"):
time.sleep(30)
resp = requests.get(f"{BASE}/jobs/{job_id}", headers=HEADERS).json()
status = resp["output"]["status"]
print("Status:", status)
# 3. Process results
if status == "SUCCEEDED":
print("Quantized model:", resp["output"]["quantized_output"])
# Use quantized_output to call the model deployment interface for deployment
elif status == "FAILED":
print("Error:", resp["output"]["error"])
List jobs and obtain logs:
# List all successfully compressed jobs
resp = requests.get(f"{BASE}/jobs", headers=HEADERS, params={"status": "SUCCEEDED", "page_size": 20}).json()
for j in resp["output"]["jobs"]:
print(j["job_id"], j["template_name"], j["quantized_output"])
# Get job logs
resp = requests.get(f"{BASE}/jobs/{job_id}/logs", headers=HEADERS, params={"offset": 0, "line": 100}).json()
for line in resp["output"]["logs"]:
print(line)
Output model naming rules:
quantized_output = {base_model}-{output_model_suffix}-{job_id}
For example, base_model is qwen3.5-flash-2026-02-23, suffix is test, job_id is quant-202604111200-a1b2, and the output model ID is:
qwen3.5-flash-2026-02-23-test-quant-202604111200-a1b2
See each interface detail page for cURL usage of each interface.
Compression job object
The model compression API is currently available only in the Beijing Region. If you use another Region, complete model compression in that Region's Bailian console.
Object properties
Response parametersField | Type | Description |
|---|---|---|
job_id | String | Job ID |
job_name | String | Job name |
job_description | String | Job description |
status | String | Job status (see Job status) |
model | String | Source model ID |
base_model | String | Base model ID |
template_id | String | ID of the compression template in use |
template_name | String | Template name |
template_description | String | Template description |
training_type | String | Job type, fixed as |
compress_type | String | Compression type, same as |
hyper_parameters | Object | Actually effective hyperparameters (only returns user-visible parameters) |
custom_calibration_file_ids | Array<String> | List of file IDs for the custom calibration dataset |
quantized_output | String | Model ID produced after quantization (only has a value when SUCCEEDED) |
create_time | String | Job creation time |
start_time | String | Job start execution time (null when PENDING/QUEUING) |
end_time | String | Job completion time (has a value in terminal states) |
error | Object | Error information on failure, containing |
group | String | Job group, fixed as |
usage | Integer | GPU duration (seconds), appears when SUCCEEDED or CANCELED |
Job status
Status | Description |
|---|---|
| Job created, waiting for scheduling |
| Entered the scheduling queue, waiting for GPU resources |
| Job in progress |
| Cancel initiated, waiting for termination |
| Job succeeded, the |
| Job failed, the |
| Job canceled |
Status transition:
PENDING ─→ QUEUING ─→ RUNNING ─→ SUCCEEDED
│ │
↓ ↓
CANCELING ─→ FAILED / CANCELED
List quantizable models and configuration templates
Lists all quantizable custom fine-tuned models of the current user, as well as the compression templates bound to each model. Templates are bound to models; different combinations of model architecture × precision × target MU specifications correspond to different templates.
EndpointOnly returns custom models that the current user has fully fine-tuned (SFT/DPO/CPT) based on a base model. LoRA fine-tuned models and already-quantized models will not appear in the results.
GET /api/v1/fine-tunes/compress/templates
Request parameters
Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
model | String | No | - | Filter by model ID; when a base model name is passed, returns all custom models based on that base model |
lang | String | No | zh-CN | Response language: |
curl "https://dashscope.aliyuncs.com/api/v1/fine-tunes/compress/templates" \
-H "Authorization: Bearer ${API_KEY}"
Response example (minimal)
{
"request_id": "uuid-string",
"output": {
"base_models": ["qwen3.5-flash-2026-02-23"],
"custom_models": [
{
"model": "qwen3.5-flash-2026-02-23-ft-***",
"model_name": "My SFT fine-tuned model",
"base_model": "qwen3.5-flash-2026-02-23",
"templates": [
{
"template_id": "quant-flash-nvfp4-mlp-nomtp",
"template_name": "W4A4 NVFP4 high-performance compression-MU5/MU8/MU9",
"description": "Balances high precision and high performance under lower-bit compression, further reducing memory usage and improving inference throughput.",
"compress_type": "quantization",
"hyper_parameters": []
}
]
}
]
}
}
Response example (complete: with tunable hyperparameters)
{
"request_id": "uuid-string",
"output": {
"base_models": ["qwen3.5-flash-2026-02-23"],
"custom_models": [
{
"model": "qwen3.5-flash-2026-02-23-ft-***",
"model_name": "My SFT fine-tuned model",
"base_model": "qwen3.5-flash-2026-02-23",
"templates": [
{
"template_id": "quant-flash-nvfp4-mlp-nomtp",
"template_name": "W4A4 NVFP4 high-performance compression-MU5/MU8/MU9",
"description": "Balances high precision and high performance under lower-bit compression, further reducing memory usage and improving inference throughput.",
"compress_type": "quantization",
"hyper_parameters": [
{
"name": "calib_input",
"type": "string",
"display_name": "Calibration input",
"description": "Whether to enable calibration input",
"support_values": ["true"],
"defaultValue": "true",
"recommend_value": "true",
"required": false
}
]
}
]
}
]
}
}
Field | Type | Description |
|---|---|---|
base_models | Array<String> | List of base model names that support compression |
custom_models[].model | String | Model ID |
custom_models[].model_name | String | Model display name |
custom_models[].base_model | String | Base model name |
custom_models[].templates | Array | List of compression configuration templates supported by this model, inherited from its base model's templates |
templates[].template_id | String | Template ID, passed as the template_id parameter when creating a compression task |
templates[].template_name | String | Template name (supports multi-language; returns the corresponding language version based on the |
templates[].description | String | Template description (supports multi-language; returns the corresponding language version based on the |
templates[].compress_type | String | Compression type, fixed as |
templates[].hyper_parameters | Array | Tunable hyperparameters; an empty array means no tunable hyperparameters |
hyper_parameters[].name | String | Parameter name (used as the Key when creating a task) |
hyper_parameters[].type | String | Type: |
hyper_parameters[].display_name | String | Parameter display name (supports multi-language; returns the corresponding language version based on the |
hyper_parameters[].description | String | Parameter description (supports multi-language; returns the corresponding language version based on the |
hyper_parameters[].defaultValue | String | Default value |
hyper_parameters[].recommend_value | String | Recommended value |
hyper_parameters[].required | Boolean | Whether required |
hyper_parameters[].support_values | Array<String> | List of enumeration values (only present when |
hyper_parameters[].data_range | Array<String> | Numeric range (only present when |
hyper_parameters[].step | Integer | Step size (only present when |
Create a compression job
EndpointPOST /api/v1/fine-tunes/compress/jobs
Request parameters
Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
model | String | Yes | - | Source model ID, which can be obtained via the API |
template_id | String | Yes | - | Compression template ID, which can be obtained via the API |
job_name | String | No | Auto-generated | Job name; duplicates are not allowed under the same user; up to 50 characters |
job_description | String | No | - | Job description; up to 200 characters |
hyper_parameters | Object | No | Template default value | Hyperparameter overrides (key-value); only pass the items you want to override |
custom_calibration_file_ids | Array<String> | No | - | List of custom calibration dataset file IDs (dataset group ID, in the format |
output_model_suffix | String | No | - | Suffix of the quantized output model name; up to 8 characters, only lowercase letters and digits. Output model name format: |
curl -X POST "https://dashscope.aliyuncs.com/api/v1/fine-tunes/compress/jobs" \
-H "Authorization: Bearer ${API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"job_name": "qwen3.5-flash compression job",
"model": "qwen3.5-flash-2026-02-23-ft-***",
"template_id": "quant-flash-nvfp4-mlp-nomtp",
"custom_calibration_file_ids": ["file-***"],
"output_model_suffix": "test"
}'
Response example
{
"request_id": "uuid-string",
"output": {
"job_id": "quant-202604111200-a1b2",
"job_name": "qwen3.5-flash compression job",
"status": "PENDING",
"model": "qwen3.5-flash-2026-02-23-ft-***",
"base_model": "qwen3.5-flash-2026-02-23",
"template_id": "quant-flash-nvfp4-mlp-nomtp",
"template_name": "W4A4 NVFP4 high-performance compression-MU5/MU8/MU9",
"training_type": "quantization",
"compress_type": "quantization",
"hyper_parameters": {},
"custom_calibration_file_ids": ["file-***"],
"quantized_output": null,
"create_time": "2026-04-11 12:00:00",
"start_time": null,
"end_time": null,
"error": null,
"group": "quantization"
}
}
Response parameters: Field meanings are the same as the request parameters.
List compression jobs
Supports filtering by status, model, template, quantization spec, algorithm, time range, job name/ID, and supports sorting by creation time and pagination.
EndpointGET /api/v1/fine-tunes/compress/jobs
Request parameters
Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
status | String | No | - | Filter by status (e.g., RUNNING, SUCCEEDED) |
model | String | No | - | Filter by source model ID |
template_id | String | No | - | Filter by template ID |
quant_spec | String | No | - | Filter by quantization spec (e.g., |
quant_method | String | No | - | Filter by quantization algorithm (e.g., |
start_time | String | No | - | Job start time is no earlier than this value. Format: |
end_time | String | No | - | Job end time is no later than this value, format same as |
job_name | String | No | - | Fuzzy match by job name |
job_id | String | No | - | Fuzzy match by job ID |
search_key | String | No | - | Search keyword. When |
select_key | String | No | - | Search field for |
sort_by | String | No | create_time | Sort field, currently only supports |
sort_order | String | No | desc | Sort direction, |
page_no | Integer | No | 1 | Page number |
page_size | Integer | No | 10 | Page size, max 100 |
# Combined search: by status + algorithm + pagination
curl "https://dashscope.aliyuncs.com/api/v1/fine-tunes/compress/jobs?status=SUCCEEDED&quant_method=gptq&page_size=10" \
-H "Authorization: Bearer ${API_KEY}"
# Time range + search by job name + ascending by create time
curl "https://dashscope.aliyuncs.com/api/v1/fine-tunes/compress/jobs?start_time=2026-04-01&end_time=2026-04-30&search_key=qwen3&select_key=job_name&sort_by=create_time&sort_order=asc" \
-H "Authorization: Bearer ${API_KEY}"
Response example
{
"request_id": "uuid-string",
"output": {
"total": 42,
"page_no": 1,
"page_size": 10,
"jobs": [
{
"job_id": "quant-202604111200-a1b2",
"job_name": "qwen3.5-flash compression job",
"status": "SUCCEEDED",
"model": "qwen3.5-flash-2026-02-23-ft-***",
"base_model": "qwen3.5-flash-2026-02-23",
"template_id": "quant-flash-nvfp4-mlp-nomtp",
"template_name": "W4A4 NVFP4 high-performance compression-MU5/MU8/MU9",
"training_type": "quantization",
"compress_type": "quantization",
"custom_calibration_file_ids": ["file-***"],
"quantized_output": "qwen3.5-flash-2026-02-23-test-quant-202604111200-a1b2",
"create_time": "2026-04-11 12:00:00",
"start_time": "2026-04-11 12:02:30",
"end_time": "2026-04-11 13:02:30",
"group": "quantization",
"usage": 3600
}
]
}
}
Response parameters
Field | Type | Description |
|---|---|---|
total | Integer | Total number of matching jobs |
page_no | Integer | Current page number |
page_size | Integer | Page size |
jobs | Array | Job list, field meanings are the same as the response parameters of creating a compression job |
Query a compression job
EndpointGET /api/v1/fine-tunes/compress/jobs/{job_id}
Request example
curl "https://dashscope.aliyuncs.com/api/v1/fine-tunes/compress/jobs/quant-202604111200-a1b2" \
-H "Authorization: Bearer ${API_KEY}"
Response example
{
"request_id": "uuid-string",
"output": {
"job_id": "quant-202604111200-a1b2",
"job_name": "qwen3.5-flash compression job",
"job_description": "...",
"status": "SUCCEEDED",
"model": "qwen3.5-flash-2026-02-23-ft-***",
"base_model": "qwen3.5-flash-2026-02-23",
"template_id": "quant-flash-nvfp4-mlp-nomtp",
"template_name": "W4A4 NVFP4 high-performance compression-MU5/MU8/MU9",
"template_description": "Maintains high accuracy and high performance under lower-bit compression, further reducing GPU memory usage and improving inference throughput.",
"training_type": "quantization",
"compress_type": "quantization",
"hyper_parameters": {},
"custom_calibration_file_ids": ["file-***"],
"quantized_output": "qwen3.5-flash-2026-02-23-test-quant-202604111200-a1b2",
"create_time": "2026-04-11 12:00:00",
"start_time": "2026-04-11 12:02:30",
"end_time": "2026-04-11 13:02:30",
"error": null,
"group": "quantization",
"usage": 3600
}
}
Response parameters
Field | Type | Description |
|---|---|---|
job_id | String | Job ID, which can be obtained via the create compression job or list compression jobs interface |
job_name | String | Job name |
job_description | String | Job description |
status | String | Job status (see Job status for details) |
model | String | Source model ID |
base_model | String | Base model ID |
template_id | String | ID of the compression template used |
template_name | String | Template name |
template_description | String | Template description |
training_type | String | Job type, fixed as |
compress_type | String | Compression type, same as |
hyper_parameters | Object | Actually effective hyperparameters (only returns user-visible parameters) |
custom_calibration_file_ids | Array<String> | List of file IDs for the custom calibration dataset |
quantized_output | String | Model ID produced after quantization (only has a value when SUCCEEDED), can be used by the Create deployment interface for model deployment |
create_time | String | Job creation time |
start_time | String | Job start execution time (null when PENDING/QUEUING) |
end_time | String | Job completion time (has a value at terminal states) |
error | Object | Error information on failure, containing |
group | String | Job group, fixed as |
usage | Integer | GPU duration (seconds), present when SUCCEEDED or CANCELED |
Get compression job logs
EndpointGET /api/v1/fine-tunes/compress/jobs/{job_id}/logs
Where {job_id} is the compression job ID, which can be obtained via the create compression job or list compression jobs interface.
Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
offset | Integer | No | 0 | Skip the first N lines and start reading from the (N+1)th line |
line | Integer | No | 100 | Number of lines to read, up to 1000 |
curl "https://dashscope.aliyuncs.com/api/v1/fine-tunes/compress/jobs/quant-202604111200-a1b2/logs?offset=0&line=50" \
-H "Authorization: Bearer ${API_KEY}"
Response example
{
"request_id": "uuid-string",
"output": {
"total": 15,
"logs": [
"2026-04-11 12:02:35 - INFO - Starting quantization...",
"2026-04-11 12:30:00 - INFO - Quantization progress: 100%",
"2026-04-11 12:35:00 - INFO - Quantization succeeded!"
]
}
}
Log display rules
- When a custom calibration dataset is provided for the job, the logs contain a data processing completion marker
data process succeeded, start to quantization - The log interface has filtered out internal system markers and only returns user-readable compression progress information
Cancel a compression job
You can cancel only jobs in the PENDING, QUEUING, or RUNNING state. Cancellation is an asynchronous operation. The job first enters the CANCELING transitional state and eventually becomes CANCELED.
POST /api/v1/fine-tunes/compress/jobs/{job_id}/cancel
Where {job_id} is the compression job ID, which can be obtained from the Create compression job or List compression jobs API.
curl -X POST "https://dashscope.aliyuncs.com/api/v1/fine-tunes/compress/jobs/quant-202604111200-a1b2/cancel" \
-H "Authorization: Bearer ${API_KEY}"
Response example
{
"request_id": "uuid-string",
"output": { "status": "success" }
}
Delete a compression job
You can delete only jobs in a terminal state (SUCCEEDED / FAILED / CANCELED). Deleting a job record does not delete the already-generated quantized model (quantized_output).
DELETE /api/v1/fine-tunes/compress/jobs/{job_id}
Where {job_id} is the compression job ID, which can be obtained from the Create compression job or List compression jobs API.
curl -X DELETE "https://dashscope.aliyuncs.com/api/v1/fine-tunes/compress/jobs/quant-202604111200-a1b2" \
-H "Authorization: Bearer ${API_KEY}"
Response example
{
"request_id": "uuid-string",
"output": { "status": "success" }
}
Error code
Common error codes
Error code | HTTP | Description |
|---|---|---|
| 400 | Invalid request parameter |
| 400 | Missing required parameter |
| 401 | Authentication failed |
| 403 | No permission to access |
| 404 | Resource does not exist |
| 400 | The resource state does not allow this operation (e.g., canceling a job that is already in a terminal state) |
| 429 | Quota exceeded |
| 500 | Internal service error |
Business error codes
The following business error codes are listed by scenario. External Code is the actual code field value returned by the interface.
External Code | HTTP | Description |
|---|---|---|
| 400 | Missing required parameter |
| 400 | Missing required parameter |
| 400 | Direct quantization of base models is not supported |
| 400 | The specified configuration template does not exist |
| 400 | The current model does not support this compression template |
| 400 | The model does not support quantization |
| 400 | LoRA fine-tuned models do not support quantization |
| 400 | Model data unavailable |
| 400 | The job name contains unsupported characters |
| 400 |
|
| 400 | The source model is not ready |
| 403 | No permission to use this compression template |
External Code | HTTP | Description |
|---|---|---|
| 400 | Required hyperparameter not provided |
| 400 | Unknown hyperparameter provided |
| 400 | The hyperparameter value is not in the enumeration list |
| 400 | The hyperparameter value is out of range |
| 400 | The hyperparameter value is not a valid number |
External Code | HTTP | Description |
|---|---|---|
| 404 | The specified compression job does not exist |
| 400 | Missing required parameter |
External Code | HTTP | Description |
|---|---|---|
| 400 | Invalid page number parameter (must be ≥ 1) |
| 400 | Invalid page size (must be 1–100) |
| 400 | Invalid time format |
Error response example
{
"request_id": "uuid-string",
"code": "InvalidParameter",
"message": "The specified model 'xxx-lora-yyy' is a LoRA model and not supported for quantization."
}