AI 工具5 credits
generate_ llms_ txt
爬取站点、分析其结构,并生成符合标准的 llms.txt(及可选的 llms-full.txt)文件,用于定义 AI 模型应如何与你的内容交互。合规级别从宽松到严格可选。
使用场景
发布 AI 就绪的文档
在文档旁发布 llms.txt,让 Claude、ChatGPT 等爬虫读取清晰的准则。
AI 合规发布
使用严格合规级别,在一处统一设置训练数据、缓存和署名规则。
机器人策略生成
为你域名上特定的 AI user agent 添加自定义准则和限制。
Endpoint
POST
/api/v1/tools/generate_llms_txtAuth Required
Free 计划 1 req/s
5 credits
Parameters
重负载操作: 此工具可能爬取多达 500 个页面。它使用预留系统,因此 credits 会在任务期间被占用。
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
url | string | Required | - | 要为其生成 llms.txt 的网站 URL Example: https://example.com |
format | string | Optional | both | 输出格式:"both" | "llms-txt" | "llms-full-txt" Example: both |
complianceLevel | string | Optional | standard | "basic" | "standard" | "strict"。为兼容而接受,不会改变本端点的输出——输出依据网站自身发布的内容生成。在 CrawlForge MCP 服务器上,它仅在 `outputOptions.robotsStyle: true` 时生效。 Example: standard |
analysisOptions | object | Optional | - | 网站分析选项(maxDepth 1-5、maxPages 10-500、respectRobots、detectAPIs、analyzeContent、checkSecurity) Example: {"maxDepth": 3, "maxPages": 100, "detectAPIs": true} |
outputOptions | object | Optional | - | 输出定制(organizationName、contactEmail、customGuidelines、customRestrictions、includeDetailed、includeAnalysis) Example: {"organizationName": "Example Inc.", "contactEmail": "ai@example.com"} |
respect_robots | boolean | Optional | true | 遵守目标站点的 robots.txt。保持 `true` 时,robots.txt 对 `CrawlForge` 禁止的路径会在抓取之前以 403 拒绝,且不扣除 credits。仅在你与目标站点另有约定时才设为 `false`——此时响应会带上一条 `warnings`,并且该覆盖会记录到你的 API key 上。`analysisOptions.respectRobots` 是别名;两者任一设为 `false` 都会关闭该检查。 Example: true |
max_inline_chars | number | Optional | 40000 | 内联返回的最大结果大小,以其 JSON 的字符数计(1,000-10,000,000)。超过后,响应会携带 `preview`(`llms_full_txt` 的前 `max_inline_chars` 个字符;只生成 `llms_txt` 时则取 `llms_txt`)、`result_handle`、`total_chars`、`truncated: true` 和 `expires_at`,其余部分由 [read_result](/docs/api-reference/tools/read-result) 读取,每次调用 1 credit。已存储的结果保留 1 小时。 Example: 40000 |
请求示例
cURL — 两种格式,标准合规
terminalBash
curl -X POST https://crawlforge.dev/api/v1/tools/generate_llms_txt \
-H "X-API-Key: cf_test_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com",
"format": "both",
"complianceLevel": "standard",
"outputOptions": {
"organizationName": "Example Inc.",
"contactEmail": "ai@example.com"
}
}'TypeScript — 带自定义准则的严格模式
generateLlmsTxt.tsTypescript
// npm install crawlforge-sdk
import { CrawlForge } from 'crawlforge-sdk';
import fs from 'node:fs/promises';
const client = new CrawlForge({ apiKey: process.env.CRAWLFORGE_API_KEY });
const result = await client.generateLlmsTxt({
url: 'https://docs.example.com',
format: 'both',
complianceLevel: 'strict',
analysisOptions: {
maxDepth: 4,
maxPages: 250,
detectAPIs: true,
analyzeContent: true,
},
outputOptions: {
organizationName: 'Example Inc.',
contactEmail: 'ai@example.com',
customGuidelines: [
'AI crawlers must respect robots.txt',
'Cache responses for up to 24 hours',
],
customRestrictions: [
'No training on user-submitted content',
],
includeAnalysis: true,
},
});
// result.data is untyped in crawlforge-sdk 0.1 — its shape is the Response Example below.
const { llms_txt, llms_full_txt } = result.data as { llms_txt: string; llms_full_txt: string };
await fs.writeFile('public/llms.txt', llms_txt);
await fs.writeFile('public/llms-full.txt', llms_full_txt);Python
generate_llms_txt.pyPython
# pip install crawlforge
from crawlforge import CrawlForge
client = CrawlForge() # reads CRAWLFORGE_API_KEY
result = client.generate_llms_txt(
url='https://example.com',
format='llms-txt',
complianceLevel='basic',
)
# result.data is a plain dict — its shape is the Response Example below.
with open('public/llms.txt', 'w') as f:
f.write(result.data['llms_txt'])响应示例
200 OK4.1s
{ "success": true, "data": { "url": "https://example.com", "llms_txt": "# Example Inc.\n\n> Tools for building things.\n\n## Docs\n\n- [Quickstart](https://example.com/docs/quickstart): Get started in five minutes\n", "llms_full_txt": "# Example Inc.\n\n## Quickstart\n\nURL: https://example.com/docs/quickstart\n\nGet started in five minutes...", "pages_analyzed": 12, "pages": [ { "url": "https://example.com", "title": "Example Inc." }, { "url": "https://example.com/docs/quickstart", "title": "Quickstart" } ], "compliance": { "robots_txt_found": true, "disallow_count": 3 }, "api_endpoints_detected": [ "https://example.com/api/v1" ], "clamps_applied": [ "maxPages clamped from 100 to 25" ], "generated_at": "2026-08-26T14:30:00.000Z" }, "credits_used": 5, "credits_remaining": 995, "processing_time": 4100}Field Descriptions
data.llms_txt生成的 llms.txt。除非 `format` 设为 llms-full-txt,否则都会出现。data.llms_full_txt内联了每个已分析页面正文的 llms.txt。仅当 `format` 为 both 或 llms-full-txt 时出现。data.pages_analyzed根页面加上所有成功抓取的页面。data.pages进入输出结果的页面,每个都附带标题。data.compliance.robots_txt_found是否取得了 robots.txt;disallow_count 表示其中包含多少条 Disallow 规则。`false` 既可能表示站点没有 robots.txt,也可能表示 robots.txt 无法读取——后一种情况还会在 `warnings` 中添加一条说明原因的记录。data.api_endpoints_detected在已抓取 HTML 中识别出的至多 10 个疑似 API 的 URL。这是基于路径的启发式判断,并非经过验证的 API 清单。robots.txt 对 `CrawlForge` 禁止的同站 URL 绝不会列出。data.clamps_applied当您请求的上限为适配无服务器预算而被下调时给出的可读说明。未发生下调时为空。data.generated_at本次生成的 ISO 8601 时间戳。错误处理
被 robots.txt 拦截(403 Forbidden)
目标站点的 robots.txt 对 CrawlForge 禁止了该路径。若你与目标站点另有约定,可设置 respect_robots: false 予以覆盖——该覆盖会记录到你的 API key 上。该覆盖不适用于列入 CrawlForge 永久排除名单的主机——无论 respect_robots 取何值,这类主机一律被拒绝。只有目标 URL 会返回 403:分析过程中发现的、被 robots.txt 禁止的页面会被排除在分析之外,并计入 warnings。
credit 费用
相关工具
准备好发布 AI 交互准则了吗?免费注册,获取 1,000 credits。