接口参考:单页抽取
POST /api/v2/extract
抓取一个公开 URL,抽取 11 个文章字段,写入系统托管默认文章库。
scope:task:write
请求头
| 头 | 必填 | 说明 |
|---|---|---|
Idempotency-Key | 否 | 建议带;不带时靠 URL 去重;幂等寿命 120 秒 |
请求体
| 字段 | 类型 | 必填 | 默认 | 说明 |
|---|---|---|---|---|
url | string | 是 | - | http/https,≤2048 |
refresh | boolean | 否 | false | 内容变化时是否写新版本 |
format | string | 否 | json | json / md / text |
fields | string[] | 否 | 全部 | 只允许 11 个固定字段 |
contentMaxChars | integer | 否 | 20000 | 1000~200000 |
11 个字段:title、content、pubDate、author、category、tag、
description、keywords、source、summary、images。
响应 data
{
"taskId": 738590,
"record": {
"_id": 1024,
"_url": "https://doc.keydatas.com/getting-started/wangzhan-wenzhang-caiji.html",
"_createdAt": 1760000000000,
"_updatedAt": 1760000000000,
"title": "文章标题",
"content": "正文纯文本……",
"tag": ["标签"],
"keywords": ["关键词"],
"images": ["https://example.com/a.jpg"],
"_warnings": []
},
"markdown": "# 文章标题\n\n正文……",
"text": null,
"deduped": false,
"refreshed": false,
"tokenEstimate": 3200,
"elapsedMs": 1840,
"warnings": []
}
format=md 时正文在 markdown;format=text 时在 text。
非 json 格式下 record 不含 content。
幂等
| 情况 | 结果 |
|---|---|
| 首次 | 写新记录,deduped=false |
| 内容未变 | 返回已有记录,deduped=true |
内容变化 + refresh=false | 返回旧记录,deduped=true,warning content_changed |
内容变化 + refresh=true | 写新版本,refreshed=true |
| 同 URL 并发 | 409 extract_in_progress |
错误
| HTTP | code | 场景 |
|---|---|---|
| 400 | invalid_param | url 缺失/超长、fields 含未知字段 |
| 401 | unauthorized | Key 无效 |
| 403 | extract_disabled | 套餐未开放或服务端关闭 |
| 409 | extract_in_progress | 同 URL 正在处理 |
| 409 | default_task_initializing | 默认文章库正在创建 |
| 422 | invalid_url | 内网/回环/非 http(s)/云元数据 |
| 422 | content_unavailable | 无正文 |
| 422 | unsupported_content_type | 非 HTML |
| 422 | html_too_large | HTML 超过 2MB |
| 429 | quota_exceeded | 当日配额用完 |
| 429 | extract_busy | 平台并发已满 |
| 502 | fetch_failed | 抓取失败 |
| 503 | extract_capacity | 平台日上限 |
| 503 | quota_unavailable | 配额服务不可用 |
| 504 | extract_timeout | 30 秒预算用尽 |
| 500 | persist_failed | 落库失败 |
示例
curl -X POST https://open.keydatas.com/api/v2/extract \
-H "Authorization: Bearer $KEYDATAS_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{"url":"https://doc.keydatas.com/getting-started/wangzhan-wenzhang-caiji.html","format":"md","contentMaxChars":8000}'