获取文档
返回一个文档,包括其状态、自定义元数据、row_version、生效的修订版本和最近一次索引任务。
文档 ID 与文档文件 ID 的关系,详见 浏览文档和分段。
1 min read
get/knowledge-fs/spaces/{knowledge_base_id}/logical-documents/{document_id}
Request example
curl --request GET \
--url https://api.dify.ai/v1/knowledge-fs/spaces/{knowledge_base_id}/logical-documents/{document_id} \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.dify.ai/v1/knowledge-fs/spaces/{knowledge_base_id}/logical-documents/{document_id}"
headers = {
"Authorization": "Bearer <token>",
}
response = requests.request("GET", url, headers=headers)
print(response.text)const response = await fetch('https://api.dify.ai/v1/knowledge-fs/spaces/{knowledge_base_id}/logical-documents/{document_id}', {
method: 'GET',
headers: {
'Authorization': 'Bearer <token>'
}
});
const data = await response.json();
console.log(data);<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://api.dify.ai/v1/knowledge-fs/spaces/{knowledge_base_id}/logical-documents/{document_id}',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => [
'Authorization: Bearer <token>',
],
]);
$response = curl_exec($curl);
curl_close($curl);
echo $response;package main
import (
"fmt"
"io"
"net/http"
)
func main() {
url := "https://api.dify.ai/v1/knowledge-fs/spaces/{knowledge_base_id}/logical-documents/{document_id}"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.dify.ai/v1/knowledge-fs/spaces/{knowledge_base_id}/logical-documents/{document_id}"))
.header("Authorization", "Bearer <token>")
.method("GET", HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());require 'uri'
require 'net/http'
url = URI('https://api.dify.ai/v1/knowledge-fs/spaces/{knowledge_base_id}/logical-documents/{document_id}')
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = url.scheme == 'https'
request = Net::HTTP::Get.new(url)
request['Authorization'] = 'Bearer <token>'
response = http.request(request)
puts response.read_bodyResponse
{
"active": {
"activated_at": "2026-10-20T08:16:05Z",
"content_hash": "4f7c2d9a1b3e5f60718293a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4",
"created_at": "2026-10-20T08:15:42Z",
"document_asset_id": "6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b",
"document_asset_version": 1,
"document_id": "2f6b8d1a-7c3e-4a5b-9d0e-1f2a3b4c5d6e",
"knowledge_space_id": "9b2e5b7a-3c1d-4e2f-8a9b-1c2d3e4f5a6b",
"mime_type": "application/pdf",
"revision": 2,
"size_bytes": 482113,
"state": "active"
},
"active_revision": 2,
"created_at": "2026-09-03T10:02:11Z",
"disabled_at": null,
"disabled_by_subject_id": null,
"enabled": true,
"id": "2f6b8d1a-7c3e-4a5b-9d0e-1f2a3b4c5d6e",
"knowledge_space_id": "9b2e5b7a-3c1d-4e2f-8a9b-1c2d3e4f5a6b",
"latest_task": {
"can_cancel": false,
"can_retry": false,
"completed_at": "2026-10-20T08:16:05Z",
"created_at": "2026-10-20T08:15:42Z",
"document_id": "2f6b8d1a-7c3e-4a5b-9d0e-1f2a3b4c5d6e",
"document_revision": 2,
"document_title": null,
"error_code": null,
"error_message": null,
"failure": null,
"failures": null,
"id": "c4e8a2f6-1b3d-4e5f-8a9b-0c1d2e3f4a5b",
"knowledge_space_id": "9b2e5b7a-3c1d-4e2f-8a9b-1c2d3e4f5a6b",
"operation": "document_processing",
"progress_completed": 1,
"progress_failed": 0,
"progress_percent": 100,
"progress_total": 1,
"semantic_enrichment": {
"error_code": null,
"error_message": null,
"failure": null,
"nodes_completed": 0,
"nodes_total": null,
"provider_calls": null,
"provider_calls_maximum": null,
"state": "disabled",
"updated_at": null
},
"source_id": null,
"source_title": null,
"state": "completed",
"task_kind": "document",
"updated_at": "2026-10-20T08:16:05Z"
},
"provider_item_id": null,
"row_version": 4,
"source_id": null,
"status": "ready",
"title": "handbook.pdf",
"updated_at": "2026-10-20T08:16:05Z",
"user_metadata": {
"owner": "support-team",
"product_line": "billing",
"review_date": "2026-12-01T00:00:00Z"
}
}{
"code": "knowledge_fs_invalid_request",
"message": "Agent Knowledge Base request is invalid.",
"status": 400
}{
"code": "knowledge_fs_invalid_request",
"failure": {
"category": "validation",
"code": "KNOWLEDGE_FS_INVALID_REQUEST",
"message": "The Agent Knowledge Base request is invalid.",
"retryPolicy": "never",
"traceId": "7f3c1a90-2e64-4b7d-8a51-6c0d9e2f4b83"
},
"message": "The Agent Knowledge Base request is invalid.",
"status": 400
}{
"code": "knowledge_fs_invalid_credential",
"message": "Invalid Agent Knowledge Base service credential.",
"status": 401
}{
"code": "unauthorized",
"message": "Access token is invalid",
"status": 401
}{
"code": "forbidden",
"message": "Sorry, you have reached the knowledge base request rate limit of your subscription.",
"status": 403
}{
"code": "knowledge_fs_access_denied",
"message": "Agent Knowledge Base operation is not allowed.",
"status": 403
}{
"code": "knowledge_fs_access_denied",
"failure": {
"action": "contact_admin",
"category": "authorization",
"code": "KNOWLEDGE_FS_ACCESS_DENIED",
"message": "You do not have permission to perform this Agent Knowledge Base operation.",
"retryPolicy": "never",
"traceId": "7f3c1a90-2e64-4b7d-8a51-6c0d9e2f4b83"
},
"message": "You do not have permission to perform this Agent Knowledge Base operation.",
"status": 403
}{
"code": "knowledge_fs_resource_not_found",
"failure": {
"category": "not_found",
"code": "KNOWLEDGE_FS_NOT_FOUND",
"message": "The requested Agent Knowledge Base resource was not found.",
"retryPolicy": "never",
"traceId": "7f3c1a90-2e64-4b7d-8a51-6c0d9e2f4b83"
},
"message": "The requested Agent Knowledge Base resource was not found.",
"status": 404
}{
"code": "not_found",
"message": "The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.",
"status": 404
}{
"code": "knowledge_fs_upstream_unavailable",
"failure": {
"action": "contact_admin",
"category": "internal",
"code": "KNOWLEDGE_FS_INTERNAL_ERROR",
"message": "Agent Knowledge Base could not complete the operation. Try again, or contact an administrator with the error reference.",
"retryPolicy": "manual",
"traceId": "5e2a9c17-3b4d-4f60-8a1b-2c3d4e5f6a7b"
},
"message": "Agent Knowledge Base could not complete the operation. Try again, or contact an administrator with the error reference.",
"status": 502
}{
"code": "knowledge_fs_upstream_unavailable",
"message": "Agent Knowledge Base is unavailable.",
"status": 502
}{
"code": "knowledge_fs_operation_unavailable",
"message": "Agent Knowledge Base operation is not available.",
"status": 503
}{
"code": "knowledge_fs_operation_unavailable",
"failure": {
"action": "retry",
"category": "dependency",
"code": "KNOWLEDGE_FS_UNAVAILABLE",
"message": "A service required by Agent Knowledge Base is temporarily unavailable.",
"retryPolicy": "manual",
"traceId": "5e2a9c17-3b4d-4f60-8a1b-2c3d4e5f6a7b"
},
"message": "A service required by Agent Knowledge Base is temporarily unavailable.",
"status": 503
}get/knowledge-fs/spaces/{knowledge_base_id}/logical-documents/{document_id}
Authorization
Path parameters
知识库 ID:即知识库 API 访问 对话框中所示服务 API 端点的最后一段(
…/knowledge-fs/spaces/<knowledge base ID>),也是地址栏中 /datasets/new/ 之后的那一段。Responses
application/json
文档。
Show child attributesHide child attributes
修订版本生效的时间,ISO 8601 格式。从未生效的修订版本为
null。内容的 SHA-256 哈希值,十六进制编码。
修订版本创建时间,ISO 8601 格式。
创建此修订版本时文档文件的
version。知识库的内部 ID,并非路径中的知识库 ID。
文档文件的 MIME 类型。
文档文件大小,单位为字节。
修订版本正在索引时为
candidate,知识库当前提供的修订版本为 active,有更新的修订版本生效后为 superseded,索引失败时为 failed。生效修订版本的编号。没有生效的修订版本时为
null。文档创建时间,ISO 8601 格式。
在 Dify 中禁用该文档的时间,ISO 8601 格式。
禁用该文档的操作者的内部 ID。调用此 API 时无需使用。
文档 ID。文档内容更新后保持不变。
知识库的内部 ID,并非路径中的知识库 ID。
为该文档生成修订版本的最新索引任务(
task_kind: document)。可用其 id 调用 获取文档的索引任务 跟踪该任务。没有索引任务时为 null,在 更新文档元数据 的响应中始终为 null。Show child attributesHide child attributes
任务结束时间,ISO 8601 格式。运行期间为
null。任务创建时间,ISO 8601 格式。
索引任务的文档 ID。批量任务只有一个文档时才设置此字段。
索引任务构建的修订版本。
文档标题,仅当批量任务只有一个文档时设置。
state 为 failed 时的错误码。error_code 对应的错误消息,可能与 failure.message 不同。state 为 failed 时的错误详情,否则为 null。Show child attributesHide child attributes
建议的下一步操作(如有):
configure_model、configure_parser、configure_source、contact_admin、reupload 或 retry。不适用时为 null。HTTP 错误响应体中不包含此字段。失败类别:
authorization、canceled、configuration、conflict、dependency、internal、not_found、rate_limit、timeout 或 validation。稳定的错误码,采用大写蛇形命名,例如
KNOWLEDGE_FS_CONFLICT 或 SOURCE_CREDENTIAL_TEST_FAILED。错误码或失败类别对应的公开消息。不会暴露提供商的错误详情。
描述失败细节的值,最多 8 个,键取自
attempt、currentRowVersion、documentCount、expectedRowVersion、fileSizeBytes、limit、maxFileSizeBytes、maxItems、modelType、providerKind、retryAfterSeconds 和 status。没有时为 null。HTTP 错误响应体中不包含此字段。重试是否有用:
automatic(服务会自动重试)、manual(需自行重试)、after_configuration(先在 Dify 中修正知识库配置)或 never(需修改请求)。失败所在的阶段,例如
query_generation 或 credential-test。不适用时为 null。HTTP 错误响应体中不包含此字段。联系管理员时需提供的参考编号。在包含失败详情的成功响应中可能为
null,在 HTTP 错误响应体中可能不出现。批量任务中每个失败的文档对应一项。其他类型的任务为
null。Show child attributesHide child attributes
文档 ID。
文档标题。
失败的错误码。
error_code 对应的错误消息。Show child attributesHide child attributes
建议的下一步操作(如有):
configure_model、configure_parser、configure_source、contact_admin、reupload 或 retry。不适用时为 null。HTTP 错误响应体中不包含此字段。失败类别:
authorization、canceled、configuration、conflict、dependency、internal、not_found、rate_limit、timeout 或 validation。稳定的错误码,采用大写蛇形命名,例如
KNOWLEDGE_FS_CONFLICT 或 SOURCE_CREDENTIAL_TEST_FAILED。错误码或失败类别对应的公开消息。不会暴露提供商的错误详情。
描述失败细节的值,最多 8 个,键取自
attempt、currentRowVersion、documentCount、expectedRowVersion、fileSizeBytes、limit、maxFileSizeBytes、maxItems、modelType、providerKind、retryAfterSeconds 和 status。没有时为 null。HTTP 错误响应体中不包含此字段。重试是否有用:
automatic(服务会自动重试)、manual(需自行重试)、after_configuration(先在 Dify 中修正知识库配置)或 never(需修改请求)。失败所在的阶段,例如
query_generation 或 credential-test。不适用时为 null。HTTP 错误响应体中不包含此字段。联系管理员时需提供的参考编号。在包含失败详情的成功响应中可能为
null,在 HTTP 错误响应体中可能不出现。该文档对应任务的 ID(如有)。
知识库的内部 ID,并非路径中的知识库 ID。
任务执行的操作:
document_processing:索引任务。document_reindex、document_upload、document_delete:批量任务。批量上传和批量删除来自 Dify。删除文档 发起的删除也会作为document_delete任务出现。此 API 的其他删除操作只创建删除作业。source_sync、source_crawl_preview、source_crawl_import、source_online_document_import、source_online_drive_import:数据源运行。
已完成的项数。索引任务按其文档计,批量任务按其中的各个文档计,数据源运行按其条目计。
失败的项数,计数方式同
progress_completed。进度,取值 0~100。索引任务的进度取决于任务所处的阶段。
任务中的总项数,计数方式同
progress_completed。索引任务为 1。索引任务发布后的知识图谱构建;其他类型的任务为
null。索引会在发布前建好知识图谱,因此不会安排这一步。任务运行期间 state 为 not_scheduled,任务结束后为 disabled。nodes_completed 始终为 0。Show child attributesHide child attributes
state 为 failed 时的错误码。error_code 对应的错误消息,可能与 failure.message 不同。state 为 failed 时的错误详情,否则为 null。Show child attributesHide child attributes
建议的下一步操作(如有):
configure_model、configure_parser、configure_source、contact_admin、reupload 或 retry。不适用时为 null。HTTP 错误响应体中不包含此字段。失败类别:
authorization、canceled、configuration、conflict、dependency、internal、not_found、rate_limit、timeout 或 validation。稳定的错误码,采用大写蛇形命名,例如
KNOWLEDGE_FS_CONFLICT 或 SOURCE_CREDENTIAL_TEST_FAILED。错误码或失败类别对应的公开消息。不会暴露提供商的错误详情。
描述失败细节的值,最多 8 个,键取自
attempt、currentRowVersion、documentCount、expectedRowVersion、fileSizeBytes、limit、maxFileSizeBytes、maxItems、modelType、providerKind、retryAfterSeconds 和 status。没有时为 null。HTTP 错误响应体中不包含此字段。重试是否有用:
automatic(服务会自动重试)、manual(需自行重试)、after_configuration(先在 Dify 中修正知识库配置)或 never(需修改请求)。失败所在的阶段,例如
query_generation 或 credential-test。不适用时为 null。HTTP 错误响应体中不包含此字段。联系管理员时需提供的参考编号。在包含失败详情的成功响应中可能为
null,在 HTTP 错误响应体中可能不出现。已构建的知识图谱节点数:
state 变为 ready 之前为 0,之后与 nodes_total 相同。需构建的知识图谱节点数。确定之前为
null。目前已发起的模型调用次数。
构建知识图谱最多可发起的模型调用次数。
not_scheduled、pending、running、ready、failed 或 disabled。语义增强最后变更时间,ISO 8601 格式。
数据源运行所属的数据源。
数据源运行所属数据源的名称。仅在未传
task_ids 列出任务时设置。document(索引任务)、document_bulk(批量任务)或 source(数据源运行)。任务最后变更时间,ISO 8601 格式。
文档的来源数据源。上传的文件为
null。pending(尚无生效的修订版本)、ready(已有修订版本生效)、failed(首个修订版本索引失败,且没有生效的修订版本)或 deleting。ready 的文档在后续修订版本失败时仍保持 ready。文档标题。
文档最后变更时间,ISO 8601 格式。