API specification that your external knowledge service must implement to integrate with Dify
This page defines the API contract your external knowledge service must implement for Dify to retrieve content from it. Once your API is ready, see Connect to External Knowledge Base to register it in Dify.
POST {your-endpoint}/retrievalContent-Type: application/jsonAuthorization: Bearer {API_KEY}
Dify appends /retrieval to the endpoint URL you configured. If you registered https://your-service.com, Dify sends requests to https://your-service.com/retrieval.
The identifier of the knowledge source in your external system. This is the value you entered in the External Knowledge ID field when connecting. Use it to route queries to the correct knowledge source.
Dify passes metadata conditions to your API but does not currently provide a UI for users to configure them. This parameter is available for programmatic use only.
Property
Required
Type
Description
logical_operator
No
string
and or or. Default: and.
conditions
Yes
array[object]
List of filter conditions.
Each object in conditions:
Property
Required
Type
Description
name
Yes
string
Metadata field name to filter on.
comparison_operator
Yes
string
Comparison operator. See supported values below.
value
No
string, number, or array[string]
Comparison value. Omit when using empty or not empty.
Dify checks the HTTP status code of your response. A non-200 status raises an error that surfaces to the user.You can optionally return structured error information in JSON:
Property
Type
Description
error_code
int
An application-level error code you define.
error_msg
string
A human-readable error description.
The following are suggested error codes. These are conventions, not enforced by Dify: