Perform inference on the service

Auth

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.

Note

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 privileges

Cluster privileges monitor_inference

Path parameters

task_type enum optional

The type of inference task that the model performs.

Leave it out to use /_inference/{inference_id}.

Values: sparse_embedding text_embedding rerank completion chat_completion embedding document_extraction decision
inference_id string required

The unique identifier for the inference endpoint.

Query parameters

timeout string · default: 30s

The amount of time to wait for the inference request to complete.

Request body

query string

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.

Note

Inference endpoints for the completion task type currently only support a single string as input.

input_type string

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.
Note

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 object

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 object[]
embedding number[] required
embeddings_bits object[]
embedding number[] required
embeddings object[]
embedding number[] required
text_embedding_bytes object[]
embedding number[] required
text_embedding_bits object[]
embedding number[] required
text_embedding object[]
embedding number[] required
sparse_embedding object[]
is_truncated boolean required

Indicates if the text input was truncated in the request sent to the service

embedding object required
completion object[]
result string required
rerank object[]
index number required
relevance_score number required
text string