---
type: api
title: Create an inference endpoint
description: **All methods and paths for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/operation/operation-inference-put
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/operation/operation-inference-put
products:
  - Elasticsearch
---

# Create an inference endpoint


Availability: 8.11+

## Paths

- `PUT` `/_inference/{task_type}/{inference_id}`
- `PUT` `/_inference/{inference_id}`

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

#### Path Parameters

- `task_type` (enum TaskType) — optional, leave it out to use `/_inference/{inference_id}`
  The task type. Refer to the integration list in the API description for the available task types.
  Values: `sparse_embedding`, `text_embedding`, `rerank`, `completion`, `chat_completion`
- `inference_id` (string Id)
  The inference Id

## Description

IMPORTANT: The inference APIs enable you to use certain services, such as built-in machine learning models (ELSER, E5), models uploaded through Eland, Cohere, OpenAI, Mistral, Azure OpenAI, Google AI Studio, Google Vertex AI, Anthropic, Watsonx.ai, or Hugging Face.
For built-in models and models uploaded through Eland, the inference APIs offer an alternative way to use and manage trained models.
However, if you do not plan to use the inference APIs to use these models or if you want to use non-NLP models, use the machine learning trained model APIs.

The following integrations are available through the inference API. You can find the available task types next to the integration name:
* AlibabaCloud AI Search (`completion`, `rerank`, `sparse_embedding`, `text_embedding`)
* Amazon Bedrock (`completion`, `text_embedding`)
* Amazon SageMaker (`chat_completion`, `completion`, `rerank`, `sparse_embedding`, `text_embedding`)
* Anthropic (`completion`)
* Azure AI Studio (`completion`, `text_embedding`)
* Azure OpenAI (`completion`, `text_embedding`)
* Cohere (`completion`, `rerank`, `text_embedding`)
* DeepSeek (`chat_completion`, `completion`)
* Elasticsearch (`rerank`, `sparse_embedding`, `text_embedding` - this service is for built-in models and models uploaded through Eland)
* ELSER (`sparse_embedding`)
* Google AI Studio (`completion`, `text_embedding`)
* Google Vertex AI (`chat_completion`, `completion`, `rerank`, `text_embedding`)
* Hugging Face (`chat_completion`, `completion`, `rerank`, `text_embedding`)
* JinaAI (`rerank`, `text_embedding`)
* Llama (`chat_completion`, `completion`, `text_embedding`)
* Mistral (`chat_completion`, `completion`, `text_embedding`)
* OpenAI (`chat_completion`, `completion`, `text_embedding`)
* VoyageAI (`rerank`, `text_embedding`)
* Watsonx (`rerank`, `text_embedding`)

## Required authorization

* Cluster privileges: `manage_inference`

## Query String Parameters

- `timeout` (string Duration · default: 30s)
  Specifies the amount of time to wait for the inference endpoint to be created.

## Request Body

`application/json`

- `chunking_settings` ({} InferenceChunkingSettings) — optional
  Chunking configuration object
  - `max_chunk_size` (number · default: 250) — optional
    The maximum size of a chunk in words.
This value cannot be higher than `300` or lower than `20` (for `sentence` strategy) or `10` (for `word` strategy).
  - `overlap` (number · default: 100) — optional
    The number of overlapping words for chunks.
It is applicable only to a `word` chunking strategy.
This value cannot be higher than half the `max_chunk_size` value.
  - `sentence_overlap` (number · default: 1) — optional
    The number of overlapping sentences for chunks.
It is applicable only for a `sentence` chunking strategy.
It can be either `1` or `0`.
  - `strategy` (string · default: sentence) — optional
    The chunking strategy: `sentence` or `word`.
- `service` (string) — required
  The service type
- `service_settings` (ServiceSettings) — required
  Settings specific to the service
- `task_settings` (TaskSettings) — optional
  Task settings specific to the service and task type

## Response

`application/json`

- `chunking_settings` ({} InferenceChunkingSettings)
  Chunking configuration object
  - `max_chunk_size` (number · default: 250)
    The maximum size of a chunk in words.
This value cannot be higher than `300` or lower than `20` (for `sentence` strategy) or `10` (for `word` strategy).
  - `overlap` (number · default: 100)
    The number of overlapping words for chunks.
It is applicable only to a `word` chunking strategy.
This value cannot be higher than half the `max_chunk_size` value.
  - `sentence_overlap` (number · default: 1)
    The number of overlapping sentences for chunks.
It is applicable only for a `sentence` chunking strategy.
It can be either `1` or `0`.
  - `strategy` (string · default: sentence)
    The chunking strategy: `sentence` or `word`.
- `service` (string)
  The service type
- `service_settings` (ServiceSettings)
  Settings specific to the service
- `task_settings` (TaskSettings)
  Task settings specific to the service and task type
- `inference_id` (string)
  The inference Id
- `task_type` (enum TaskType)
  The task type
  Values: `sparse_embedding`, `text_embedding`, `rerank`, `completion`, `chat_completion`
## Code Examples

#### Console

```console
PUT _inference/rerank/my-rerank-model
{
 "service": "cohere",
 "service_settings": {
   "model_id": "rerank-english-v3.0",
   "api_key": "{{COHERE_API_KEY}}"
 }
}
```

#### JavaScript

```javascript
const response = await client.inference.put({
  task_type: "rerank",
  inference_id: "my-rerank-model",
  inference_config: {
    service: "cohere",
    service_settings: {
      model_id: "rerank-english-v3.0",
      api_key: "{{COHERE_API_KEY}}",
    },
  },
});
```

#### Python

```python
resp = client.inference.put(
    task_type="rerank",
    inference_id="my-rerank-model",
    inference_config={
        "service": "cohere",
        "service_settings": {
            "model_id": "rerank-english-v3.0",
            "api_key": "{{COHERE_API_KEY}}"
        }
    },
)
```

#### curl

```curl
curl -X PUT "$ELASTICSEARCH_URL/_inference/rerank/my-rerank-model" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "service": "cohere",
    "service_settings": {
      "model_id": "rerank-english-v3.0",
      "api_key": "{{COHERE_API_KEY}}"
    }
  }'
```

#### Java

```java
client.inference().put(p -> p
    .inferenceId("my-rerank-model")
    .taskType(TaskType.Rerank)
    .inferenceConfig(i -> i
        .service("cohere")
        .serviceSettings(JsonData.fromJson("{\"model_id\":\"rerank-english-v3.0\",\"api_key\":\"{{COHERE_API_KEY}}\"}"))
    )
);
```

#### C#

```c#
var response = await client.Inference
    .PutAsync(new PutInferenceRequest()
    {
        InferenceId = "my-rerank-model",
        TaskType = TaskType.Rerank,
        InferenceConfig = new()
        {
            Service = "cohere",
            ServiceSettings = JsonSerializer.Deserialize<JsonElement>("""
            {
              "model_id": "rerank-english-v3.0",
              "api_key": "{{COHERE_API_KEY}}"
            }
            """)
        }
    });
```

#### PHP

```php
$resp = $client->inference()->put([
    "task_type" => "rerank",
    "inference_id" => "my-rerank-model",
    "body" => [
        "service" => "cohere",
        "service_settings" => [
            "model_id" => "rerank-english-v3.0",
            "api_key" => "{{COHERE_API_KEY}}",
        ],
    ],
]);
```

#### Ruby

```ruby
response = client.inference.put(
  task_type: "rerank",
  inference_id: "my-rerank-model",
  body: {
    "service": "cohere",
    "service_settings": {
      "model_id": "rerank-english-v3.0",
      "api_key": "{{COHERE_API_KEY}}"
    }
  }
)
```

