How API Integration Works
- Build your app in Dify Studio with the AI capabilities you need
- Generate API credentials to securely access your app’s functionality
- Call the API from your application to get AI-powered responses
- Users interact with your custom interface while Dify handles the AI processing
Getting Started
1
Access API settings
In your app, navigate to API Access in the left sidebar.
2
Create API credentials
Generate new credentials for your integration. You can create multiple keys for different environments or users.
3
Review documentation
Dify generates complete API documentation specific to your app’s configuration.
4
Implement in your app
Use the provided examples to integrate API calls into your application.
Text-generation application
These applications are used to generate high-quality text, such as articles, summaries, translations, etc., by calling the completion-messages API and sending user input to obtain generated text results. The model parameters and prompt templates used for generating text depend on the developer’s settings in the Dify Prompt Arrangement page. You can find the API documentation and example requests for this application in Applications -> Access API. For example, here is a sample call an API for text generation:- cURL
- Python
Conversational Applications
Conversational applications facilitate ongoing dialogue with users through a question-and-answer format. To initiate a conversation, you will call thechat-messages API. A conversation_id is generated for each session and must be included in subsequent API calls to maintain the conversation flow.
Important Note: The Service API does not share conversations created by the WebApp. Conversations created through the API are isolated from those created in the WebApp interface.
Key Considerations for conversation_id:
- Generating the
conversation_id: When starting a new conversation, leave theconversation_idfield empty. The system will generate and return a newconversation_id, which you will use in future interactions to continue the dialogue. - Handling
conversation_idin Existing Sessions: Once aconversation_idis generated, future calls to the API should include thisconversation_idto ensure the conversation continuity with the Dify bot. When a previousconversation_idis passed, any newinputswill be ignored. Only thequeryis processed for the ongoing conversation. - Managing Dynamic Variables: If there is a need to modify logic or variables during the session, you can use conversation variables (session-specific variables) to adjust the bot’s behavior or responses.
chat-messages API:
- cURL
- Python