Developers can extend module capabilities through the API extension module. Currently supported module extensions include:
moderation
external_data_tool
Before extending module capabilities, prepare an API and an API Key for authentication, which can also be automatically generated by Dify. In addition to developing the corresponding module capabilities, follow the specifications below so that Dify can invoke the API correctly.
Dify will invoke your API according to the following specifications:
Header | Value | Desc |
---|---|---|
Content-Type | application/json | The request content is in JSON format. |
Authorization | Bearer {api_key} | The API Key is transmitted as a token. You need to parse the api_key and verify if it matches the provided API Key to ensure API security. |
When configuring API-based Extension in Dify, Dify will send a request to the API Endpoint to verify the availability of the API. When the API Endpoint receives point=ping
, the API should return result=pong
, as follows:
Here we take the external data tool as an example, where the scenario is to retrieve external weather information based on the region as context.
POST https://fake-domain.com/api/dify/receive
The code is based on the Python FastAPI framework.
The default port is 8000. The complete address of the API is: http://127.0.0.1:8000/api/dify/receive
with the configured API Key ‘123456’.
When debugging the App, Dify will request the configured API and send the following content (example):
API Response:
Since Dify’s cloud version can’t access internal network API services, you can use Ngrok to expose your local API service endpoint to the public internet for cloud-based debugging of local code. The steps are:
Run the following command to start:
Upon successful startup, you’ll see something like the following:
https://177e-159-223-41-52.ngrok-free.app
, and use it as your public domain.http://127.0.0.1:8000/api/dify/receive
with https://177e-159-223-41-52.ngrok-free.app/api/dify/receive
.Now, this API endpoint is accessible publicly. You can configure this endpoint in Dify for local debugging. For the configuration steps, consult the appropriate documentation or guide.
We recommend that you use Cloudflare Workers to deploy your API extension, because Cloudflare Workers can easily provide a public address and can be used for free.
Deploy API Tools with Cloudflare Workers
Edit this page | Report an issue
Developers can extend module capabilities through the API extension module. Currently supported module extensions include:
moderation
external_data_tool
Before extending module capabilities, prepare an API and an API Key for authentication, which can also be automatically generated by Dify. In addition to developing the corresponding module capabilities, follow the specifications below so that Dify can invoke the API correctly.
Dify will invoke your API according to the following specifications:
Header | Value | Desc |
---|---|---|
Content-Type | application/json | The request content is in JSON format. |
Authorization | Bearer {api_key} | The API Key is transmitted as a token. You need to parse the api_key and verify if it matches the provided API Key to ensure API security. |
When configuring API-based Extension in Dify, Dify will send a request to the API Endpoint to verify the availability of the API. When the API Endpoint receives point=ping
, the API should return result=pong
, as follows:
Here we take the external data tool as an example, where the scenario is to retrieve external weather information based on the region as context.
POST https://fake-domain.com/api/dify/receive
The code is based on the Python FastAPI framework.
The default port is 8000. The complete address of the API is: http://127.0.0.1:8000/api/dify/receive
with the configured API Key ‘123456’.
When debugging the App, Dify will request the configured API and send the following content (example):
API Response:
Since Dify’s cloud version can’t access internal network API services, you can use Ngrok to expose your local API service endpoint to the public internet for cloud-based debugging of local code. The steps are:
Run the following command to start:
Upon successful startup, you’ll see something like the following:
https://177e-159-223-41-52.ngrok-free.app
, and use it as your public domain.http://127.0.0.1:8000/api/dify/receive
with https://177e-159-223-41-52.ngrok-free.app/api/dify/receive
.Now, this API endpoint is accessible publicly. You can configure this endpoint in Dify for local debugging. For the configuration steps, consult the appropriate documentation or guide.
We recommend that you use Cloudflare Workers to deploy your API extension, because Cloudflare Workers can easily provide a public address and can be used for free.
Deploy API Tools with Cloudflare Workers
Edit this page | Report an issue