Decision Model API

Updated at:

Call POST /compatible-mode/v1/systemone to use the Bailian decision model (decision-model / decision-model-preview), which returns classification, scoring, and yes/no decisions with full probability distributions and confidence in a single forward pass, without generating text. Suitable for high-frequency structured decisions such as ticket routing, content moderation, agent routing, and result verification.

Prerequisites

You have created an API Key and set it as the environment variable DASHSCOPE_API_KEY. For configuration, see Configure the API key in environment variables.

ImportantTry the preview model online: Before writing code, try the decision model in the Playground. Pick a demo scenario (customer service judgment, agent verification, ticket routing, content moderation, agent task routing, or medical triage), enter your business content, run the model, and review decisions, probability distributions, and token usage. Modify inputs to observe how results change.

Request

Protocol: TypeSafe System One (POST /compatible-mode/v1/systemone)

A single request carries the business state and several typed questions (choice / noul / score). The model returns the decision result and probability distribution for each question in one forward pass, with choice and score additionally returning confidence, and does not generate text, so latency and cost are independent of output length.

Endpoint

Replace {WorkspaceId} with your workspace ID. See Regions and endpoints.

Region

Endpoint

China (Beijing)

https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/systemone

Singapore

https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/systemone

US (Virginia)
decision-model

https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/compatible-mode/v1/systemone

Germany (Frankfurt)
decision-model

https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/compatible-mode/v1/systemone

Japan (Tokyo)
decision-model

https://{WorkspaceId}.ap-northeast-1.maas.aliyuncs.com/compatible-mode/v1/systemone

Hong Kong (China)
decision-model

https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com/compatible-mode/v1/systemone

Request Parameters

Content-Type · String · Header · Required

Request type: application/json.

Authorization · String · Header · Required

API key, in the format: Bearer $DASHSCOPE_API_KEY.

model · String · Body · Required

Model name. Supported values:

state · String / Object / Array · Body · Required

The business state to make decisions on: ticket text, a conversation, or a structured object (objects are serialized before being sent to the model).

The following image input parameters apply to the stable decision-model.

image · Object · Body · Optional

Single image used with the text in state for decisions. url is a publicly accessible image URL or a Base64 Data URL such as data:image/png;base64,... (use the MIME type of the image file).

images · Array<Object> · Body · Optional

Multiple images, each using the same object format as image.

At most 4 images per question and 16 images per request.

Image input can be sent over HTTP, or through the DashScope Python SDK (2.1.0 or later): image/images are not named parameters of client.decision.create yet and must be passed through extra_body (see the image input example below). The DashScope Java SDK does not support image input yet; use HTTP calls.

questions · Object · Body · Required

A map of questions. The key is a caller-defined question id; the value is a question object with the following fields.

Question object properties

type · String · Required

Question type:

  • choice: single choice
  • noul: yes/no
  • score: ordinal scale

instructions · String · Optional

Question description or judgment criteria.

criteria · Object / Array · Depends on type

  • choice: a map of option name → option description (1–255 items; providing all options and an other fallback is recommended).
  • noul: optional {"true":…, "false":…} descriptions.
  • score: an array of level descriptions from low to high (2–255 levels; 3–7 clearly distinguishable levels recommended).
Limits and recommendations
  • Maximum 16 questions (latency grows near-linearly with the number of questions).
  • choice options: ≤ 255.
  • score levels: 2–255 (3–7 recommended).
  • Context: decision-model: 268,288 tokens; decision-model-preview: 65,536 tokens; overlong state is rejected.

Request Examples

  • Python: DashScope SDK 2.0.1 or later (client.decision.create). The SDK builds the endpoint from your workspace and region; image input requires 2.1.0 or later (passed through extra_body). Install with pip install -U "dashscope>=2.0.1", see Install the SDK.
  • Java: DashScope SDK 2.23.3 or later (DecisionModel.call), Maven dependency com.alibaba:dashscope-sdk-java. See the DashScope Java SDK documentation for the full API reference.
  • On call failures, the Python SDK raises a DashScopeError exception and the Java SDK raises an ApiException.

Image input example

Image URL(curl)

curl -sS -X POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/systemone \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "decision-model",
    "state": "Identify the animal in the image.",
    "image": {"url": "https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg"},
    "questions": {
      "animal": {
        "type": "choice",
        "instructions": "Which animal is in the image?",
        "criteria": {"dog": "Dog", "cat": "Cat", "none": "No animal"}
      }
    }
  }'

Base64 image(Python)

Replace /path/to/screenshot.png with your local PNG screenshot path. For multiple images, replace image with images: [{"url": ...}, ...].

import base64
import json
import os
import urllib.request

with open("/path/to/screenshot.png", "rb") as image_file:
    img_b64 = base64.b64encode(image_file.read()).decode()

body = {
    "model": "decision-model",
    "state": "Identify the problem in this ticket screenshot.",
    "image": {"url": f"data:image/png;base64,{img_b64}"},
    "questions": {
        "error_code": {
            "type": "choice",
            "instructions": "Which error code appears in the screenshot?",
            "criteria": {"E-7788": "Disk full", "500": "HTTP 500", "other": "Other or absent"},
        },
        "escalate": {"type": "noul", "instructions": "Should the on-call team be notified immediately?"},
        "severity": {
            "type": "score",
            "instructions": "How severe is the issue?",
            "criteria": ["Minor", "Some functions affected", "Core functions unavailable", "Severe business/security impact"],
        },
    },
}
request = urllib.request.Request(
    "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/systemone",
    data=json.dumps(body).encode(),
    headers={
        "Authorization": f"Bearer {os.environ['DASHSCOPE_API_KEY']}",
        "Content-Type": "application/json",
    },
)
with urllib.request.urlopen(request) as response:
    print(json.dumps(json.load(response), ensure_ascii=False, indent=2))

DashScope Python

Requires DashScope Python SDK 2.1.0 or later.

import os

import dashscope

# Configuration for China (Beijing) region. Replace "{WorkspaceId}" with your real workspace ID; other regions differ.
# image/images are not named parameters of create yet; extra_body forwards them alongside state and questions.
client = dashscope.Client(
    # If the API key is not in an environment variable, replace the line below: api_key="sk-xxx"
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    workspace="{WorkspaceId}",
    region="cn-beijing",
)

result = client.decision.create(
    model="decision-model",
    state="Identify the animal in the image.",
    questions={
        "animal": {"type": "choice", "instructions": "Which animal is in the image?",
                   "criteria": {"dog": "Dog", "cat": "Cat", "none": "No animal"}},
    },
    # A local image can be Base64-encoded into a data URL first (see the Base64 example above); multiple images use images: [{"url": ...}, ...]
    extra_body={"image": {"url": "https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg"}},
)

print(result.answers["animal"].choice)   # selected option
print(result.usage.input_tokens, result.latency_ms)

Ticket routing

A single request handles three decisions at once: team assignment (choice), escalation (noul), and severity (score). The example below uses the China (Beijing) region.

DashScope Python

import os

import dashscope

# The following is the configuration for the China (Beijing) region. Replace "{WorkspaceId}" with your actual workspace ID. The configuration differs by region.
# The decision model endpoint always sits under the compatible-mode path of the workspace gateway; the SDK derives it from workspace and region.
client = dashscope.Client(
    # If you have not configured an environment variable, replace the following line with your Model Studio API key: api_key="sk-xxx"
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    workspace="{WorkspaceId}",
    region="cn-beijing",
)

result = client.decision.create(
    model="decision-model",
    state={"ticket_id": "T-1001", "content": "More than 24 hours after payment, the order has not been credited."},
    questions={
        "department": {"type": "choice", "instructions": "Which team should handle this?",
                       "criteria": {"billing": "Payment, refund, and billing issues", "technical": "Product failure and integration issues"}},
        "escalate": {"type": "noul", "instructions": "Should on-call staff be notified immediately?"},
        "severity": {"type": "score", "instructions": "How severe is this issue?",
                     "criteria": ["Minor issue, no impact on functionality", "Some functionality affected, but a workaround exists",
                                  "Core functionality unavailable, no workaround", "Severe business or security impact"]},
    },
)

print(result.answers["department"].choice)   # selected option
print(result.answers["escalate"].noul)       # P(yes)
print(result.answers["severity"].score)      # probability-weighted level index
print(result.usage.input_tokens, result.latency_ms)

DashScope Java

import com.alibaba.dashscope.decision.DecisionModel;
import com.alibaba.dashscope.decision.DecisionModelParam;
import com.alibaba.dashscope.decision.DecisionModelResult;
import com.alibaba.dashscope.decision.DecisionQuestion;
import com.alibaba.dashscope.utils.JsonUtils;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class DecisionDemo {
  public static void main(String[] args) throws Exception {
    // The API key is read from the DASHSCOPE_API_KEY environment variable by default.
    // The constructor takes the workspace ID and region; the SDK derives
    // https://{WorkspaceId}.{region}.maas.aliyuncs.com/compatible-mode/v1/systemone
    Map<String, Object> state = new HashMap<>();
    state.put("ticket_id", "T-1001");
    state.put("content", "More than 24 hours after payment, the order has not been credited. The user cannot continue using core services and demands immediate handling.");

    Map<String, String> options = new LinkedHashMap<>();
    options.put("billing", "Payment, refund, and billing issues");
    options.put("technical", "Product failure and integration issues");

    List<String> levels = Arrays.asList(
        "Minor issue, no impact on functionality",
        "Some functionality affected, but a workaround exists",
        "Core functionality unavailable, no workaround",
        "Severe business or security impact");

    Map<String, DecisionQuestion> questions = new LinkedHashMap<>();
    questions.put("department", DecisionQuestion.choice("Which team should handle this?", options));
    questions.put("escalate", DecisionQuestion.noul("Should on-call staff be notified immediately?"));
    questions.put("severity", DecisionQuestion.score("How severe is this issue?", levels));

    DecisionModelParam param = DecisionModelParam.builder()
        .model("decision-model")
        .state(state)
        .questions(questions)
        .build();

    DecisionModel decisionModel = new DecisionModel("{WorkspaceId}", "cn-beijing");
    DecisionModelResult result = decisionModel.call(param);

    System.out.println(JsonUtils.toJson(result));
  }
}

TypeSafe Python

import os
from typesafe_sdk import TypeSafeClient

client = TypeSafeClient(
    api_key=os.environ["DASHSCOPE_API_KEY"],
    base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode",
)

result = client.system_one(
    model="decision-model",
    state={"ticket_id": "T-1001", "content": "More than 24 hours after payment, the order has not been credited."},
    questions={
        "department": {"type": "choice", "instructions": "Which team should handle this?",
                       "criteria": {"billing": "Payment, refund, and billing issues", "technical": "Product failure and integration issues"}},
        "escalate": {"type": "noul", "instructions": "Should on-call staff be notified immediately?"},
        "severity": {"type": "score", "instructions": "How severe is this issue?",
                     "criteria": ["Minor issue, no impact on functionality", "Some functionality affected, but a workaround exists",
                                  "Core functionality unavailable, no workaround", "Severe business or security impact"]},
    },
)

print(result.answers["department"])   # choice, confidence, probabilities
print(result.answers["escalate"])     # noul P(yes)
print(result.answers["severity"])     # score, legend, probabilities

curl

curl -sS -X POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/systemone \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "decision-model",
    "state": {"ticket_id": "T-1001", "content": "More than 24 hours after payment, the order has not been credited. The user cannot continue using core services and demands immediate handling."},
    "questions": {
      "department": {"type": "choice", "instructions": "Which team should handle this?",
                     "criteria": {"billing": "Payment, refund, and billing issues", "technical": "Product failure and integration issues"}},
      "escalate":   {"type": "noul",  "instructions": "Should on-call staff be notified immediately?"},
      "severity":   {"type": "score", "instructions": "How severe is this issue?",
                     "criteria": ["Minor issue, no impact on functionality", "Some functionality affected, but a workaround exists",
                                  "Core functionality unavailable, no workaround", "Severe business or security impact"]}
    }
  }'

Yes/no decision

A noul question returns P(yes), where 0 = no and 1 = yes. The example below uses the China (Beijing) region.

DashScope Python

import os

import dashscope

client = dashscope.Client(
    # If you have not configured an environment variable, replace the following line with your Model Studio API key: api_key="sk-xxx"
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    workspace="{WorkspaceId}",
    region="cn-beijing",
)

result = client.decision.create(
    model="decision-model",
    state="Is this comment asking for a refund?",
    questions={"refund": {"type": "noul", "instructions": "Is the user asking for a refund?"}},
)

print(result.answers["refund"].noul)   # P(yes)

DashScope Java

import com.alibaba.dashscope.decision.DecisionModel;
import com.alibaba.dashscope.decision.DecisionModelParam;
import com.alibaba.dashscope.decision.DecisionModelResult;
import com.alibaba.dashscope.decision.DecisionQuestion;
import java.util.LinkedHashMap;
import java.util.Map;

public class DecisionDemo {
  public static void main(String[] args) throws Exception {
    Map<String, DecisionQuestion> questions = new LinkedHashMap<>();
    questions.put("refund", DecisionQuestion.noul("Is the user asking for a refund?"));

    DecisionModelParam param = DecisionModelParam.builder()
        .model("decision-model")
        .state("Is this comment asking for a refund?")
        .questions(questions)
        .build();

    DecisionModel decisionModel = new DecisionModel("{WorkspaceId}", "cn-beijing");
    DecisionModelResult result = decisionModel.call(param);

    System.out.println(result.getAnswers().get("refund").getNoul());   // P(yes)
  }
}

TypeSafe Python

import os
from typesafe_sdk import TypeSafeClient

client = TypeSafeClient(
    api_key=os.environ["DASHSCOPE_API_KEY"],
    base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode",
)

result = client.system_one(
    model="decision-model",
    state="Is this comment asking for a refund?",
    questions={"refund": {"type": "noul", "instructions": "Is the user asking for a refund?"}},
)

print(result.answers["refund"])   # noul P(yes)

curl

curl -sS -X POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/systemone \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "decision-model",
    "state": "Is this comment asking for a refund?",
    "questions": {
      "refund": {"type": "noul", "instructions": "Is the user asking for a refund?"}
    }
  }'

Response Parameters

model · String

Model name echoed back.

request_id · String

Request ID, for troubleshooting.

answers · Object

A map of answers. The key corresponds to the question id in the request; the value is an answer object with the following fields.

Answer object properties

type · String

Matches the question type (choice / noul / score).

choice · String

For choice: the selected option name.

noul · Float

For noul: P(yes), where 0 = no and 1 = yes.

score · Float

For score: the probability-weighted expectation of the level index, which can fall between two levels (e.g. 1.43).

probabilities · Object

The probability of each option / level (sums to 1).

confidence · Float

The confidence of the answer (returned for choice / score).

legend · Object

For score: a map of level index → level description.

usage · Object

Metering information:

  • input_tokens (Integer): number of input tokens.

latency_ms · Float

Server-side latency (milliseconds).

Response Example

The following is the response for the ticket routing example (abbreviated). Probabilities and confidence depend on the actual result.

{
  "model": "decision-model",
  "request_id": "7b986c65-b223-9341-b5f0-b988e27ecaac",
  "answers": {
    "department": {
      "type": "choice",
      "choice": "billing",
      "confidence": 0.88,
      "probabilities": {"billing": 0.94, "technical": 0.06}
    },
    "escalate": {
      "type": "noul",
      "noul": 0.99
    },
    "severity": {
      "type": "score",
      "score": 2.25,
      "confidence": 0.91,
      "legend": {
        "0": "Minor issue, no impact on functionality",
        "1": "Some functionality affected, but a workaround exists",
        "2": "Core functionality unavailable, no workaround",
        "3": "Severe business or security impact"
      },
      "probabilities": {"0": 0.0, "1": 0.01, "2": 0.73, "3": 0.26}
    }
  },
  "usage": {"input_tokens": 125},
  "latency_ms": 52.9
}

Error Codes

If the call fails, an error message is returned. For more error codes and solutions, see Error messages.