> 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/chuang-jian-nei-rong/openapi/insert-api-reference-in-your-docs.md).

# 在你的文档中插入 API 参考

从你的 OpenAPI 规范中插入完整的 API 参考，或选择单个操作或模式

GitBook 允许你自动生成与你在 OpenAPI 规范中的端点相关的页面。这些页面将包含 OpenAPI 操作块，使你和访客能够测试你的端点，并基于规范中的信息进一步探索它们。

{% hint style="success" %}
从规范添加的端点会在规范更新时自动更新。更多信息请参阅 [更新规范](https://gitbook.com/docs/documentation/zh/chuang-jian-nei-rong/openapi/add-an-openapi-specification.md#update-your-specification) 部分。
{% endhint %}

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

完成 [添加 OpenAPI 规范](https://gitbook.com/docs/documentation/zh/chuang-jian-nei-rong/openapi/add-an-openapi-specification.md)后，你可以在某个分区的目录中插入 **OpenAPI 参考** ，以生成端点页面。

<figure><img src="https://2111890564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2Fgit-blob-8a6c8e4bdd70968c0ed0f0ee1c556b0703488255%2F25_12_10_create_api_pages%402x.png?alt=media" 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 生成页面**

在要生成端点页面的部分，点击 **添加新项…** 按钮，该按钮位于此部分 [目录的底部](https://gitbook.com/docs/documentation/zh/can-kao/gitbook-ui.md#table-of-contents).

接下来，点击 **OpenAPI 参考**.
{% endstep %}

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

选择之前上传的 OpenAPI 规范，然后选择 **页面结构**:

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

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

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

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

前往 [OpenAPI 布局](https://gitbook.com/docs/documentation/zh/chuang-jian-nei-rong/openapi/guides/openapi-layouts.md) 比较不同布局，或参阅 [构建 API 参考文档](https://gitbook.com/docs/documentation/zh/chuang-jian-nei-rong/openapi/guides/structuring-your-api-reference.md) 了解如何使用标签组织页面。
{% endstep %}
{% endstepper %}

### 添加单个 OpenAPI 块

或者，你可以将规范中的 OpenAPI 操作或架构单独添加到文档中的各个页面。

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

按 **/**&#x6253;开区块选择器，然后搜索 OpenAPI。
{% endstep %}

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

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

{% step %}
**选择你想插入的操作或架构**

选择要插入文档的操作和架构，然后点击 **插入**.
{% 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://gitbook.com/docs/documentation/zh/chuang-jian-nei-rong/openapi/insert-api-reference-in-your-docs.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
