跳到主要内容

接口参考:Schema

GET /api/v2/tasks/{taskId}/schema​

返回任务的字段契约。

scope:data:read

路径参数​

参数类型说明
taskIdinteger任务 ID,≥1

查询参数​

无。契约里的 refresh 参数未实现;服务端始终走约 10 分钟缓存。

响应 data​

{
"taskId": 738590,
"schemaVersion": 3,
"jsonSchema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"title": {"type": "string"},
"pubDate": {"type": "string", "format": "date"},
"tag": {"type": "array", "items": {"type": "string"}}
},
"required": [],
"additionalProperties": true
},
"fields": [
{
"name": "title",
"type": "string",
"description": "标题",
"required": false,
"format": null,
"sample": "……",
"inferred": false,
"multiValue": false
}
],
"sampleCount": 12,
"updatedAt": 1760000000000,
"warnings": []
}

FieldMeta​

字段类型说明
namestring字段名
typestringstring / integer / number / boolean / date
descriptionstring描述
requiredboolean是否必填;默认 false
formatstring日期格式,如 yyyy-MM-dd HH:mm:ss
samplestring样例值
inferredboolean类型是否由样例推断
multiValueboolean多值字段;JSON 中是字符串数组,type 仍是 string

错误​

HTTPcode场景
401unauthorizedKey 无效
404not_found任务不存在
500internal_error生成 Schema 失败

示例​

curl https://open.keydatas.com/api/v2/tasks/738590/schema \
-H "Authorization: Bearer $KEYDATAS_API_KEY"

GET /api/v2/schema​

默认文章库的 Schema。

scope:data:read

响应​

未初始化时返回静态 canonical schema:

{
"taskId": 0,
"schemaVersion": 0,
"jsonSchema": { "...": "..." },
"fields": [ "11 个 canonical 字段" ],
"sampleCount": 0,
"updatedAt": 0,
"warnings": ["default_task_not_initialized"]
}

初始化后返回真实 taskId 与字段信息。

错误​

HTTPcode场景
401unauthorizedKey 无效
500internal_error生成失败

示例​

curl https://open.keydatas.com/api/v2/schema \
-H "Authorization: Bearer $KEYDATAS_API_KEY"

怎么用 Schema​

  1. 取 fields[].name 作为 records?fields= 的候选;
  2. 取 type 决定程序里的反序列化类型;
  3. multiValue=true 时按数组处理;
  4. inferred=true 表示类型是从样例推断的,数据里可能混入其它类型;
  5. jsonSchema 可直接给支持 JSON Schema 的校验器或 LLM 工具定义。

相关​