> For the complete documentation index, see [llms.txt](https://gitbook.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.com/docs/documentation/zh/api-references/openapi/insert-api-reference-in-your-docs.md).

# 在文档中插入 API 参考

GitBook 允许你自动生成与你在 OpenAPI 规范中的端点相关的页面。这些页面将包含 OpenAPI 操作块，让你和你的访问者可以测试你的端点，并根据规范中找到的信息进一步探索它们。

{% hint style="success" %}
从你的规范中添加的端点将在你的规范更新时持续更新。请参见 [更新你的规范](/docs/documentation/zh/api-references/openapi/add-an-openapi-specification.md#update-your-specification) 部分以了解更多信息。
{% endhint %}

### 根据你的规范自动创建 OpenAPI 页面

在你 [添加了 OpenAPI 规范](/docs/documentation/zh/api-references/openapi/add-an-openapi-specification.md)之后，你可以通过插入一个 **OpenAPI 参考** 到某个章节的目录中来生成端点页面。

<figure><img src="/files/22304f3aaa594a5a51ce2043d5bd82f98be6f4d5" alt="A GitBook screenshot showing how to insert API references into the table of contents of a section"><figcaption><p>在某个章节的目录中插入 API 参考。</p></figcaption></figure>

{% stepper %}
{% step %}
**从 OpenAPI 生成页面**

在你想要生成端点页面的章节中，点击 **添加新的...** 按钮，位于你章节的底部 [目录](/docs/documentation/zh/zi-yuan/gitbook-ui.md#table-of-contents).

在这里，点击 **OpenAPI 参考**.
{% endstep %}

{% step %}
**选择你的 OpenAPI 规范**

选择你之前上传的 OpenAPI 规范。然后选择一个 **页面结构**:

* **每个标签一页**
* **每个操作一页**

你也可以选择添加模型页面和下载链接。点击 **插入** 来生成该参考。
{% endstep %}

{% step %}
**管理你的 API 操作**

GitBook 将根据你的 OpenAPI 规范及其定义中设置的标签自动生成页面。如果你选择 **每个操作一页**，GitBook 会按标签对生成的操作页面进行分组。

前往 [OpenAPI 布局](/docs/documentation/zh/api-references/guides/openapi-layouts.md) 比较不同布局，或者 [构建你的 API 参考](/docs/documentation/zh/api-references/guides/structuring-your-api-reference.md) 使用标签来组织页面。
{% endstep %}
{% endstepper %}

### 添加单独的 OpenAPI 块

另外，你也可以将规范中的 OpenAPI 操作或 schema 单独添加到文档中的各个页面。

{% stepper %}
{% step %}
**添加新的 OpenAPI 块**

按下 **/**&#x53EF;打开块选择器，并搜索 OpenAPI。
{% endstep %}

{% step %}
**选择你的 OpenAPI 规范**

选择你之前上传的 OpenAPI 规范，然后点击 **继续** 来选择你想使用的端点。
{% endstep %}

{% step %}
**选择你想要插入的操作或 schema**

选择你想要插入到文档中的操作和 schema，然后点击 **插入**.
{% endstep %}
{% endstepper %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://gitbook.com/docs/documentation/zh/api-references/openapi/insert-api-reference-in-your-docs.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
