> ## 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.

# OpenAI

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

GPT 模型是业内顶级的 LLM，并且被 **Agents** 用作默认 LLM。OpenAI 支持各种世界一流的模型。在此处查看其模型：[https://platform.openai.com/docs/models](https://platform.openai.com/docs/models)。

我们建议进行实验以找到最适合您用例的模型。以下是一些通用建议：

* `gpt-4o` 适用于大多数通用用例。
* `gpt-4o-mini` 模型适用于较小的任务和更快的推理。
* `o1` 模型适用于复杂的推理和多步任务。
* `o3-mini` 是一款强大的推理模型，支持工具调用和结构化输出，但成本低得多。

OpenAI 有基于层级的速率限制。有关更多信息，请参阅[文档](https://platform.openai.com/docs/guides/rate-limits/usage-tiers)。

## 身份验证

设置您的 `OPENAI_API_KEY` 环境变量。您可以在[此处从 OpenAI 获取](https://platform.openai.com/account/api-keys)。

<CodeGroup>
  ```bash Mac theme={null}
  export OPENAI_API_KEY=sk-***
  ```

  ```bash Windows theme={null}
  setx OPENAI_API_KEY sk-***
  ```
</CodeGroup>

## 示例

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

<CodeGroup>
  ```python agent.py theme={null}

  from agno.agent import Agent, RunResponse
  from agno.models.openai import OpenAIChat

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

  # 在终端中打印响应
  agent.print_response("写一个两句话的恐怖故事。")

  ```

  ## Prompt 缓存

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

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

## 参数

有关更多信息，请参阅[OpenAI 文档](https://platform.openai.com/docs/api-reference/chat/create)。

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

`OpenAIChat` 是 [Model](/reference/models/model) 类的子类，可以访问相同的参数。
