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

# Azure OpenAI

> 了解如何在 Agno 中使用 Azure OpenAI 模型。

通过 Azure 的基础设施使用 OpenAI 模型。在此处了解更多信息：[here](https://learn.microsoft.com/azure/ai-services/openai/overview)。

Azure OpenAI 提供对 OpenAI 模型的访问，例如 `GPT-4o`、`o3-mini` 等。

## 身份验证

在 [Azure Portal](https://portal.azure.com/) 中导航到 Azure OpenAI 并创建一个服务。然后，使用 Azure AI Studio portal 创建一个部署，并设置您的环境变量：

<CodeGroup>
  ```bash Mac theme={null}
  export AZURE_OPENAI_API_KEY=***
  export AZURE_OPENAI_ENDPOINT=***  # 格式为 https://<your-resource-name>.openai.azure.com/openai/deployments/<your-deployment-name>
  # 可选:
  # export AZURE_OPENAI_DEPLOYMENT=***
  ```

  ```bash Windows theme={null}
  setx AZURE_OPENAI_API_KEY ***  # 格式为 https://<your-resource-name>.openai.azure.com/openai/deployments/<your-deployment-name>
  setx AZURE_OPENAI_ENDPOINT ***
  # 可选:
  # setx AZURE_OPENAI_DEPLOYMENT ***
  ```
</CodeGroup>

## 示例

在您的 `Agent` 中使用 `AzureOpenAI`：

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

  agent = Agent(
      model=AzureOpenAI(id="gpt-4o"),
      markdown=True
  )

  # 在终端打印响应
  agent.print_response("分享一个两句话的恐怖故事。")
  ```
</CodeGroup>

## Prompt 缓存

Prompt 缓存将通过我们的 `AzureOpenAI` 模型自动进行。您可以在[他们的文档](https://platform.openai.com/docs/guides/prompt-caching)中详细了解 OpenAI 如何处理缓存。

## 高级示例

在此处查看更多示例：[here](../examples/models/azure/openai)。

## 参数

<Snippet file="model-azure-openai-params.mdx" />

`AzureOpenAI` 还支持 [OpenAI](/reference/models/openai) 的参数。
