> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreflux.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Azure OpenAI and Azure AI Foundry

> Client-mode REST API connector for Azure OpenAI / Foundry chat completions and embeddings — MQTT into Azure-hosted LLM alarm classification

Technical Preview

## Overview

A client-mode connector for a **curated** slice of [Azure OpenAI](https://learn.microsoft.com/en-us/azure/foundry/openai/reference) / [Azure AI Foundry](https://learn.microsoft.com/en-us/rest/api/microsoft-foundry/azureopenai/chat) focused on IIoT / edge alarm text into Azure-hosted LLMs (OpenAI-compatible bodies, deployment-based paths):

| Catalog connector event | Entity / path | Notes |
| - | - | - |
| POST chat/completions | `POST /openai/deployments/{deployment}/chat/completions?api-version=…` | Chat Completions — same body template as OpenAI |
| POST embeddings | `POST /openai/deployments/{deployment}/embeddings?api-version=…` | Create embeddings on an embeddings deployment |
| (supporting) GET models | `GET /openai/models?api-version=…` | List models (auth smoke) |
| (supporting) GET model | `GET /openai/models/{model}?api-version=…` | Retrieve one model |

Default `BASE_ADDRESS` placeholder is `https://YOUR_RESOURCE.openai.azure.com` (no trailing slash) — replace with your real resource host. Default `api-version` in docs/examples: **`2024-10-21`**. Topics use `ai/azure-openai/<object>/<verb>`.

See the base guide: [REST API Connectors](/latest/lot-language/routes/rest-api-routes).

> [!NOTE]
>
> **Auth:** `api-key: &lt;Azure OpenAI resource key&gt;` on every request (template default). Prefer Hub secrets (`GET SECRET "AZURE_OPENAI_API_KEY"` or `AZURE_OPENAI_KEY`) mapped into MQTT `api_token`. **Entra ID alternative:** `Authorization: Bearer &lt;token&gt;` with scope `https://cognitiveservices.azure.com/.default`. Never commit real keys.

> [!NOTE]
>
> Factory live smoke is **blocked** until a resource endpoint + API key + deployment name are supplied. Set `BASE_ADDRESS` to your `https://{resource}.openai.azure.com` host before production use.

## Basic Syntax

```lot wrap theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
# Coreflux REST_API template — Azure OpenAI / Foundry
# Auth: api-key {value.json.api_token}
# BASE_ADDRESS: https://YOUR_RESOURCE.openai.azure.com

DEFINE ROUTE AzureOpenaiAndAzureAiFoundryRestApi WITH TYPE REST_API
    ADD REST_API_CONFIG
        WITH BASE_ADDRESS "https://YOUR_RESOURCE.openai.azure.com"
        WITH ENABLE_CLIENT "true"
        WITH USE_SSL "true"
        WITH REQUEST_TIMEOUT '60'
        WITH DEFAULT_CONTENT_TYPE "application/json"
    ADD EVENT PostChatCompletions
        WITH SOURCE_TOPIC "ai/azure-openai/chat/completions/post"
        WITH DESTINATION_TOPIC "ai/azure-openai/chat/completions/post/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/openai/deployments/{value.json.deployment}/chat/completions?api-version={value.json.api_version}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "api-key" "{value.json.api_token}"
        WITH BODY "{payload}"
    ADD EVENT PostEmbeddings
        WITH SOURCE_TOPIC "ai/azure-openai/embeddings/post"
        WITH DESTINATION_TOPIC "ai/azure-openai/embeddings/post/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/openai/deployments/{value.json.deployment}/embeddings?api-version={value.json.api_version}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "api-key" "{value.json.api_token}"
        WITH BODY "{payload}"
```

Full deployable file: `AzureOpenaiAndAzureAiFoundryRestApi.lot` in the factory package (no `ADD METADATA`).

## Topics

| Event | Source topic | Destination topic |
| - | - | - |
| PostChatCompletions | `ai/azure-openai/chat/completions/post` | `…/response` |
| PostEmbeddings | `ai/azure-openai/embeddings/post` | `…/response` |
| GetModels | `ai/azure-openai/models/list` | `…/response` |
| GetModel | `ai/azure-openai/models/get` | `…/response` |

## Configuration

1. Set `BASE_ADDRESS` to `https://{your-resource}.openai.azure.com` (no trailing slash).
2. Store the Azure OpenAI API key in Hub secrets (`AZURE_OPENAI_API_KEY` or `AZURE_OPENAI_KEY`); map into MQTT `api_token`.
3. Pass `deployment` (deployment name) and `api_version` (e.g. `2024-10-21`) on inference MQTT JSON.
4. For alarm classification: publish to `ai/azure-openai/chat/completions/post` with an OpenAI-compatible messages body (optional `response_format`).
5. For semantic search / similarity: publish to `ai/azure-openai/embeddings/post` with a tiny `input` string against an embeddings deployment.
6. Use `GetModels` as a cheap auth smoke before production workloads.

## References

* [Azure OpenAI REST reference](https://learn.microsoft.com/en-us/azure/foundry/openai/reference)
* [Models — List (2024-10-21)](https://learn.microsoft.com/en-us/rest/api/azureopenai/models/list?view=rest-azureopenai-2024-10-21)
* [Foundry — Chat Completions](https://learn.microsoft.com/en-us/rest/api/microsoft-foundry/azureopenai/chat)
* [Foundry — Embeddings](https://learn.microsoft.com/en-us/rest/api/microsoft-foundry/azureopenai/embeddings)
* Sibling: [OpenAI](/latest/lot-language/routes/rest-api-apps/openai)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.