获取文件
接口说明
通过 fileId 读取当前可读取文件的元数据和可用读取链接。
接口信息
| 字段 | 值 |
|---|---|
| 方法 | GET |
| 路径 | /openapi/v2/knowledge-bases/{knowledgeBaseId}/files/{fileId} |
| Operation ID | getFileById |
| 鉴权 | Bearer OpenAPI key |
入参
| 名称 | 位置 | 必填 | 类型 | 示例 | 说明 |
|---|---|---|---|---|---|
knowledgeBaseId | path | 是 | string | knowledge-base-11111111-1111-4111-8111-111111111111 | 知识库 API 返回的知识库标识。 |
fileId | path | 是 | string | source-file-11111111-1111-4111-8111-111111111111 | 文件树、搜索、相关文件或文件接口返回的可读取文件标识。 |
请求体
这个接口没有请求体。
请求示例
bash
curl -X GET "https://openapi.example.com/openapi/v2/knowledge-bases/knowledge-base-11111111-1111-4111-8111-111111111111/files/source-file-11111111-1111-4111-8111-111111111111" \
-H "Authorization: Bearer <openapi-key>"成功响应
200
返回指定当前可读取文件的元数据,以及读取和探索链接。
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
file | 是 | object | 当前可读取文件的元数据。 |
成功响应示例
json
{
"file": {
"activeContentRevision": 1,
"fileId": "source-file-11111111-1111-4111-8111-111111111111",
"knowledgeBaseId": "knowledge-base-11111111-1111-4111-8111-111111111111",
"sourceFileId": "source-file-11111111-1111-4111-8111-111111111111",
"path": "pages/guide.md",
"fileKind": "page",
"contentType": "text/markdown; charset=utf-8",
"sizeBytes": 2048,
"okfType": "Guide",
"title": "Verified guide",
"description": null,
"tags": [
"guide",
"policy"
],
"frontmatter": {
"okf_version": "0.2",
"type": "Guide",
"title": "Verified guide",
"tags": [
"guide",
"policy"
],
"sources": [
{
"id": "source-a",
"resource": "references/source-a.md"
}
],
"generated": {
"by": "publisher:example",
"at": "2026-06-17T00:00:00Z"
},
"verified": [
{
"by": "human:reviewer",
"at": "2026-06-17T01:00:00Z"
}
],
"status": "stable",
"stale_after": "2026-12-31"
},
"okfSignals": {
"effectiveStatus": "stable",
"trustTier": "human-reviewed",
"isStale": false,
"staleAfter": "2026-12-31",
"generatedAt": "2026-06-17T00:00:00.000Z",
"generatedAtSource": "generated",
"latestVerifiedAt": "2026-06-17T01:00:00.000Z",
"sourceCount": 1
},
"deletable": true,
"contentAvailable": true,
"readActions": {
"fileDetailById": "/openapi/v2/knowledge-bases/knowledge-base-11111111-1111-4111-8111-111111111111/files/source-file-11111111-1111-4111-8111-111111111111",
"fileContentById": "/openapi/v2/knowledge-bases/knowledge-base-11111111-1111-4111-8111-111111111111/files/source-file-11111111-1111-4111-8111-111111111111/content",
"fileContentByPath": "/openapi/v2/knowledge-bases/knowledge-base-11111111-1111-4111-8111-111111111111/files/content?path=pages%2Fguide.md",
"relatedFilesById": "/openapi/v2/knowledge-bases/knowledge-base-11111111-1111-4111-8111-111111111111/files/source-file-11111111-1111-4111-8111-111111111111/related",
"graphExpansionByFileId": "/openapi/v2/knowledge-bases/knowledge-base-11111111-1111-4111-8111-111111111111/graph/expand?fileId=source-file-11111111-1111-4111-8111-111111111111",
"sourceFileStatusById": "/openapi/v2/knowledge-bases/knowledge-base-11111111-1111-4111-8111-111111111111/source-files/source-file-11111111-1111-4111-8111-111111111111"
}
}
}错误码
下表列出这个接口已声明的全部错误响应。
| HTTP 状态 | 错误码 | 说明 |
|---|---|---|
| 401 | UNAUTHORIZED | Bearer API key 缺失、格式错误、未知、已撤销或已删除。 |
| 404 | NOT_FOUND | 请求的资源不存在。 |
| 429 | RATE_LIMITED | 请求超过当前配置的速率限制。 |
| 500 | INTERNAL_ERROR | API 遇到内部错误。 |
| 503 | DATABASE_REPOSITORY_UNAVAILABLE | 当前接口所需的数据暂时不可用。 |