> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2-codex-studio-runner-docs-legacy.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Azure OpenAI

> Use OpenAI models through Azure with Agno agents.

Use OpenAI models through Azure's infrastructure. Learn more [here](https://learn.microsoft.com/azure/ai-services/openai/overview).

Azure OpenAI provides access to OpenAI's models like `gpt-4o`, `gpt-5-mini`, and more.

## Installation

```bash theme={null}
uv pip install -U openai agno
```

## Authentication

Navigate to Azure OpenAI on the [Azure Portal](https://portal.azure.com/) and create a service. Then, using the Azure AI Foundry portal, create a deployment and set your environment variables:

<CodeGroup>
  ```bash Mac theme={null}
  export AZURE_OPENAI_API_KEY=***
  export AZURE_OPENAI_ENDPOINT=***  # Of the form https://<your-resource-name>.openai.azure.com
  # Optional:
  # export AZURE_OPENAI_DEPLOYMENT=***
  ```

  ```bash Windows theme={null}
  setx AZURE_OPENAI_API_KEY ***
  setx AZURE_OPENAI_ENDPOINT ***  # Of the form https://<your-resource-name>.openai.azure.com
  # Optional:
  # setx AZURE_OPENAI_DEPLOYMENT ***
  ```
</CodeGroup>

## Example

Use `AzureOpenAI` with your `Agent`:

<CodeGroup>
  ```python agent.py theme={null}
  from agno.agent import Agent
  from agno.models.azure import AzureOpenAI

  agent = Agent(
      model=AzureOpenAI(id="gpt-5-mini"),
      markdown=True
  )

  # Print the response on the terminal
  agent.print_response("Share a 2 sentence horror story.")
  ```
</CodeGroup>

## Prompt caching

Prompt caching happens automatically with the `AzureOpenAI` model. Read more about how OpenAI handles caching in [their docs](https://platform.openai.com/docs/guides/prompt-caching).

## Advanced Examples

View more examples [here](/models/providers/cloud/azure-openai/usage/basic-stream).

## Parameters

| Parameter | Type | Default | Description |
| - | - | - | - |
| `id` | `str` | (required) | The deployment name or model name to use |
| `name` | `str` | `"AzureOpenAI"` | The name of the model |
| `provider` | `str` | `"Azure"` | The provider of the model |
| `api_key` | `Optional[str]` | `None` | The API key for Azure OpenAI (defaults to AZURE\_OPENAI\_API\_KEY env var) |
| `api_version` | `Optional[str]` | `"2024-10-21"` | The API version to use |
| `azure_endpoint` | `Optional[str]` | `None` | The Azure endpoint URL (defaults to AZURE\_OPENAI\_ENDPOINT env var) |
| `azure_deployment` | `Optional[str]` | `None` | The deployment name (defaults to AZURE\_OPENAI\_DEPLOYMENT env var) |
| `base_url` | `Optional[str]` | `None` | Alternative base URL for the service |
| `azure_ad_token` | `Optional[str]` | `None` | Azure AD token for authentication |
| `azure_ad_token_provider` | `Optional[Any]` | `None` | Azure AD token provider for authentication |
| `default_headers` | `Optional[Dict[str, str]]` | `None` | Default headers to include in all requests |
| `default_query` | `Optional[Dict[str, Any]]` | `None` | Default query parameters to include in all requests |

`AzureOpenAI` also supports the parameters of [OpenAI](/reference/models/openai).


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