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

# Perform text embedding inference on the service

Availability: Generally available since 8.11

## Paths

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

#### Path parameters

- `inference_id` (string) — required
  The inference Id

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

- `timeout` (string · default: 30s) — optional
  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` (object) — optional
  Optional task settings

## Response

`application/json`

- `text_embedding_bytes` (object[])
  - `embedding` (number[])
- `text_embedding_bits` (object[])
  - `embedding` (number[])
- `text_embedding` (object[])
  - `embedding` (number[])
## 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.")
    .taskSettings(JsonData.fromJson("{\"input_type\":\"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
      ]
    }
  ]
}
```

