Skip to main content
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.

Authentication

Dify sends the API Key you configured as a Bearer token in every request:
You define the authentication logic on your side. Dify only passes the key—it does not validate it.

Request

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.

Body

retrieval_setting

metadata_condition

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.
Each object in conditions:

Example Request

Response

Return HTTP 200 with a JSON body containing a records array. If no results match the query, return an empty array: {"records": []}.

records

Dify does not reject records with missing fields, but omitting content or score will produce incomplete or unranked results.
If you include metadata in a record, it must be an object ({}), not null. A null metadata value causes errors in Dify’s retrieval pipeline.

Example Response

Error Handling

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: The following are suggested error codes. These are conventions, not enforced by Dify:

Example Error Response

Last modified on June 6, 2026