---
type: api
title: Get trained models usage info
description: **All methods and paths for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/operation/operation-ml-get-trained-models-stats
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/operation/operation-ml-get-trained-models-stats
products:
  - Elasticsearch
---

# Get trained models usage info


Availability: 7.10+

## Paths

- `GET` `/_ml/trained_models/{model_id}/_stats`
- `GET` `/_ml/trained_models/_stats`

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/authentication#apikeyauth)
- [Basic auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/authentication#basicauth)
- [Bearer auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/authentication#bearerauth)

#### Path Parameters

- `model_id` (union Id | [] Id) — optional, leave it out to use `/_ml/trained_models/_stats`
  The unique identifier of the trained model or a model alias. It can be a
comma-separated list or a wildcard expression.

## Description

You can get usage information for multiple trained
models in a single API request by using a comma-separated list of model IDs or a wildcard expression.

## Required authorization

* Cluster privileges: `monitor_ml`

## Query String Parameters

- `allow_no_match` (boolean · default: true)
  Specifies what to do when the request:

- Contains wildcard expressions and there are no models that match.
- Contains the _all string or no identifiers and there are no matches.
- Contains wildcard expressions and there are only partial matches.

If true, it returns an empty array when there are no matches and the
subset of results when there are partial matches.
- `from` (number · default: 0)
  Skips the specified number of models.
- `size` (number · default: 100)
  Specifies the maximum number of models to obtain.

## Response

`application/json`

- `count` (number)
  The total number of trained model statistics that matched the requested ID patterns. Could be higher than the number of items in the trained_model_stats array as the size of the array is restricted by the supplied size parameter.
- `trained_model_stats` ([] TrainedModelStats)
  An array of trained model statistics, which are sorted by the model_id value in ascending order.
  - `deployment_stats` ({} TrainedModelDeploymentStats)
    A collection of deployment stats, which is present when the models are deployed.
    - `adaptive_allocations` ({} AdaptiveAllocationsSettings)
      - `enabled` (boolean)
        If true, adaptive_allocations is enabled
      - `min_number_of_allocations` (number)
        Specifies the minimum number of allocations to scale to.
If set, it must be greater than or equal to 0.
If not defined, the deployment scales to 0.
      - `max_number_of_allocations` (number)
        Specifies the maximum number of allocations to scale to.
If set, it must be greater than or equal to min_number_of_allocations.
    - `allocation_status` ({} TrainedModelDeploymentAllocationStatus)
      The detailed allocation status for the deployment.
      - `allocation_count` (number)
        The current number of nodes where the model is allocated.
      - `state` (enum DeploymentAllocationState)
        The detailed allocation state related to the nodes.

Supported values include:
  - `started`: The trained model is started on at least one node.
  - `starting`: Trained model deployment is starting but it is not yet deployed on any nodes.
  - `fully_allocated`: Trained model deployment has started on all valid nodes.
        Values: `started`, `starting`, `fully_allocated`
      - `target_allocation_count` (number)
        The desired number of nodes for model allocation.
    - `cache_size` (number | string ByteSize)
    - `deployment_id` (string Id)
      The unique identifier for the trained model deployment.
    - `error_count` (number)
      The sum of `error_count` for all nodes in the deployment.
    - `inference_count` (number)
      The sum of `inference_count` for all nodes in the deployment.
    - `model_id` (string Id)
      The unique identifier for the trained model.
    - `nodes` ([] TrainedModelDeploymentNodesStats)
      The deployment stats for each node that currently has the model allocated.
In serverless, stats are reported for a single unnamed virtual node.
      - `average_inference_time_ms` (DurationValueUnitFloatMillis)
        The average time for each inference call to complete on this node.
      - `average_inference_time_ms_last_minute` (DurationValueUnitFloatMillis)
      - `average_inference_time_ms_excluding_cache_hits` (DurationValueUnitFloatMillis)
        The average time for each inference call to complete on this node, excluding cache
      - `average_inference_process_memory_rss_bytes` (number | string ByteSize)
      - `error_count` (number)
        The number of errors when evaluating the trained model.
      - `inference_count` (number)
        The total number of inference calls made against this node for this model.
      - `inference_cache_hit_count` (number)
      - `inference_cache_hit_count_last_minute` (number)
      - `last_access` (EpochTimeUnitMillis)
        The epoch time stamp of the last inference call for the model on this node.
      - `node` (DiscoveryNode)
        Information pertaining to the node.
      - `number_of_allocations` (number)
        The number of allocations assigned to this node.
      - `number_of_pending_requests` (number)
        The number of inference requests queued to be processed.
      - `peak_throughput_per_minute` (number)
      - `rejected_execution_count` (number)
        The number of inference requests that were not processed because the queue was full.
      - `routing_state` ({} TrainedModelAssignmentRoutingStateAndReason)
        The current routing state and reason for the current routing state for this allocation.
        - `reason` (string)
          The reason for the current state. It is usually populated only when the
`routing_state` is `failed`.
        - `routing_state` (enum RoutingState)
          The current routing state.

Supported values include:
  - `failed`: The allocation attempt failed.
  - `started`: The trained model is allocated and ready to accept inference requests.
  - `starting`: The trained model is attempting to allocate on this node; inference requests are not yet accepted.
  - `stopped`: The trained model is fully deallocated from this node.
  - `stopping`: The trained model is being deallocated from this node.
          Values: `failed`, `started`, `starting`, `stopped`, `stopping`
      - `start_time` (EpochTimeUnitMillis)
        The epoch timestamp when the allocation started.
      - `threads_per_allocation` (number)
        The number of threads used by each allocation during inference.
      - `throughput_last_minute` (number)
      - `timeout_count` (number)
        The number of inference requests that timed out before being processed.
    - `number_of_allocations` (number)
      The number of allocations requested.
    - `peak_throughput_per_minute` (number)
    - `priority` (enum TrainingPriority)
      Values: `normal`, `low`
    - `queue_capacity` (number)
      The number of inference requests that can be queued before new requests are rejected.
    - `rejected_execution_count` (number)
      The sum of `rejected_execution_count` for all nodes in the deployment.
Individual nodes reject an inference request if the inference queue is full.
The queue size is controlled by the `queue_capacity` setting in the start
trained model deployment API.
    - `reason` (string)
      The reason for the current deployment state. Usually only populated when
the model is not deployed to a node.
    - `start_time` (EpochTimeUnitMillis)
      The epoch timestamp when the deployment started.
    - `state` (enum DeploymentAssignmentState)
      The overall state of the deployment.

Supported values include:
  - `started`: The deployment is usable; at least one node has the model allocated.
  - `starting`: The deployment has recently started but is not yet usable; the model is not allocated on any nodes.
  - `stopping`: The deployment is preparing to stop and deallocate the model from the relevant nodes.
  - `failed`: The deployment is on a failed state and must be re-deployed.
      Values: `started`, `starting`, `stopping`, `failed`
    - `threads_per_allocation` (number)
      The number of threads used be each allocation during inference.
    - `timeout_count` (number)
      The sum of `timeout_count` for all nodes in the deployment.
  - `inference_stats` ({} TrainedModelInferenceStats)
    A collection of inference stats fields.
    - `cache_miss_count` (number)
      The number of times the model was loaded for inference and was not retrieved from the cache.
If this number is close to the `inference_count`, the cache is not being appropriately used.
This can be solved by increasing the cache size or its time-to-live (TTL).
Refer to general machine learning settings for the appropriate settings.
    - `failure_count` (number)
      The number of failures when using the model for inference.
    - `inference_count` (number)
      The total number of times the model has been called for inference.
This is across all inference contexts, including all pipelines.
    - `missing_all_fields_count` (number)
      The number of inference calls where all the training features for the model were missing.
    - `timestamp` (EpochTimeUnitMillis)
      The time when the statistics were last updated.
  - `ingest` (map string to object)
    A collection of ingest stats for the model across all nodes.
The values are summations of the individual node statistics.
The format matches the ingest section in the nodes stats API.
  - `model_id` (string Id)
    The unique identifier of the trained model.
  - `model_size_stats` ({} TrainedModelSizeStats)
    A collection of model size stats.
    - `model_size_bytes` (number | string ByteSize)
      The size of the model in bytes.
    - `required_native_memory_bytes` (number | string ByteSize)
      The amount of memory required to load the model in bytes.
  - `pipeline_count` (number)
    The number of ingest pipelines that currently refer to the model.
## Code Examples

#### Console

```console
GET _ml/trained_models/_stats
```

#### JavaScript

```javascript
const response = await client.ml.getTrainedModelsStats();
```

#### Python

```python
resp = client.ml.get_trained_models_stats()
```

#### curl

```curl
curl -X GET "$ELASTICSEARCH_URL/_ml/trained_models/_stats" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY"
```

#### Java

```java
client.ml().getTrainedModelsStats(g -> g);
```

#### C#

```c#
var response = await client.MachineLearning.GetTrainedModelsStatsAsync();
```

#### PHP

```php
$resp = $client->ml()->getTrainedModelsStats();
```

#### Ruby

```ruby
response = client.ml.get_trained_models_stats
```

