> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.milliseconds.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.milliseconds.ai/_mcp/server.

# Walk a label tree

POST https://api.milliseconds.ai/v1/decision-machine-1/classify-tree
Content-Type: application/json

Runs classify once per level of a nested label tree, on the same text, descending into the winning label each time. Returns the path, the deepest label, the compound probability and confidence (products over the levels), and one entry per level with its scores, the input it sent to the model and its inference time.

Send `text` for one result, `texts` for a batch wrapped as `{ results: [...] }`, or `image` (one image, at most 5 MB decoded, optionally with `text`; never with `texts`). The response carries `x-input-chars` (input characters) and `x-input-tokens` (input tokens billed for this call) headers. Each item of `texts` (and each of `statements` or `questions`) counts as one request against the requests-per-minute limit. Each level re-sends the text, so latency grows with depth.

Reference: https://docs.milliseconds.ai/api/decision-machine-1/classify-tree

## Authentication

- `Authorization` header (bearer token, required) — A milliseconds API key, test\_sk-\{namespace}-\{entropy} or prod\_sk-\{namespace}-\{entropy}. Every /v1 route requires it.

## Request

### Body (application/json)

This endpoint expects a ClassifyTreeRequest.

- `tree` (ClassifyTree, required)
- `text` (string, optional) — The text to decide about.
- `texts` (list of string, optional) — Batch form: one result per text.
- `image` (string, optional) — One image: a `data:image/(jpeg|png|webp);base64,` URL, or bare base64 of a JPEG, PNG or WebP. 5 MB decoded at most. URLs are never fetched. May travel with `text` (extra context), never with `texts`.
- `detail` (enum, optional) — Image resolution: `low` 512 px, `medium` 768 px (default), `high` 1024 px longest edge. Higher sees more and bills more.
  - Allowed values: `low`, `medium`, `high`
- `question` (string, optional) — The question the model answers by choosing one label or level. Defaults to a generic one; a real rubric (what to look for, how to treat missing evidence) improves hard cases.

## Response

### 200

Result, or \{ results } for a batch

- `decision-machine-1_classifyTree_Response_200`
  - ClassifyTreeResult: ClassifyTreeResult
  - DecisionMachine1ClassifyTreeResponse2001

## Errors

### 400 Bad Request Error

Invalid request

- `error` (ErrorError, required)

### 502 Bad Gateway Error

Inference failed twice

- `error` (ErrorError, required)

## Types

### ClassifyTree

- string
- ClassifyTreeNode: ClassifyTreeNode

### ClassifyTreeResult

- `path` (list of string, required) — Winning label per level, top to bottom
- `label` (string, required) — The deepest label, the last of `path`
- `probability` (double, required) — Product of the level probabilities
- `confidence` (double, required) — Product of the level confidences
- `levels` (list of ClassifyTreeLevel, required)

### DecisionMachine1ClassifyTreeResponse2001

- `results` (list of ClassifyTreeResult, required)

### ErrorError

- `code` (string, required)
- `message` (string, required)

### ClassifyTreeNode

- `description` (string, optional)
- `labels` (ClassifyTree, optional)

### ClassifyTreeLevel

- `label` (string, required)
- `probability` (double, required)
- `confidence` (double, required)
- `scores` (map from string to double, required)
- `input_chars` (integer, required)
- `input_tokens` (integer, required)
- `inference_ms` (integer, required)

## Examples

**Request**

```json
{
  "tree": {
    "cardiovascular": {
      "description": "heart and blood vessels: chest pain, arrhythmia, heart failure, hypertension",
      "labels": {
        "acute_coronary_syndrome": {
          "description": "heart attack or angina: chest pain, ST elevation on the ECG, troponin rise",
          "labels": {
            "nstemi": "non-ST-elevation myocardial infarction: troponin rise without ST elevation",
            "stemi": "ST-elevation myocardial infarction: ST elevation on the ECG",
            "unstable_angina": "chest pain at rest without a troponin rise"
          }
        },
        "arrhythmia": "abnormal heart rhythm: palpitations, atrial fibrillation, bradycardia",
        "heart_failure": "fluid overload, breathlessness on exertion, swollen legs, reduced ejection fraction"
      }
    },
    "gastrointestinal": "digestive tract: abdominal pain, nausea, vomiting, bleeding",
    "neurological": "brain and nerves: headache, seizure, weakness, numbness",
    "pulmonary": {
      "description": "lungs and airways: cough, breathlessness, wheeze, pneumonia",
      "labels": {
        "embolism": "pulmonary embolism: sudden breathlessness, pleuritic pain, low oxygen",
        "infection": "pneumonia or bronchitis: fever with a productive cough",
        "obstructive": "asthma or COPD: wheeze, chronic cough, smoking history"
      }
    }
  },
  "text": "62-year-old man with crushing substernal chest pain radiating to the left arm for 40 minutes, sweating, and ST elevation in leads II, III and aVF."
}
```

**Response**

```json
{
  "confidence": 0.524,
  "label": "stemi",
  "levels": [
    {
      "confidence": 0.931,
      "inference_ms": 57,
      "input_chars": 456,
      "input_tokens": 112,
      "label": "cardiovascular",
      "probability": 0.982,
      "scores": {
        "cardiovascular": 0.982,
        "gastrointestinal": 0.001,
        "neurological": 0.016,
        "pulmonary": 0.001
      }
    },
    {
      "confidence": 0.564,
      "inference_ms": 56,
      "input_chars": 428,
      "input_tokens": 105,
      "label": "acute_coronary_syndrome",
      "probability": 0.825,
      "scores": {
        "acute_coronary_syndrome": 0.825,
        "arrhythmia": 0.173,
        "heart_failure": 0.003
      }
    },
    {
      "confidence": 0.998,
      "inference_ms": 59,
      "input_chars": 357,
      "input_tokens": 88,
      "label": "stemi",
      "probability": 1,
      "scores": {
        "nstemi": 0,
        "stemi": 1,
        "unstable_angina": 0
      }
    }
  ],
  "path": [
    "cardiovascular",
    "acute_coronary_syndrome",
    "stemi"
  ],
  "probability": 0.81
}
```

**SDK Code**

```python decision-machine-1_classifyTree_example
import requests

url = "https://api.milliseconds.ai/v1/decision-machine-1/classify-tree"

payload = {
    "tree": {
        "cardiovascular": {
            "description": "heart and blood vessels: chest pain, arrhythmia, heart failure, hypertension",
            "labels": {
                "acute_coronary_syndrome": {
                    "description": "heart attack or angina: chest pain, ST elevation on the ECG, troponin rise",
                    "labels": {
                        "nstemi": "non-ST-elevation myocardial infarction: troponin rise without ST elevation",
                        "stemi": "ST-elevation myocardial infarction: ST elevation on the ECG",
                        "unstable_angina": "chest pain at rest without a troponin rise"
                    }
                },
                "arrhythmia": "abnormal heart rhythm: palpitations, atrial fibrillation, bradycardia",
                "heart_failure": "fluid overload, breathlessness on exertion, swollen legs, reduced ejection fraction"
            }
        },
        "gastrointestinal": "digestive tract: abdominal pain, nausea, vomiting, bleeding",
        "neurological": "brain and nerves: headache, seizure, weakness, numbness",
        "pulmonary": {
            "description": "lungs and airways: cough, breathlessness, wheeze, pneumonia",
            "labels": {
                "embolism": "pulmonary embolism: sudden breathlessness, pleuritic pain, low oxygen",
                "infection": "pneumonia or bronchitis: fever with a productive cough",
                "obstructive": "asthma or COPD: wheeze, chronic cough, smoking history"
            }
        }
    },
    "text": "62-year-old man with crushing substernal chest pain radiating to the left arm for 40 minutes, sweating, and ST elevation in leads II, III and aVF."
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript decision-machine-1_classifyTree_example
const url = 'https://api.milliseconds.ai/v1/decision-machine-1/classify-tree';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"tree":{"cardiovascular":{"description":"heart and blood vessels: chest pain, arrhythmia, heart failure, hypertension","labels":{"acute_coronary_syndrome":{"description":"heart attack or angina: chest pain, ST elevation on the ECG, troponin rise","labels":{"nstemi":"non-ST-elevation myocardial infarction: troponin rise without ST elevation","stemi":"ST-elevation myocardial infarction: ST elevation on the ECG","unstable_angina":"chest pain at rest without a troponin rise"}},"arrhythmia":"abnormal heart rhythm: palpitations, atrial fibrillation, bradycardia","heart_failure":"fluid overload, breathlessness on exertion, swollen legs, reduced ejection fraction"}},"gastrointestinal":"digestive tract: abdominal pain, nausea, vomiting, bleeding","neurological":"brain and nerves: headache, seizure, weakness, numbness","pulmonary":{"description":"lungs and airways: cough, breathlessness, wheeze, pneumonia","labels":{"embolism":"pulmonary embolism: sudden breathlessness, pleuritic pain, low oxygen","infection":"pneumonia or bronchitis: fever with a productive cough","obstructive":"asthma or COPD: wheeze, chronic cough, smoking history"}}},"text":"62-year-old man with crushing substernal chest pain radiating to the left arm for 40 minutes, sweating, and ST elevation in leads II, III and aVF."}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go decision-machine-1_classifyTree_example
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.milliseconds.ai/v1/decision-machine-1/classify-tree"

	payload := strings.NewReader("{\n  \"tree\": {\n    \"cardiovascular\": {\n      \"description\": \"heart and blood vessels: chest pain, arrhythmia, heart failure, hypertension\",\n      \"labels\": {\n        \"acute_coronary_syndrome\": {\n          \"description\": \"heart attack or angina: chest pain, ST elevation on the ECG, troponin rise\",\n          \"labels\": {\n            \"nstemi\": \"non-ST-elevation myocardial infarction: troponin rise without ST elevation\",\n            \"stemi\": \"ST-elevation myocardial infarction: ST elevation on the ECG\",\n            \"unstable_angina\": \"chest pain at rest without a troponin rise\"\n          }\n        },\n        \"arrhythmia\": \"abnormal heart rhythm: palpitations, atrial fibrillation, bradycardia\",\n        \"heart_failure\": \"fluid overload, breathlessness on exertion, swollen legs, reduced ejection fraction\"\n      }\n    },\n    \"gastrointestinal\": \"digestive tract: abdominal pain, nausea, vomiting, bleeding\",\n    \"neurological\": \"brain and nerves: headache, seizure, weakness, numbness\",\n    \"pulmonary\": {\n      \"description\": \"lungs and airways: cough, breathlessness, wheeze, pneumonia\",\n      \"labels\": {\n        \"embolism\": \"pulmonary embolism: sudden breathlessness, pleuritic pain, low oxygen\",\n        \"infection\": \"pneumonia or bronchitis: fever with a productive cough\",\n        \"obstructive\": \"asthma or COPD: wheeze, chronic cough, smoking history\"\n      }\n    }\n  },\n  \"text\": \"62-year-old man with crushing substernal chest pain radiating to the left arm for 40 minutes, sweating, and ST elevation in leads II, III and aVF.\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby decision-machine-1_classifyTree_example
require 'uri'
require 'net/http'

url = URI("https://api.milliseconds.ai/v1/decision-machine-1/classify-tree")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"tree\": {\n    \"cardiovascular\": {\n      \"description\": \"heart and blood vessels: chest pain, arrhythmia, heart failure, hypertension\",\n      \"labels\": {\n        \"acute_coronary_syndrome\": {\n          \"description\": \"heart attack or angina: chest pain, ST elevation on the ECG, troponin rise\",\n          \"labels\": {\n            \"nstemi\": \"non-ST-elevation myocardial infarction: troponin rise without ST elevation\",\n            \"stemi\": \"ST-elevation myocardial infarction: ST elevation on the ECG\",\n            \"unstable_angina\": \"chest pain at rest without a troponin rise\"\n          }\n        },\n        \"arrhythmia\": \"abnormal heart rhythm: palpitations, atrial fibrillation, bradycardia\",\n        \"heart_failure\": \"fluid overload, breathlessness on exertion, swollen legs, reduced ejection fraction\"\n      }\n    },\n    \"gastrointestinal\": \"digestive tract: abdominal pain, nausea, vomiting, bleeding\",\n    \"neurological\": \"brain and nerves: headache, seizure, weakness, numbness\",\n    \"pulmonary\": {\n      \"description\": \"lungs and airways: cough, breathlessness, wheeze, pneumonia\",\n      \"labels\": {\n        \"embolism\": \"pulmonary embolism: sudden breathlessness, pleuritic pain, low oxygen\",\n        \"infection\": \"pneumonia or bronchitis: fever with a productive cough\",\n        \"obstructive\": \"asthma or COPD: wheeze, chronic cough, smoking history\"\n      }\n    }\n  },\n  \"text\": \"62-year-old man with crushing substernal chest pain radiating to the left arm for 40 minutes, sweating, and ST elevation in leads II, III and aVF.\"\n}"

response = http.request(request)
puts response.read_body
```

```java decision-machine-1_classifyTree_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.milliseconds.ai/v1/decision-machine-1/classify-tree")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"tree\": {\n    \"cardiovascular\": {\n      \"description\": \"heart and blood vessels: chest pain, arrhythmia, heart failure, hypertension\",\n      \"labels\": {\n        \"acute_coronary_syndrome\": {\n          \"description\": \"heart attack or angina: chest pain, ST elevation on the ECG, troponin rise\",\n          \"labels\": {\n            \"nstemi\": \"non-ST-elevation myocardial infarction: troponin rise without ST elevation\",\n            \"stemi\": \"ST-elevation myocardial infarction: ST elevation on the ECG\",\n            \"unstable_angina\": \"chest pain at rest without a troponin rise\"\n          }\n        },\n        \"arrhythmia\": \"abnormal heart rhythm: palpitations, atrial fibrillation, bradycardia\",\n        \"heart_failure\": \"fluid overload, breathlessness on exertion, swollen legs, reduced ejection fraction\"\n      }\n    },\n    \"gastrointestinal\": \"digestive tract: abdominal pain, nausea, vomiting, bleeding\",\n    \"neurological\": \"brain and nerves: headache, seizure, weakness, numbness\",\n    \"pulmonary\": {\n      \"description\": \"lungs and airways: cough, breathlessness, wheeze, pneumonia\",\n      \"labels\": {\n        \"embolism\": \"pulmonary embolism: sudden breathlessness, pleuritic pain, low oxygen\",\n        \"infection\": \"pneumonia or bronchitis: fever with a productive cough\",\n        \"obstructive\": \"asthma or COPD: wheeze, chronic cough, smoking history\"\n      }\n    }\n  },\n  \"text\": \"62-year-old man with crushing substernal chest pain radiating to the left arm for 40 minutes, sweating, and ST elevation in leads II, III and aVF.\"\n}")
  .asString();
```

```php decision-machine-1_classifyTree_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.milliseconds.ai/v1/decision-machine-1/classify-tree', [
  'body' => '{
  "tree": {
    "cardiovascular": {
      "description": "heart and blood vessels: chest pain, arrhythmia, heart failure, hypertension",
      "labels": {
        "acute_coronary_syndrome": {
          "description": "heart attack or angina: chest pain, ST elevation on the ECG, troponin rise",
          "labels": {
            "nstemi": "non-ST-elevation myocardial infarction: troponin rise without ST elevation",
            "stemi": "ST-elevation myocardial infarction: ST elevation on the ECG",
            "unstable_angina": "chest pain at rest without a troponin rise"
          }
        },
        "arrhythmia": "abnormal heart rhythm: palpitations, atrial fibrillation, bradycardia",
        "heart_failure": "fluid overload, breathlessness on exertion, swollen legs, reduced ejection fraction"
      }
    },
    "gastrointestinal": "digestive tract: abdominal pain, nausea, vomiting, bleeding",
    "neurological": "brain and nerves: headache, seizure, weakness, numbness",
    "pulmonary": {
      "description": "lungs and airways: cough, breathlessness, wheeze, pneumonia",
      "labels": {
        "embolism": "pulmonary embolism: sudden breathlessness, pleuritic pain, low oxygen",
        "infection": "pneumonia or bronchitis: fever with a productive cough",
        "obstructive": "asthma or COPD: wheeze, chronic cough, smoking history"
      }
    }
  },
  "text": "62-year-old man with crushing substernal chest pain radiating to the left arm for 40 minutes, sweating, and ST elevation in leads II, III and aVF."
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp decision-machine-1_classifyTree_example
using RestSharp;

var client = new RestClient("https://api.milliseconds.ai/v1/decision-machine-1/classify-tree");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"tree\": {\n    \"cardiovascular\": {\n      \"description\": \"heart and blood vessels: chest pain, arrhythmia, heart failure, hypertension\",\n      \"labels\": {\n        \"acute_coronary_syndrome\": {\n          \"description\": \"heart attack or angina: chest pain, ST elevation on the ECG, troponin rise\",\n          \"labels\": {\n            \"nstemi\": \"non-ST-elevation myocardial infarction: troponin rise without ST elevation\",\n            \"stemi\": \"ST-elevation myocardial infarction: ST elevation on the ECG\",\n            \"unstable_angina\": \"chest pain at rest without a troponin rise\"\n          }\n        },\n        \"arrhythmia\": \"abnormal heart rhythm: palpitations, atrial fibrillation, bradycardia\",\n        \"heart_failure\": \"fluid overload, breathlessness on exertion, swollen legs, reduced ejection fraction\"\n      }\n    },\n    \"gastrointestinal\": \"digestive tract: abdominal pain, nausea, vomiting, bleeding\",\n    \"neurological\": \"brain and nerves: headache, seizure, weakness, numbness\",\n    \"pulmonary\": {\n      \"description\": \"lungs and airways: cough, breathlessness, wheeze, pneumonia\",\n      \"labels\": {\n        \"embolism\": \"pulmonary embolism: sudden breathlessness, pleuritic pain, low oxygen\",\n        \"infection\": \"pneumonia or bronchitis: fever with a productive cough\",\n        \"obstructive\": \"asthma or COPD: wheeze, chronic cough, smoking history\"\n      }\n    }\n  },\n  \"text\": \"62-year-old man with crushing substernal chest pain radiating to the left arm for 40 minutes, sweating, and ST elevation in leads II, III and aVF.\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift decision-machine-1_classifyTree_example
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "tree": [
    "cardiovascular": [
      "description": "heart and blood vessels: chest pain, arrhythmia, heart failure, hypertension",
      "labels": [
        "acute_coronary_syndrome": [
          "description": "heart attack or angina: chest pain, ST elevation on the ECG, troponin rise",
          "labels": [
            "nstemi": "non-ST-elevation myocardial infarction: troponin rise without ST elevation",
            "stemi": "ST-elevation myocardial infarction: ST elevation on the ECG",
            "unstable_angina": "chest pain at rest without a troponin rise"
          ]
        ],
        "arrhythmia": "abnormal heart rhythm: palpitations, atrial fibrillation, bradycardia",
        "heart_failure": "fluid overload, breathlessness on exertion, swollen legs, reduced ejection fraction"
      ]
    ],
    "gastrointestinal": "digestive tract: abdominal pain, nausea, vomiting, bleeding",
    "neurological": "brain and nerves: headache, seizure, weakness, numbness",
    "pulmonary": [
      "description": "lungs and airways: cough, breathlessness, wheeze, pneumonia",
      "labels": [
        "embolism": "pulmonary embolism: sudden breathlessness, pleuritic pain, low oxygen",
        "infection": "pneumonia or bronchitis: fever with a productive cough",
        "obstructive": "asthma or COPD: wheeze, chronic cough, smoking history"
      ]
    ]
  ],
  "text": "62-year-old man with crushing substernal chest pain radiating to the left arm for 40 minutes, sweating, and ST elevation in leads II, III and aVF."
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.milliseconds.ai/v1/decision-machine-1/classify-tree")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```