获取数据源列表
按数据源 ID 升序列出知识库的数据源。每个数据源附带其定时同步设置、最近一次完成的同步或导入,以及当前运行;没有正在进行的运行时,改为附带最近一次同步。
数据源的删除请求一经受理,该数据源就不再出现在此列表中。
如何启动和跟踪同步,详见 同步数据源与定时同步。
1 min read
get/knowledge-fs/spaces/{knowledge_base_id}/sources
Request example
curl --request GET \
--url https://api.dify.ai/v1/knowledge-fs/spaces/{knowledge_base_id}/sources \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.dify.ai/v1/knowledge-fs/spaces/{knowledge_base_id}/sources"
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}/sources', {
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}/sources',
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}/sources"
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}/sources"))
.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}/sources')
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
{
"data": [
{
"connection_id": "c3d4e5f6-7a8b-4c9d-8e0f-1a2b3c4d5e6f",
"created_at": "2026-09-01T08:00:00Z",
"credential_configured": null,
"id": "6f1c2b0e-3d0b-4a5e-9f4c-1c0e6a7b8d90",
"knowledge_space_id": "0a9d3c2e-5b6f-4e1a-8c7d-2f3e4a5b6c7d",
"last_synced_at": "2026-09-05T10:12:00Z",
"metadata": {
"client_request_id": "source-20260907-0001",
"providerKind": "website",
"tenantId": "2f1e0d9c-8b7a-4695-8473-2a1b0c9d8e7f"
},
"name": "Docs site",
"permission_scope": [],
"status": "active",
"sync_policy": {
"created_at": "2026-09-01T08:05:00Z",
"custom_interval_seconds": null,
"enabled": true,
"expected_source_version": 7,
"id": "8e7d6c5b-4a39-4f28-9e17-0d1c2b3a4f5e",
"knowledge_space_id": "0a9d3c2e-5b6f-4e1a-8c7d-2f3e4a5b6c7d",
"mode": "interval",
"next_run_at": "2026-09-06T10:00:00Z",
"revision": 2,
"source_id": "6f1c2b0e-3d0b-4a5e-9f4c-1c0e6a7b8d90",
"updated_at": "2026-09-05T10:00:00Z"
},
"sync_workflow": {
"canceled_at": null,
"checkpoint": "source-committed",
"completed_at": "2026-09-05T10:12:00Z",
"created_at": "2026-09-05T10:00:00Z",
"cursor": "ss1:eyJmaW5nZXJwcmludCI6IjgxZDk5OWY4YjI4ZDZhMGFlMTVmNjQxYzE2NjE3ZWNlMTBjYTcxMzE3OWU1MmVhMTYwODYyMzExMDcyYmQ4YmUiLCJraW5kIjoid2Vic2l0ZSIsIm9mZnNldCI6MCwicGhhc2UiOiJlb2YiLCJwcm9ncmVzc0NvbXBsZXRlZCI6NDUsInByb2dyZXNzVG90YWwiOjQ1fQ",
"execution_attempts": 1,
"failure": null,
"id": "d4c3b2a1-6f5e-4d7c-8b9a-0f1e2d3c4b5a",
"kind": "sync",
"knowledge_space_id": "0a9d3c2e-5b6f-4e1a-8c7d-2f3e4a5b6c7d",
"last_error_code": null,
"max_execution_attempts": 5,
"progress_completed": 45,
"progress_failed": 0,
"progress_skipped": 0,
"progress_total": 45,
"source_id": "6f1c2b0e-3d0b-4a5e-9f4c-1c0e6a7b8d90",
"state": "completed",
"updated_at": "2026-09-05T10:12:00Z"
},
"type": "web",
"updated_at": "2026-09-03T09:20:00Z",
"uri": "https://docs.example.com",
"version": 7
}
],
"next_cursor": null
}{
"code": "knowledge_fs_invalid_request",
"message": "Agent Knowledge Base request is invalid.",
"status": 400,
"violations": [
{
"field": [
"limit"
],
"type": "less_than_equal"
}
]
}{
"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"
},
"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"
},
"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",
"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}/sources
Authorization
Path parameters
知识库 ID:即知识库 API 访问 对话框中所示服务 API 端点的最后一段(
…/knowledge-fs/spaces/<knowledge base ID>),也是地址栏中 /datasets/new/ 之后的那一段。Query parameters
Responses
application/json
一页数据源。
本页的数据源。
Show child attributesHide child attributes
数据源获取凭据所用的连接。将其他数据源绑定到同一连接时,将此值作为
connectionId 传入。未绑定时为 null。创建时间,ISO 8601 格式。
数据源持有自己的凭据引用时为
true。未持有时为 null,例如绑定到连接的数据源。数据源 ID。
知识库的内部 ID,并非路径中的知识库 ID。
提供商设置,以及由服务端管理的同步或页面选择数据。可能包含提供商标识和
parameters;由连接管理的设置不一定出现在此处。凭据类的键已移除。创建其他数据源时,不要复制整个对象。显示名称。
读取此数据源所需的内容访问范围。列表为空表示在知识库内不额外限制内容,但知识库本身的授权仍然适用。
active、syncing、error 或 disabled。大多数操作返回存储的值。获取数据源列表 根据最近一次同步运行推导该值:
- 运行为
failed或canceled:error - 运行为
completed或zero_results:active - 有进行中的运行:
syncing
disabled 永远不会被覆盖。
Show child attributesHide child attributes
创建时间,ISO 8601 格式。
mode: custom 时的同步间隔,单位为秒。其他模式为 null。是否运行定时同步。
mode: manual 时始终为 false。定时同步绑定的数据源
version。同步策略 ID,更新后保持不变。
知识库的内部 ID,并非路径中的知识库 ID。
manual(不安排定时同步)、interval(每 24 小时)或 custom(按 custom_interval_seconds 的间隔)。下次定时同步的时间,ISO 8601 格式。没有安排时为
null。定时同步所属的数据源。
最后变更时间,ISO 8601 格式。定时同步开始时也会更新。
Show child attributesHide child attributes
取消运行的时间。仅当
state 为 canceled 时有值,否则为 null。运行已到达的最后一步:
queued、provider-read、preview-staged、selection-frozen、materialized、cleanup-staging 或 source-committed。无论运行停在哪个检查点,重试数据源运行 都会从头开始运行。运行结束(
completed、zero_results、failed 或 canceled)的时间,ISO 8601 格式。运行期间为 null。创建时间,ISO 8601 格式。
运行恢复时所用的提供商游标。运行尚未翻页时为
null。state 为 failed 时的错误详情。其中 stage 为失败时运行的 checkpoint,traceId 为运行 ID。其他情况下为 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 错误响应体中可能不出现。知识库的内部 ID,并非路径中的知识库 ID。
state 为 failed 时为 failure.code 的值,否则为 null。已处理完的项数,包括同步时检查过但未变化的项。
数据源运行始终为
0:任一项失败都会导致整个运行失败。数据源运行始终为
0。运行预计处理的项数:导入请求的页面或条目数、抓取预览目前已暂存的页面数,或同步列出数据源条目后的条目数。确定之前为 null。
导入网站页面 的运行抓取 URL 期间,progress_completed 和 progress_total 都统计目前已抓取的页面数。所有 URL 抓取完成后,进度从 0 重新开始计,总数变为 URL 的数量。
运行所属的数据源。
最后变更时间,ISO 8601 格式。
web(网站抓取)、connector(在线文档或在线云盘)、upload 或 object-storage。
connector 数据源的 metadata.providerKind 为 online-document 或 online-drive,web 数据源则为 website。
upload 和 object-storage 数据源由 Dify 填充。
最后变更时间,ISO 8601 格式。
web 数据源为抓取的根 URL。Dify 创建的连接器数据源为 connector://<connection_id>。下一页的游标,最后一页时为
null。将其作为 cursor 传回。