---
type: api
title: Start a trained model deployment
description: It allocates the model to every machine learning node.
url: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/v8/operation/operation-ml-start-trained-model-deployment
resource: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/v8/operation/operation-ml-start-trained-model-deployment
products:
  - Elasticsearch
---

# Start a trained model deployment

Availability: Generally available since 8.0

## Paths

- `POST` `/_ml/trained_models/{model_id}/deployment/_start`

#### Path parameters

- `model_id` (string) — required
  The unique identifier of the trained model. Currently, only PyTorch models are supported.

## Description

It allocates the model to every machine learning node.

## Required authorization

- Cluster privileges: `manage_ml`

## Authentication

- Api key: `Authorization: <value>`
  Elasticsearch APIs support key-based authentication.
  You must create an API key and use the encoded value in the request header.
  For example:
  
  
  ```
  curl -X GET "${ES_URL}/_cat/indices?v=true" \
    -H "Authorization: ApiKey ${API_KEY}"
  ```
  
  To get API keys, use the `/_security/api_key` APIs.
- Basic: `Authorization: Basic <credentials>`
- Bearer: `Authorization: Bearer <token>`
  Elasticsearch APIs support the use of bearer tokens in the `Authorization` HTTP header to authenticate with the API.
  For examples, refer to [Token-based authentication services](https://www.elastic.co/guide/en/elasticsearch/reference/current/token-authentication-services.html)

## Query string parameters

- `cache_size` (number | string) — optional
  The inference cache size (in memory outside the JVM heap) per node for the model.
The default value is the same size as the `model_size_bytes`. To disable the cache,
`0b` can be provided.
- `deployment_id` (string) — optional
  A unique identifier for the deployment of the model.
- `number_of_allocations` (number · default: 1) — optional
  The number of model allocations on each node where the model is deployed.
All allocations on a node share the same copy of the model in memory but use
a separate set of threads to evaluate the model.
Increasing this value generally increases the throughput.
If this setting is greater than the number of hardware threads
it will automatically be changed to a value less than the number of hardware threads.
If adaptive_allocations is enabled, do not set this value, because it’s automatically set.
- `priority` (enum) — optional
  The deployment priority
  Values: `normal`, `low`
- `queue_capacity` (number · default: 1024) — optional
  Specifies the number of inference requests that are allowed in the queue. After the number of requests exceeds
this value, new requests are rejected with a 429 error.
- `threads_per_allocation` (number · default: 1) — optional
  Sets the number of threads used by each model allocation during inference. This generally increases
the inference speed. The inference process is a compute-bound process; any number
greater than the number of available hardware threads on the machine does not increase the
inference speed. If this setting is greater than the number of hardware threads
it will automatically be changed to a value less than the number of hardware threads.
- `timeout` (string · default: 20s) — optional
  Specifies the amount of time to wait for the model to deploy.
- `wait_for` (enum · default: started) — optional
  Specifies the allocation status to wait for before returning.

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`

## Request body

`application/json`

- `adaptive_allocations` (object) — optional
  Adaptive allocations configuration. When enabled, the number of allocations
is set based on the current load.
If adaptive_allocations is enabled, do not set the number of allocations manually.
  - `enabled` (boolean) — required
    If true, adaptive_allocations is enabled
  - `min_number_of_allocations` (number) — optional
    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) — optional
    Specifies the maximum number of allocations to scale to.
If set, it must be greater than or equal to min_number_of_allocations.

## Response

`application/json`

- `assignment` (object)
  - `adaptive_allocations` (union oneOf) — nullable
    - **{ enabled, min_number_of_allocations, max_number_of_allocations }**
      - `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.
    - **string**
  - `assignment_state` (enum)
    The overall assignment state.

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`
  - `max_assigned_allocations` (number)
  - `reason` (string)
  - `routing_table` (map string to object)
    The allocation state for each node.
    Map values (object)
    - `reason` (string)
      The reason for the current state. It is usually populated only when the
`routing_state` is `failed`.
    - `routing_state` (enum)
      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`
    - `current_allocations` (number)
      Current number of allocations.
    - `target_allocations` (number)
      Target number of allocations.
  - `start_time` (union)
    The timestamp when the deployment started.
  - `task_parameters` (object)
    - `model_bytes` (number | string)
      The size of the trained model in bytes.
    - `model_id` (string)
      The unique identifier for the trained model.
    - `deployment_id` (string)
      The unique identifier for the trained model deployment.
    - `cache_size` (number | string)
      The size of the trained model cache.
    - `number_of_allocations` (number)
      The total number of allocations this model is assigned across ML nodes.
    - `priority` (enum)
      Values: `normal`, `low`
    - `per_deployment_memory_bytes` (number | string)
    - `per_allocation_memory_bytes` (number | string)
    - `queue_capacity` (number)
      Number of inference requests are allowed in the queue at a time.
    - `threads_per_allocation` (number)
      Number of threads per allocation.
## Code examples

#### Console

```console
POST _ml/trained_models/elastic__distilbert-base-uncased-finetuned-conll03-english/deployment/_start?wait_for=started&timeout=1m
```

#### JavaScript

```javascript
const response = await client.ml.startTrainedModelDeployment({
  model_id: "elastic__distilbert-base-uncased-finetuned-conll03-english",
  wait_for: "started",
  timeout: "1m",
});
```

#### Python

```python
resp = client.ml.start_trained_model_deployment(
    model_id="elastic__distilbert-base-uncased-finetuned-conll03-english",
    wait_for="started",
    timeout="1m",
)
```

#### curl

```curl
curl -X POST "$ELASTICSEARCH_URL/_ml/trained_models/elastic__distilbert-base-uncased-finetuned-conll03-english/deployment/_start?wait_for=started&timeout=1m" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY"
```

#### Java

```java
client.ml().startTrainedModelDeployment(s -> s
    .modelId("elastic__distilbert-base-uncased-finetuned-conll03-english")
    .timeout(t -> t
        .offset(1)
    )
    .waitFor(DeploymentAllocationState.Started)
);
```

#### C#

```c#
var response = await client.MachineLearning
    .StartTrainedModelDeploymentAsync(modelId: "elastic__distilbert-base-uncased-finetuned-conll03-english", d1 => d1
        .Timeout("1m")
        .WaitFor(DeploymentAllocationState.Started)
    );
```

#### PHP

```php
$resp = $client->ml()->startTrainedModelDeployment([
    "model_id" => "elastic__distilbert-base-uncased-finetuned-conll03-english",
    "wait_for" => "started",
    "timeout" => "1m",
]);
```

#### Ruby

```ruby
response = client.ml.start_trained_model_deployment(
  model_id: "elastic__distilbert-base-uncased-finetuned-conll03-english",
  wait_for: "started",
  timeout: "1m"
)
```

