删除数据源
请求删除数据源,并返回删除作业。
已删除数据源的文档如何处理,详见 删除文档和数据源。
1 min read
delete/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id}
Request example
curl --request DELETE \
--url https://api.dify.ai/v1/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id} \
--header 'Authorization: Bearer <token>' \
--header 'Idempotency-Key: <string>' \
--header 'Content-Type: application/json' \
--data '{
"expectedRevision": 8
}'import requests
url = "https://api.dify.ai/v1/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id}"
headers = {
"Authorization": "Bearer <token>",
"Idempotency-Key": "<string>",
"Content-Type": "application/json",
}
payload = {
"expectedRevision": 8
}
response = requests.request("DELETE", url, headers=headers, json=payload)
print(response.text)const response = await fetch('https://api.dify.ai/v1/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id}', {
method: 'DELETE',
headers: {
'Authorization': 'Bearer <token>',
'Idempotency-Key': '<string>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"expectedRevision": 8
})
});
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/{source_id}',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'DELETE',
CURLOPT_POSTFIELDS => '{
"expectedRevision": 8
}',
CURLOPT_HTTPHEADER => [
'Authorization: Bearer <token>',
'Idempotency-Key: <string>',
'Content-Type: application/json',
],
]);
$response = curl_exec($curl);
curl_close($curl);
echo $response;package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func main() {
url := "https://api.dify.ai/v1/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id}"
payload := strings.NewReader("{\n \"expectedRevision\": 8\n}")
req, _ := http.NewRequest("DELETE", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Idempotency-Key", "<string>")
req.Header.Add("Content-Type", "application/json")
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/{source_id}"))
.header("Authorization", "Bearer <token>")
.header("Idempotency-Key", "<string>")
.header("Content-Type", "application/json")
.method("DELETE", HttpRequest.BodyPublishers.ofString("{\n \"expectedRevision\": 8\n}"))
.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/{source_id}')
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = url.scheme == 'https'
request = Net::HTTP::Delete.new(url)
request['Authorization'] = 'Bearer <token>'
request['Idempotency-Key'] = '<string>'
request['Content-Type'] = 'application/json'
request.body = '{
"expectedRevision": 8
}'
response = http.request(request)
puts response.read_bodyResponse
{
"document_title": null,
"job": {
"checkpoint": "requested",
"completed_at": null,
"created_at": "2026-09-06T02:00:00Z",
"error": null,
"id": "b2f1d3e4-5c6a-4b7d-8e9f-0a1b2c3d4e5f",
"knowledge_space_id": "0a9d3c2e-5b6f-4e1a-8c7d-2f3e4a5b6c7d",
"mode": "keep",
"progress": null,
"retry_at": null,
"run_state": "dispatch_pending",
"target_id": "6f1c2b0e-3d0b-4a5e-9f4c-1c0e6a7b8d90",
"target_type": "source",
"updated_at": "2026-09-06T02:00:00Z"
},
"status_url": "https://api.example.com/v1/knowledge-fs/spaces/8d2c6a1e-5b3f-4c7d-9e01-2a3b4c5d6e7f/deletion-jobs/b2f1d3e4-5c6a-4b7d-8e9f-0a1b2c3d4e5f"
}{
"code": "knowledge_fs_invalid_request",
"message": "Agent Knowledge Base request is invalid.",
"status": 400,
"violations": [
{
"field": [
"expectedRevision"
],
"type": "missing"
}
]
}{
"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": "5e2a9c17-3b4d-4f60-8a1b-2c3d4e5f6a7b"
},
"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"
},
"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_conflict",
"failure": {
"category": "conflict",
"code": "DURABLE_DELETION_IDEMPOTENCY_CONFLICT",
"message": "The Agent Knowledge Base operation conflicts with the current resource state.",
"retryPolicy": "never",
"traceId": "5e2a9c17-3b4d-4f60-8a1b-2c3d4e5f6a7b"
},
"message": "The Agent Knowledge Base operation conflicts with the current resource state.",
"status": 409
}{
"code": "knowledge_fs_conflict",
"failure": {
"action": "retry",
"category": "conflict",
"code": "KNOWLEDGE_FS_CONFLICT",
"message": "The Agent Knowledge Base operation conflicts with the current resource state.",
"retryPolicy": "manual"
},
"message": "The Agent Knowledge Base operation conflicts with the current resource state.",
"status": 409
}{
"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
}delete/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id}
Authorization
Path parameters
知识库 ID:即知识库 API 访问 对话框中所示服务 API 端点的最后一段(
…/knowledge-fs/spaces/<knowledge base ID>),也是地址栏中 /datasets/new/ 之后的那一段。Query parameters
Headers
用同一个 API 密钥重复发送相同的键和请求,会以
202 返回原作业。将该键用于其他请求,或通过其他 API 密钥使用,会返回 409。使用可打印 ASCII 字符,首尾不得有空白。Length: 8–255
Body
application/jsonResponses
application/json
删除数据源时始终为
null。删除作业。
target_type 为 source,mode 回显传入的 documents。Show child attributesHide child attributes
删除进行到哪一步:从
requested(刚受理)开始,依次经过 quiescing、deleting_objects、deleting_derived_data、deleting_primary_data,直到 completed。作业完成时间,ISO 8601 格式。完成前以及作业为
failed 时为 null。作业的受理时间,ISO 8601 格式。
最近一次错误,没有错误时为
null。run_state 为 retry_wait 时也会设置此字段,因此判断作业是否失败应看 run_state,而不是 error。删除作业 ID。
知识库的内部 ID,并非路径中的知识库 ID。
删除数据源时如何处理其文档:
cascade 一并删除,keep 保留。删除文档文件或文档时,忽略该值。多项删除的项数统计。此 API 不填充该字段,始终为
null。下次自动重试的时间,ISO 8601 格式。未安排重试时为
null。调度状态:
dispatch_pending(刚受理)、queued、running:进行中。retry_wait:已安排在retry_at自动重试。completed:已全部移除。failed:清理已停止,删除目标仍保持隐藏,且无法重试。
删除目标的 ID:
document 时为文档文件 ID,logical_document 时为文档 ID,source 时为数据源 ID。作业删除的对象:
document 表示文档文件,logical_document 表示整个文档,source 表示数据源。作业最后变更时间,ISO 8601 格式。
删除作业在此 API 中的 URL:部署设置了
SERVICE_API_URL 时为绝对 URL,否则为以 /v1/ 开头的路径。Location 响应头中返回相同的值。