Dify provides a complete set of Knowledge Base APIs that let you manage knowledge bases, documents, and chunks programmatically. This is useful for automating data synchronization or integrating knowledge base operations into CI/CD pipelines.
API access is enabled by default when you create a knowledge base. To start making API calls, all you need is your API credentials: an endpoint and a key.
A single Knowledge Base API key has access to all visible knowledge bases under the same account. Handle your credentials carefully to avoid unintended data exposure.
Get Your API Endpoint and Key
Navigate to Knowledge in Dify. In the top-right corner, click Service API to open the API configuration panel. From here you can:
-
Get the Service API endpoint. This is the base URL for all Knowledge Base API requests.
-
Click API Key to create new keys and manage existing ones.
Store your API key securely on the server side. Never expose it in client-side code or public repositories.
Manage API Access for a Knowledge Base
Every knowledge base is accessible via the Service API by default.
If you want to restrict API access to a specific knowledge base, open it, then click API Access in the bottom-left corner and toggle it off.
API Reference
See the Knowledge Base API Reference for the complete list of endpoints, request/response schemas, error codes, and interactive examples.