# AzureAIOpenAIApiChatModel

> **Class** in `langchain_azure_ai`

📖 [View in docs](https://reference.langchain.com/python/langchain-azure-ai/chat_models/openai/AzureAIOpenAIApiChatModel)

Azure AI chat model using the OpenAI-compatible API.

This class wraps :class:`langchain_openai.ChatOpenAI` and adds support
for the *project-endpoint pattern* available in Azure AI Foundry, in addition
to the classic *endpoint + API-key* style used by OpenAI-compatible services.

Use `AzureAIOpenAIApiChatModel` with any Foundry model compatible with
OpenAI APIs (e.g. gpt-5, Mistral, Cohere.) to get the benefits of
unified authentication, single configuration, and seamless integration
with other Azure services.

By default, this class uses Responses API. Set `use_responses_api=False`
to disable it and use the standard chat completions API instead.

**Project-endpoint pattern (recommended for Azure AI Foundry):**

```python
from langchain_azure_ai.chat_models import AzureAIOpenAIApiChatModel
from azure.identity import DefaultAzureCredential

model = AzureAIOpenAIApiChatModel(
    project_endpoint=(
        "https://resource.services.ai.azure.com/api/projects/my-project"
    ),
    credential=DefaultAzureCredential(),
    model="gpt-4o",
)
```

Parameter `model` refers to the model deployment name in Azure AI Foundry,
which may differ from the base model name (e.g. "gpt-4o") depending on how
the deployment was configured.

If ``project_endpoint`` is omitted the value of the
``AZURE_AI_PROJECT_ENDPOINT`` environment variable is used.

**Direct endpoint + API-key pattern:**

```python
from langchain_azure_ai.chat_models import AzureAIOpenAIApiChatModel

model = AzureAIOpenAIApiChatModel(
    endpoint="https://resource.services.ai.azure.com/openai/v1",
    credential="your-api-key",
    model="gpt-4o",
)
```

Use `api_version` parameter to specify the API version when using a
direct endpoint, or rely on the automatic API version detection
when using a project endpoint.

```python
from langchain_azure_ai.chat_models import AzureAIOpenAIApiChatModel

model = AzureAIOpenAIApiChatModel(
    endpoint="https://resource.services.ai.azure.com/openai/v1",
    credential="your-api-key",
    model="gpt-4o",
    api_version="2025-05-12"
)
```

**Environment variables:**

The following environment variables are recognised as fallbacks when the
corresponding constructor parameters are not provided:

* ``AZURE_AI_PROJECT_ENDPOINT`` – used as ``project_endpoint``.
* ``AZURE_AI_OPENAI_ENDPOINT`` – direct OpenAI-compatible endpoint
  (e.g. ``https://<resource>.services.ai.azure.com/openai/v1``).
  Used as ``endpoint`` verbatim (no path is appended).
* ``AZURE_OPENAI_ENDPOINT`` – root Azure OpenAI endpoint (e.g.
  ``https://<resource>.services.ai.azure.com``).  ``/openai/v1`` is
  appended automatically and the result is treated as ``endpoint``.
* ``AZURE_OPENAI_DEPLOYMENT_NAME`` – model deployment name (``model``).
* ``AZURE_OPENAI_API_VERSION`` – API version passed as the
  ``api-version`` query parameter on every request.

**Resolution priority** (highest → lowest):

1. Constructor parameters.
2. ``AZURE_AI_PROJECT_ENDPOINT`` environment variable.
3. ``AZURE_AI_OPENAI_ENDPOINT`` environment variable.
4. ``AZURE_OPENAI_ENDPOINT`` / ``AZURE_OPENAI_API_VERSION`` /
   ``AZURE_OPENAI_DEPLOYMENT_NAME`` environment variables.

``AZURE_AI_PROJECT_ENDPOINT``, ``AZURE_AI_OPENAI_ENDPOINT``, and
``AZURE_OPENAI_ENDPOINT`` may all be set at the same time; the project
endpoint takes precedence, then ``AZURE_AI_OPENAI_ENDPOINT``, then
``AZURE_OPENAI_ENDPOINT``.  However, passing both ``project_endpoint``
*and* ``endpoint`` as constructor parameters raises :class:`ValueError`.

All other keyword arguments accepted by
:class:`langchain_openai.ChatOpenAI` are forwarded as-is, so you
retain full control over temperature, max_tokens, streaming, etc.

## Signature

```python
AzureAIOpenAIApiChatModel()
```

## Extends

- `ChatOpenAI`

## Properties

- `model_config`
- `project_endpoint`
- `endpoint`
- `credential`
- `api_version`

## Methods

- [`bind_tools()`](https://reference.langchain.com/python/langchain-azure-ai/chat_models/openai/AzureAIOpenAIApiChatModel/bind_tools)

---

[View source on GitHub](https://github.com/langchain-ai/langchain-azure/blob/7a6a664d617264df8dcb12fcfb1bacc09f21d504/libs/azure-ai/langchain_azure_ai/chat_models/openai.py#L17)