You can extend module capabilities through custom endpoints. Currently, the following extension types are supported:
moderation Sensitive content moderation
external_data_tool External data tools
Before extending module capabilities, you need to prepare an API and an API Key for authentication.
In addition to developing the corresponding module capabilities, you also need to follow the specifications below to ensure Dify correctly calls the API.
API Specification
Dify will call your interface with the following specification:
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 receives point=ping, the interface should return result=pong, as follows:
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
Header
Request Body
API Response
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 is 123456.
-
Configure this API in Dify.
-
Select this custom endpoint in the App.
When debugging the App, Dify will request the configured API and send the following content (example):
The API response is:
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.
Following the example above, we expose the locally started service endpoint and replace the code example interface: 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.
Deploy Custom Endpoints Using Cloudflare Workers
We recommend using Cloudflare Workers to deploy your custom endpoints because Cloudflare Workers can conveniently provide a public network address and can be used for free.
For detailed instructions, see Deploy Custom Endpoints Using Cloudflare Workers. Last modified on July 2, 2026