Skip to main content
Text Generation

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_id and the quantizable model
  • Create a compression task → obtain the job_id
  • Poll Query compression task / Get compression task logs → until SUCCEEDED / FAILED / CANCELED
  • After SUCCEEDED, use quantized_output to create a deployment; when no longer needed, Cancel compression task / Delete compression task
Domain for all API endpoints: https://dashscope-intl.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 Singapore 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:
  1. Activated Alibaba Cloud Bailian service and completed real-name verification.
  2. 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.
  3. 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 in the Bailian console under "Model Deployment". The current compression feature is free for a limited time.

Interface List

All interface domains: https://dashscope-intl.aliyuncs.com

#

Method

Path

Description

1

GET

/api/v1/fine-tunes/compress/templates

List quantizable models and configuration templates

2

POST

/api/v1/fine-tunes/compress/jobs

Create compression job

3

GET

/api/v1/fine-tunes/compress/jobs

List compression jobs

4

GET

/api/v1/fine-tunes/compress/jobs/{job_id}

Query compression job details

5

GET

/api/v1/fine-tunes/compress/jobs/{job_id}/logs

Get compression job logs

6

POST

/api/v1/fine-tunes/compress/jobs/{job_id}/cancel

Cancel compression job

7

DELETE

/api/v1/fine-tunes/compress/jobs/{job_id}

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-intl.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 Singapore Region. If you use another Region, complete model compression in that Region's Bailian console.

Object properties

Response parameters

Field

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 quantization

compress_type

String

Compression type, same as training_type, fixed as quantization

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 code and message; null on success

group

String

Job group, fixed as quantization

usage

Integer

GPU duration (seconds), appears when SUCCEEDED or CANCELED

Job status

Status

Description

PENDING

Job created, waiting for scheduling

QUEUING

Entered the scheduling queue, waiting for GPU resources

RUNNING

Job in progress

CANCELING

Cancel initiated, waiting for termination

SUCCEEDED

Job succeeded, the quantized_output field returns the produced model ID

FAILED

Job failed, the error.code / error.message fields return the reason

CANCELED

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.
Only 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.
Endpoint
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: zh-CN / en-US (see Multi-language support)

Request example
curl "https://dashscope-intl.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": []
          }
        ]
      }
    ]
  }
}
{
  "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
              }
            ]
          }
        ]
      }
    ]
  }
}
Response parameters

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 lang parameter)

templates[].description

String

Template description (supports multi-language; returns the corresponding language version based on the lang parameter)

templates[].compress_type

String

Compression type, fixed as quantization

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: number (numeric, used with data_range/step) / string (enumeration, used with support_values)

hyper_parameters[].display_name

String

Parameter display name (supports multi-language; returns the corresponding language version based on the lang parameter)

hyper_parameters[].description

String

Parameter description (supports multi-language; returns the corresponding language version based on the lang parameter)

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 type=string), e.g. ["instruct", "think", "hybrid"]

hyper_parameters[].data_range

Array<String>

Numeric range (only present when type=number), e.g. ["64","256"] indicates a range of 64~256

hyper_parameters[].step

Integer

Step size (only present when type=number)

Create a compression job

Endpoint
POST /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 file-{32hex}); takes effect only when calib_input=true. The dataset must be created and published in Data Management first

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: {base_model}-{suffix}-{job_id}

Request example
curl -X POST "https://dashscope-intl.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. Endpoint
GET /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., w4a16, w8a8)

quant_method

String

No

-

Filter by quantization algorithm (e.g., gptq, awq, fp8)

start_time

String

No

-

Job start time is no earlier than this value. Format: yyyy-MM-dd HH:mm:ss / ISO-8601 / yyyy-MM-dd

end_time

String

No

-

Job end time is no later than this value, format same as start_time

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 is not provided, fuzzy matches both job_id and job_name; when combined with select_key, only the specified field is matched

select_key

String

No

-

Search field for search_key, options: job_id / job_name

sort_by

String

No

create_time

Sort field, currently only supports create_time

sort_order

String

No

desc

Sort direction, asc ascending / desc descending

page_no

Integer

No

1

Page number

page_size

Integer

No

10

Page size, max 100

Request examples
# Combined search: by status + algorithm + pagination
curl "https://dashscope-intl.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-intl.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

Endpoint
GET /api/v1/fine-tunes/compress/jobs/{job_id}
Request example
curl "https://dashscope-intl.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 quantization

compress_type

String

Compression type, same as training_type, fixed as quantization

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 code and message; null on success

group

String

Job group, fixed as quantization

usage

Integer

GPU duration (seconds), present when SUCCEEDED or CANCELED

Get compression job logs

Endpoint
GET /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. Request parameters

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

Request example
curl "https://dashscope-intl.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. Endpoint
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. Request example
curl -X POST "https://dashscope-intl.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). Endpoint
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. Request example
curl -X DELETE "https://dashscope-intl.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

InvalidParameter

400

Invalid request parameter

MissingParameter

400

Missing required parameter

Unauthorized

401

Authentication failed

Forbidden

403

No permission to access

ResourceNotFound

404

Resource does not exist

UnsupportedOperation

400

The resource state does not allow this operation (e.g., canceling a job that is already in a terminal state)

QuotaExceeded

429

Quota exceeded

InternalError

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. Parameter validation

External Code

HTTP

Description

InvalidParameter

400

Missing required parameter model

InvalidParameter

400

Missing required parameter template_id

InvalidParameter

400

Direct quantization of base models is not supported

InvalidParameter

400

The specified configuration template does not exist

InvalidParameter

400

The current model does not support this compression template

InvalidParameter

400

The model does not support quantization

InvalidParameter

400

LoRA fine-tuned models do not support quantization

InvalidParameter

400

Model data unavailable

InvalidParameter

400

The job name contains unsupported characters

InvalidParameter

400

output_model_suffix exceeds 8 characters

InvalidParameter

400

The source model is not ready

AccessDenied

403

No permission to use this compression template

Hyperparameter validation

External Code

HTTP

Description

InvalidParameter

400

Required hyperparameter not provided

InvalidParameter

400

Unknown hyperparameter provided

InvalidParameter

400

The hyperparameter value is not in the enumeration list

InvalidParameter

400

The hyperparameter value is out of range

InvalidParameter

400

The hyperparameter value is not a valid number

Job query

External Code

HTTP

Description

NotFound

404

The specified compression job does not exist

InvalidParameter

400

Missing required parameter job_id

Pagination and time parameters

External Code

HTTP

Description

InvalidParameter

400

Invalid page number parameter (must be ≥ 1)

InvalidParameter

400

Invalid page size (must be 1–100)

InvalidParameter

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."
}
Text Generation
Image Generation
  • FAQ
Video Generation
Audio
Realtime API
Text Embedding
Model Production