moderationSensitive content moderationexternal_data_toolExternal data tools
API Specification
Dify will call your interface with the following specification:Header
Request Body
API Response
Validation
When configuring a custom endpoint in Dify, Dify will send a request to the API Endpoint to verify API availability. When the API Endpoint receivespoint=ping, the interface should return result=pong, as follows:
Header
Request Body
Expected API Response
Example
Here we use an external data tool as an example, where the scenario is to retrieve external weather information by region as context.API Example
Code Example
The code is based on the Python FastAPI framework.-
Install dependencies
-
Write code according to the interface specification
-
Start the API service. The default port is 8000, the complete API address is:
http://127.0.0.1:8000/api/dify/receive, and the configured API Key is123456. - Configure this API in Dify.
- Select this custom endpoint in the App.
Local Debugging
Because Dify cannot reach API services on your private network, you can use Ngrok to expose the API service endpoint to the public network to enable cloud debugging of local code. Steps:-
Go to https://ngrok.com, register and download the Ngrok file.

-
After downloading, go to the download directory, extract the archive according to the instructions below, and execute the initialization script in the instructions.
-
Check the port of your local API service:
And run the following command to start:
A successful startup example looks like this:
-
Find the Forwarding address, as shown above:
https://177e-159-223-41-52.ngrok-free.app(this is an example domain, please replace with your own), which is the public domain.
http://127.0.0.1:8000/api/dify/receive with https://177e-159-223-41-52.ngrok-free.app/api/dify/receive
This API endpoint can now be accessed publicly. At this point, we can configure this API endpoint in Dify for local code debugging. For configuration steps, please refer to External Data Tool.