---
type: api
title: Create an Azure OpenAI inference endpoint
description: Create an inference endpoint to perform an inference task with the `azureopenai` service.
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/operation/operation-inference-put-azureopenai
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/operation/operation-inference-put-azureopenai
products:
  - Elasticsearch
---

# Create an Azure OpenAI inference endpoint

Availability: 8.14+

## Paths

- `PUT` `/_inference/{task_type}/{azureopenai_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 AzureOpenAITaskType)
  The type of the inference task that the model will perform.
NOTE: The `chat_completion` task type only supports streaming and only through the _stream API.
  Values: `completion`, `text_embedding`
- `azureopenai_inference_id` (string Id)
  The unique identifier of the inference endpoint.

## Description

Create an inference endpoint to perform an inference task with the `azureopenai` service.

The list of chat completion models that you can choose from in your Azure OpenAI deployment include:

* [GPT-4 and GPT-4 Turbo models](https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/models?tabs=global-standard%2Cstandard-chat-completions#gpt-4-and-gpt-4-turbo-models)
* [GPT-3.5](https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/models?tabs=global-standard%2Cstandard-chat-completions#gpt-35)

The list of embeddings models that you can choose from in your deployment can be found in the [Azure models documentation](https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/models?tabs=global-standard%2Cstandard-chat-completions#embeddings).

## 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
  The 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` (enum AzureOpenAIServiceType) — required
  The type of service supported for the specified task type. In this case, `azureopenai`.
  Values: `azureopenai`
- `service_settings` ({} AzureOpenAIServiceSettings) — required
  Settings used to install the inference model. These settings are specific to the `azureopenai` service.
  - `api_key` (string) — optional
    A valid API key for your Azure OpenAI account.
You must specify either `api_key` or `entra_id`.
If you do not provide either or you provide both, you will receive an error when you try to create your model.

IMPORTANT: You need to provide the API key only once, during the inference model creation.
The get inference endpoint API does not retrieve your API key.
  - `api_version` (string) — required
    The Azure API version ID to use.
It is recommended to use the latest supported non-preview version.
  - `deployment_id` (string) — required
    The deployment name of your deployed models.
Your Azure OpenAI deployments can be found though the Azure OpenAI Studio portal that is linked to your subscription.
  - `entra_id` (string) — optional
    A valid Microsoft Entra token.
You must specify either `api_key` or `entra_id`.
If you do not provide either or you provide both, you will receive an error when you try to create your model.
  - `rate_limit` ({} RateLimitSetting) — optional
    This setting helps to minimize the number of rate limit errors returned from Azure.
The `azureopenai` service sets a default number of requests allowed per minute depending on the task type.
For `text_embedding`, it is set to `1440`.
For `completion`, it is set to `120`.
    - `requests_per_minute` (number) — optional
      The number of requests allowed per minute.
  - `resource_name` (string) — required
    The name of your Azure OpenAI resource.
You can find this from the list of resources in the Azure Portal for your subscription.
- `task_settings` ({} AzureOpenAITaskSettings) — optional
  Settings to configure the inference task.
These settings are specific to the task type you specified.
  - `user` (string) — optional
    For a `completion` or `text_embedding` task, specify the user issuing the request.
This information can be used for abuse detection.

## 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 TaskTypeAzureOpenAI)
  The task type
  Values: `text_embedding`, `completion`
## Code Examples

#### Console

```console
PUT _inference/text_embedding/azure_openai_embeddings
{
    "service": "azureopenai",
    "service_settings": {
        "api_key": "Api-Key",
        "resource_name": "Resource-name",
        "deployment_id": "Deployment-id",
        "api_version": "2024-02-01"
    }
}
```

#### JavaScript

```javascript
const response = await client.inference.put({
  task_type: "text_embedding",
  inference_id: "azure_openai_embeddings",
  inference_config: {
    service: "azureopenai",
    service_settings: {
      api_key: "Api-Key",
      resource_name: "Resource-name",
      deployment_id: "Deployment-id",
      api_version: "2024-02-01",
    },
  },
});
```

#### Python

```python
resp = client.inference.put(
    task_type="text_embedding",
    inference_id="azure_openai_embeddings",
    inference_config={
        "service": "azureopenai",
        "service_settings": {
            "api_key": "Api-Key",
            "resource_name": "Resource-name",
            "deployment_id": "Deployment-id",
            "api_version": "2024-02-01"
        }
    },
)
```

#### curl

```curl
curl -X PUT "$ELASTICSEARCH_URL/_inference/text_embedding/azure_openai_embeddings" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "service": "azureopenai",
    "service_settings": {
      "api_key": "Api-Key",
      "resource_name": "Resource-name",
      "deployment_id": "Deployment-id",
      "api_version": "2024-02-01"
    }
  }'
```

#### Java

```java
client.inference().put(p -> p
    .inferenceId("azure_openai_embeddings")
    .taskType(TaskType.TextEmbedding)
    .inferenceConfig(i -> i
        .service("azureopenai")
        .serviceSettings(JsonData.fromJson("{\"api_key\":\"Api-Key\",\"resource_name\":\"Resource-name\",\"deployment_id\":\"Deployment-id\",\"api_version\":\"2024-02-01\"}"))
    )
);
```

#### C#

```c#
var response = await client.Inference
    .PutAsync(new PutInferenceRequest()
    {
        InferenceId = "azure_openai_embeddings",
        TaskType = TaskType.TextEmbedding,
        InferenceConfig = new()
        {
            Service = "azureopenai",
            ServiceSettings = JsonSerializer.Deserialize<JsonElement>("""
            {
              "api_key": "Api-Key",
              "resource_name": "Resource-name",
              "deployment_id": "Deployment-id",
              "api_version": "2024-02-01"
            }
            """)
        }
    });
```

#### PHP

```php
$resp = $client->inference()->put([
    "task_type" => "text_embedding",
    "inference_id" => "azure_openai_embeddings",
    "body" => [
        "service" => "azureopenai",
        "service_settings" => [
            "api_key" => "Api-Key",
            "resource_name" => "Resource-name",
            "deployment_id" => "Deployment-id",
            "api_version" => "2024-02-01",
        ],
    ],
]);
```

#### Ruby

```ruby
response = client.inference.put(
  task_type: "text_embedding",
  inference_id: "azure_openai_embeddings",
  body: {
    "service": "azureopenai",
    "service_settings": {
      "api_key": "Api-Key",
      "resource_name": "Resource-name",
      "deployment_id": "Deployment-id",
      "api_version": "2024-02-01"
    }
  }
)
```

