---
type: api
title: Perform text embedding inference on the service
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/operation/operation-inference-text-embedding
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/operation/operation-inference-text-embedding
products:
  - Elasticsearch
---

# Perform text embedding inference on the service

Availability: 8.11+

## Paths

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

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

#### Path Parameters

- `inference_id` (string Id)
  The inference Id

## Query String Parameters

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

## Request Body

`application/json`

- `input` (union string | [] string) — required
  Inference input.
Either a string or an array of strings.
- `input_type` (string) — optional
  The input data type for the text embedding model. 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`

- `text_embedding_bytes` ([] DenseEmbeddingByteResult)
  - `embedding` (DenseByteVector)
- `text_embedding_bits` ([] DenseEmbeddingByteResult)
  - `embedding` (DenseByteVector)
- `text_embedding` ([] DenseEmbeddingResult)
  - `embedding` (DenseVector)
## Code Examples

#### Console

```console
POST _inference/text_embedding/my-cohere-endpoint
{
  "input": "The sky above the port was the color of television tuned to a dead channel.",
  "input_type": "ingest"
}
```

#### JavaScript

```javascript
const response = await client.inference.textEmbedding({
  inference_id: "my-cohere-endpoint",
  input:
    "The sky above the port was the color of television tuned to a dead channel.",
  input_type: "ingest",
});
```

#### Python

```python
resp = client.inference.text_embedding(
    inference_id="my-cohere-endpoint",
    input="The sky above the port was the color of television tuned to a dead channel.",
    input_type="ingest",
)
```

#### curl

```curl
curl -X POST "$ELASTICSEARCH_URL/_inference/text_embedding/my-cohere-endpoint" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "input": "The sky above the port was the color of television tuned to a dead channel.",
    "input_type": "ingest"
  }'
```

#### Java

```java
client.inference().textEmbedding(t -> t
    .inferenceId("my-cohere-endpoint")
    .input("The sky above the port was the color of television tuned to a dead channel.")
    .inputType("ingest")
);
```

#### C#

```c#
var response = await client.Inference
    .TextEmbeddingAsync(inferenceId: "my-cohere-endpoint", d1 => d1
        .Input("The sky above the port was the color of television tuned to a dead channel.")
        .InputType("ingest")
    );
```

#### PHP

```php
$resp = $client->inference()->textEmbedding([
    "inference_id" => "my-cohere-endpoint",
    "body" => [
        "input" => "The sky above the port was the color of television tuned to a dead channel.",
        "input_type" => "ingest",
    ],
]);
```

#### Ruby

```ruby
response = client.inference.text_embedding(
  inference_id: "my-cohere-endpoint",
  body: {
    "input": "The sky above the port was the color of television tuned to a dead channel.",
    "input_type": "ingest"
  }
)
```

## Response Examples

#### Text embedding task

An abbreviated response from `POST _inference/text_embedding/my-text-embedding-endpoint`.

```json
{
  "text_embedding": [
    {
      "embedding": [
        0.018569946,
        -0.036895752,
        0.01486969,
        -0.0045204163,
        -0.04385376,
        0.0075950623,
        0.04260254,
        -0.004005432,
        0.007865906,
        0.030792236,
        -0.050476074,
        0.011795044,
        -0.011642456,
        -0.010070801
      ]
    }
  ]
}
```

