# Azure OpenAI (/en/ai/models/llm/azure-openai)

> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).

> Documentation: Conversational AI.
> Documentation version: Main.
> This document describes only this version. [Version index](/llms/doc-versions-convoai-guides-v1.txt).


Azure OpenAI service provides REST API access to OpenAI's powerful language models through Microsoft Azure's secure infrastructure.

### Sample configuration

The following example shows how to configure Azure OpenAI LLM when starting a conversational AI agent.

**Python SDK**

```python
from agora_agent import Agent, AzureOpenAI

# client is your configured Agora client
agent = (
    Agent(client)
    .with_stt(...)  # configure your STT vendor
    .with_llm(AzureOpenAI(
        api_key='your-azure-api-key',
        endpoint='https://your-resource-name.openai.azure.com',
        deployment_name='your-deployment-name', # the name given to your model deployment in Azure OpenAI Studio
        model='gpt-4o-mini',
        system_messages=[{'role': 'system', 'content': 'You are a helpful chatbot.'}],
        greeting_message='Hello, how can I assist you today?',
        failure_message='Please hold on a second.',
        max_history=32,
    ))
    .with_tts(...)  # configure your TTS vendor
)
```

**TypeScript SDK**

```typescript
import { Agent, AzureOpenAI } from 'agora-agents';

// client is your configured Agora client
const agent = new Agent({ client })
  .withStt(/* configure your STT vendor */)
  .withLlm(new AzureOpenAI({
    apiKey: 'your-azure-api-key',
    resourceName: 'your-resource-name',
    deploymentName: 'your-deployment-name', // the name given to your model deployment in Azure OpenAI Studio
    model: 'gpt-4o-mini',
    systemMessages: [{ role: 'system', content: 'You are a helpful chatbot.' }],
    greetingMessage: 'Hello, how can I assist you today?',
    failureMessage: 'Please hold on a second.',
    maxHistory: 32,
  }))
  .withTts(/* configure your TTS vendor */);
```

**Go SDK**

```go
import (
    Agora "github.com/AgoraIO/agora-agents-go/v2"
    "github.com/AgoraIO/agora-agents-go/v2/agentkit"
    "github.com/AgoraIO/agora-agents-go/v2/agentkit/vendors"
)

// client is your configured Agora client
agent := agentkit.NewAgent(client).WithStt(/* configure your STT vendor */).
  WithLlm(
    vendors.NewAzureOpenAI(vendors.AzureOpenAIOptions{
        APIKey:         "your-azure-api-key",
        Endpoint:       "https://your-resource-name.openai.azure.com",
        DeploymentName: "your-deployment-name", // the name given to your model deployment in Azure OpenAI Studio
        Model:          "gpt-4o-mini",
        SystemMessages: []map[string]interface{}{
            {"role": "system", "content": "You are a helpful chatbot."},
        },
        GreetingMessage: "Hello, how can I assist you today?",
        FailureMessage:  "Please hold on a second.",
        MaxHistory:      Agora.Int(32),
    }),
).WithTts(/* configure your TTS vendor */)
```

**REST API**

Use the following `llm` configuration in your request:

```json
"llm": {
    "url": "https://YOUR_RESOURCE_NAME.openai.azure.com/openai/deployments/YOUR_DEPLOYMENT_NAME/chat/completions?api-version=AZURE_API_VERSION",
    "api_key": "<api_key>",
    "system_messages": [
        {
            "role": "system",
            "content": "You are a helpful chatbot."
        }
    ],
    "max_history": 32,
    "greeting_message": "Hello, how can I assist you today?",
    "failure_message": "Please hold on a second.",
    "style": "openai",
    "vendor": "azure",
    "params": {
        "model": "gpt-4o-mini"
    }
}
```

### Key parameters

**llm required**

**`api_key` (string) required**

Find your API key in the Azure portal under your OpenAI resource.

**`url` (string) required**

Replace `YOUR_RESOURCE_NAME` with your Azure resource name and `YOUR_DEPLOYMENT_NAME` with your model deployment name.

**`params` (object) required**

**`model` (string) required**

Use the deployment name you created in Azure, not the base model name.

For advanced configuration options, deployment setup, and detailed parameter descriptions, see the [Azure OpenAI API documentation](https://learn.microsoft.com/en-us/azure/ai-services/openai/reference).
