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

# 将 CometAPI 文档与 LLM 一起使用

> 将 CometAPI llms.txt 和 llms-full.txt 用于编码助手、检索系统和模型 Prompt。

当你需要一个紧凑的 CometAPI 文档页面索引时，请使用 `llms.txt`。当你的工具可以摄取完整文档文本以用于检索、问答或编码辅助时，请使用 `llms-full.txt`。

## 获取紧凑索引

以下请求会下载 CometAPI 的 `llms.txt` 索引：

```bash theme={null}
curl https://apidoc.cometapi.com/llms.txt
```

响应以文档标题和链接页面列表开头：

```text theme={null}
# CometAPI Documentation

> CometAPI developer documentation for unified API access...

## Docs

- [Create a new API key](https://apidoc.cometapi.com/api/api-keys/create-api-key.md)
```

## 获取完整文本

以下请求会下载完整文本导出：

```bash theme={null}
curl https://apidoc.cometapi.com/llms-full.txt
```

响应包含按源 URL 分组的页面内容：

```text theme={null}
# Create a new API key
Source: https://apidoc.cometapi.com/api/api-keys/create-api-key

Create a new CometAPI API key for the authenticated account.
```

## 将文档添加到检索任务中

以下 Python 示例会下载完整文本并将其写入本地文件以进行索引：

```python theme={null}
from pathlib import Path

import requests

url = "https://apidoc.cometapi.com/llms-full.txt"
response = requests.get(url, timeout=60)
response.raise_for_status()

Path("cometapi-docs.txt").write_text(response.text, encoding="utf-8")
print(len(response.text))
```

结果是保存的字符数。这只是示例输出；每当文档发生变化时，你的值都会不同：

```text theme={null}
449946
```

## 常见错误

| Error      | Fix                                       |
| ---------- | ----------------------------------------- |
| 工具上下文太小    | 先使用 `llms.txt`，然后仅获取相关的链接页面。              |
| 完整文本过大     | 在建立索引之前，按标题或源 URL 对 `llms-full.txt` 进行分块。 |
| 本地缓存损坏     | 在你的文档同步任务期间刷新该文件。                         |
| AI 结果中缺少页面 | 确认该页面出现在导航中，并且也在 `llms.txt` 中。            |

## 相关链接

* [CometAPI 文档首页](/)
* [模型页面](/zh-Hans/overview/models)
* [模型目录](https://www.cometapi.com/models/)
* [价格](https://www.cometapi.com/pricing/)
* [CometAPI 快速开始](/zh-Hans/overview/quick-start)

<script type="application/ld+json">
  {`
    {
    "@context": "https://schema.org",
    "@graph": [
      {
        "@type": "TechArticle",
        "@id": "https://apidoc.cometapi.com/guides/how-to-use-cometapi-docs-with-llms",
        "headline": "如何将 CometAPI 文档与 LLM 一起使用？",
        "description": "将 CometAPI llms.txt 和 llms-full.txt 用于编码助手、检索系统和模型 Prompt。",
        "url": "https://apidoc.cometapi.com/guides/how-to-use-cometapi-docs-with-llms",
        "author": {
          "@type": "Organization",
          "name": "CometAPI"
        },
        "publisher": {
          "@type": "Organization",
          "name": "CometAPI",
          "url": "https://www.cometapi.com"
        }
      },
      {
        "@type": "BreadcrumbList",
        "itemListElement": [
          {
            "@type": "ListItem",
            "position": 1,
            "name": "CometAPI 文档",
            "item": "https://apidoc.cometapi.com/"
          },
          {
            "@type": "ListItem",
            "position": 2,
            "name": "指南",
            "item": "https://apidoc.cometapi.com/guides/use-cometapi-with-openai-sdk"
          },
          {
            "@type": "ListItem",
            "position": 3,
            "name": "如何将 CometAPI 文档与 LLM 一起使用？",
            "item": "https://apidoc.cometapi.com/guides/how-to-use-cometapi-docs-with-llms"
          }
        ]
      }
    ]
    }
    `}
</script>
