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

# 使用API生成LLMs.txt

> 从任何网站生成LLMs.txt文件，用于LLM训练和分析

## LLMs.txt生成器端点介绍（Alpha）📃

`/llmstxt`端点允许您将任何网站转换为干净的[LLM准备就绪的文本文件](https://www.firecrawl.dev/blog/How-to-Create-an-llms-txt-File-for-Any-Website)。只需提供网址，Firecrawl就会爬取该网站并生成可用于与任何LLM进行训练或分析的`llms.txt`和`llms-full.txt`文件。

## 工作原理

LLMs.txt生成器：

1. 爬取提供的网址及其链接页面
2. 提取干净、有意义的文本内容
3. 生成两种格式：
   * `llms.txt`: 简洁总结和关键信息
   * `llms-full.txt`: 更详细的完整文本内容

### 示例用法

<CodeGroup>
  ```python Python theme={null}
  from firecrawl import FirecrawlApp

  # 初始化客户端
  firecrawl = FirecrawlApp(api_key="your_api_key")

  # 定义生成参数
  params = {
      "maxUrls": 2,  # 要分析的最大URL数量
      "showFullText": True  # 在结果中包含全文
  }

  # 使用轮询生成 LLMs.txt
  results = firecrawl.generate_llms_text(
      url="https://example.com",
      params=params
  )

  # 访问生成结果
  if results['success']:
      print(f"状态: {results['status']}")
      print(f"生成的数据: {results['data']}")
  else:
      print(f"错误: {results.get('error', '未知错误')}")
  ```

  ```js Node theme={null}
  import FirecrawlApp from "firecrawl";

  // 初始化客户端
  const firecrawl = new FirecrawlApp({ apiKey: "your_api_key" });

  // 定义生成参数
  const params = {
    maxUrls: 2, // 要分析的最大URL数
    showFullText: true, // 在结果中包含全文
  };

  // 使用轮询生成LLMs.txt
  const results = await firecrawl.generateLLMsText("https://example.com", params);

  // 访问生成结果
  if (results.success) {
    console.log(`状态: ${results.status}`);
    console.log(`生成的数据:`, results.data);
  } else {
    console.error(`错误: ${results.error || "未知错误"}`);
  }
  ```

  ```bash cURL theme={null}
  # 开始生成LLMs.txt
  curl -X POST "https://api.firecrawl.dev/v1/llmstxt" \
    -H "Authorization: Bearer your_api_key" \
    -H "Content-Type: application/json" \
    -d '{
      "url": "https://example.com",
      "maxUrls": 2,
      "showFullText": true
    }'

  # 检查生成状态
  curl -X GET "https://api.firecrawl.dev/v1/llmstxt/job_id" \
    -H "Authorization: Bearer your_api_key"
  ```
</CodeGroup>

**关键参数：**

* **url**: 要生成LLMs.txt文件的网站URL
* **maxUrls** (可选): 要爬取的最大页面数（1-100，默认值：10）
* **showFullText** (可选): 除了`llms.txt`外，还生成`llms-full.txt`（默认值：false）

有关更多详细信息，请参见[API参考](/api-reference/endpoint/llmstxt)。

## 检查生成状态

LLMs.txt生成是异步进行的。进行异步调用并监控状态：

<CodeGroup>
  ```python Python theme={null}
  from firecrawl import FirecrawlApp

  # 初始化客户端
  firecrawl = FirecrawlApp(api_key="your_api_key")

  # 创建异步任务
  job = firecrawl.async_generate_llms_text(
      url="https://example.com",
  )

  if job['success']:
      job_id = job['id']

  # 检查 LLMs.txt 生成状态
  status = firecrawl.check_generate_llms_text_status("job_id")

  # 打印当前状态
  print(f"Status: {status['status']}")

  if status['status'] == 'completed':
      print("LLMs.txt 内容:", status['data']['llmstxt'])
      if 'llmsfulltxt' in status['data']:
          print("完整文本内容:", status['data']['llmsfulltxt'])
      print(f"处理过的 URLs: {len(status['data']['processedUrls'])}")
  ```

  ```js Node theme={null}
  import FirecrawlApp from "firecrawl";

  // 初始化客户端
  const firecrawl = new FirecrawlApp({ apiKey: "your_api_key" });

  // 创建异步任务
  const job = await firecrawl.asyncGenerateLLMsText("https://example.com", {
    maxUrls: 50,
    showFullText: true
  });

  // 检查 LLMs.txt 生成状态
  const status = await firecrawl.checkGenerateLLMsTextStatus(job.jobId);

  // 打印当前状态
  console.log(`Status: ${status.status}`);

  if (status.status === "completed") {
    console.log("LLMs.txt 内容:", status.data.llmstxt);
    if (status.data.llmsfulltxt) {
      console.log("完整文本内容:", status.data.llmsfulltxt);
    }
    console.log(`已处理的 URL: ${status.data.processedUrls.length}`);
  }
  ```

  ```bash theme={null}
  curl "https://api.firecrawl.dev/v1/llmstxt/job_id" \
    -H "Authorization: Bearer your_api_key"
  ```
</CodeGroup>

### 状态示例

#### 进行中

```json theme={null}
{
  "success": true,
  "data": {
    "llmstxt": "# Firecrawl.dev llms.txt

- [Web Data Extraction Tool](https://www.firecrawl.dev/)...",
    "llmsfulltxt": "# Firecrawl.dev llms-full.txt

"
  },
  "status": "processing",
  "expiresAt": "2025-03-03T23:19:18.000Z"
}
```

#### 已完成

```json theme={null}
{
  "success": true,
  "data": {
    "llmstxt": "# http://firecrawl.dev llms.txt

- [Web数据提取工具](https://www.firecrawl.dev/): 轻松将网站转换为干净的、适用于LLM的数据。
- [灵活的网页抓取定价](https://www.firecrawl.dev/pricing): 提供灵活的网页抓取和数据提取定价计划。
- [网页抓取与人工智能](https://www.firecrawl.dev/blog): 浏览有关网页抓取和人工智能的教程和文章...",
    "llmsfulltxt": "# http://firecrawl.dev llms-full.txt

## Web数据提取工具
介绍 /extract - 通过提示获取网页数据 [立即尝试](https://www.firecrawl.dev/extract)

[💥购买年度计划可享受2个月免费](https://www.firecrawl.dev/pricing)..."
  },
  "status": "completed",
  "expiresAt": "2025-03-03T22:45:50.000Z"
}
```

## 已知限制（Alpha）

1. **访问限制**\
   只能处理公开可访问的页面。登录保护或付费墙内容不受支持。

2. **站点大小**\
   在alpha阶段，我们只允许处理最多5000个URL。

3. **Alpha状态**\
   作为一个Alpha功能，输出格式和处理可能会根据反馈而演变。

## 计费和使用

计费基于处理的URL数量：

* 基础费用：每个处理的URL收费1个积分
* 使用`maxUrls`参数控制URL成本

有反馈或需要帮助吗？发送邮件至 [help@firecrawl.dev](mailto:help@firecrawl.dev)。
