接口参考:Schema
GET /api/v2/tasks/{taskId}/schema
返回任务的字段契约。
scope:data:read
路径参数
| 参数 | 类型 | 说明 |
|---|---|---|
taskId | integer | 任务 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
| 字段 | 类型 | 说明 |
|---|---|---|
name | string | 字段名 |
type | string | string / integer / number / boolean / date |
description | string | 描述 |
required | boolean | 是否必填;默认 false |
format | string | 日期格式,如 yyyy-MM-dd HH:mm:ss |
sample | string | 样例值 |
inferred | boolean | 类型是否由样例推断 |
multiValue | boolean | 多值字段;JSON 中是字符串数组,type 仍是 string |
错误
| HTTP | code | 场景 |
|---|---|---|
| 401 | unauthorized | Key 无效 |
| 404 | not_found | 任务不存在 |
| 500 | internal_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 与字段信息。
错误
| HTTP | code | 场景 |
|---|---|---|
| 401 | unauthorized | Key 无效 |
| 500 | internal_error | 生成失败 |
示例
curl https://open.keydatas.com/api/v2/schema \
-H "Authorization: Bearer $KEYDATAS_API_KEY"
怎么用 Schema
- 取
fields[].name作为records?fields=的候选; - 取
type决定程序里的反序列化类型; multiValue=true时按数组处理;inferred=true表示类型是从样例推断的,数据里可能混入其它类型;jsonSchema可直接给支持 JSON Schema 的校验器或 LLM 工具定义。