---
type: api
title: Perform inference on the service
description: **All methods and paths for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/operation/operation-inference-inference
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/operation/operation-inference-inference
products:
  - Elasticsearch
---

# Perform inference on the service


Availability: 8.11+

## Paths

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

- [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

- `task_type` (enum TaskType) — optional, leave it out to use `/_inference/{inference_id}`
  The type of inference task that the model performs.
  Values: `sparse_embedding`, `text_embedding`, `rerank`, `completion`, `chat_completion`, `embedding`
- `inference_id` (string Id)
  The unique identifier for the inference endpoint.

## Description

This API enables you to use machine learning models to perform specific tasks on data that you provide as an input.
It returns a response with the results of the tasks.
The inference endpoint you use can perform one specific task that has been defined when the endpoint was created with the create inference API.

For details about using this API with a service, such as Amazon Bedrock, Anthropic, or HuggingFace, refer to the service-specific documentation.

> info
> The inference APIs enable you to use certain services, such as built-in machine learning models (ELSER, E5), models uploaded through Eland, Cohere, OpenAI, Azure, 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.

## Required authorization

* Cluster privileges: `monitor_inference`

## Query String Parameters

- `timeout` (string Duration · default: 30s)
  The amount of time to wait for the inference request to complete.

## Request Body

`application/json`

- `query` (string) — optional
  The query input, which is required only for the `rerank` task.
It is not required for other tasks.
- `input` (union string | [] string) — required
  The text on which you want to perform the inference task.
It can be a single string or an array.

> info
> Inference endpoints for the `completion` task type currently only support a single string as input.
- `input_type` (string) — optional
  Specifies the input data type for the embedding model. The `input_type` parameter only applies to Inference Endpoints with the `embedding` or `text_embedding` task type. Possible values include:
* `SEARCH`
* `INGEST`
* `CLASSIFICATION`
* `CLUSTERING`
Not all services support all values. Unsupported values will trigger a validation exception.
Accepted values depend on the configured inference service, refer to the relevant service-specific documentation for more info.

> info
> The `input_type` parameter specified on the root level of the request body will take precedence over the `input_type` parameter specified in `task_settings`.
- `task_settings` (TaskSettings) — optional
  Task settings for the individual inference request.
These settings are specific to the task type you specified and override the task settings specified when initializing the service.

## Response

`application/json`

- `embeddings_bytes` ([] DenseEmbeddingByteResult)
  - `embedding` (DenseByteVector)
- `embeddings_bits` ([] DenseEmbeddingByteResult)
  - `embedding` (DenseByteVector)
- `embeddings` ([] DenseEmbeddingResult)
  - `embedding` (DenseVector)
- `text_embedding_bytes` ([] DenseEmbeddingByteResult)
  - `embedding` (DenseByteVector)
- `text_embedding_bits` ([] DenseEmbeddingByteResult)
  - `embedding` (DenseByteVector)
- `text_embedding` ([] DenseEmbeddingResult)
  - `embedding` (DenseVector)
- `sparse_embedding` ([] SparseEmbeddingResult)
  - `is_truncated` (boolean)
    Indicates if the text input was truncated in the request sent to the service
  - `embedding` (SparseVector)
- `completion` ([] CompletionResult)
  - `result` (string)
- `rerank` ([] RankedDocument)
  - `index` (number)
  - `relevance_score` (number)
  - `text` (string)
## Code Examples

#### Console

```console
POST /_inference/{task_type}/{inference_id}
```

#### curl

```curl
curl -X POST "/_inference/{task_type}/{inference_id}"
```

