Here's the English version of the README for the Dify API Java SDK:
The Dify API Java Client is a Java client library for interacting with the Dify platform. It provides full support for Dify's application API and knowledge base API, allowing Java developers to easily integrate Dify's generative AI capabilities into their applications.
The Dify API Java Client offers the following core features:
DifyChatApi to call conversational applications, supporting session management, message feedback, and more.DIfyCompletionApi to call text generation applications.DifyChayflowApi to call workflow orchestrated conversational applications.DifyWorkflowApi to call workflow applications.DifyDatasetsApi to manage knowledge bases, documents, and retrieval.<dependency>
<groupId>io.github.chat-pass</groupId>
<artifactId>dify-api-java-sdk</artifactId>
<version>1.0.1.FINAL</version>
</dependency>
// Environment configuration
Map<String,String> envs = System.getenv();
DifyChatApi difyChatApi = DifyApiFactory.newInstance(envs.get("DIFY_BASE_URL"),envs.get("DIFY_API_KEY")).newDifyChatApi();
// Send chat message
ChatMessageRequest request = new ChatMessageRequest();
request.setUser("test-user");
request.setQuery("Hello, please introduce yourself");
request.setResponseMode(ResponseMode.BLOCKING);
ChatMessageResponse response = difyChatApi.sendChatMessage(request);
System.out.println(response.getAnswer());
This SDK provides rich functional examples covering all major use cases:
🔗 View Complete Examples Documentation →
The examples documentation includes:
- 🚀 Basic API Examples - Application info retrieval, parameter configuration
- 💬 Conversational Applications - Blocking and streaming chat, message handling
- ⚡ Workflow Applications - Execution, monitoring, log management
- 📊 Dataset Management - Knowledge base creation, document management, semantic retrieval
- 🎵 Audio Processing - Text-to-speech, speech-to-text
- 📁 File Management - File upload, processing
- 🛠️ Best Practices - Error handling, performance optimization, concurrent processing
| Client Type | Description | Main Features |
|---|---|---|
DifyBaseApi |
General base API for Dify | Get application info, file upload/download, etc. |
DifyChatApi |
Conversational application client | Conversations, session management, message feedback |
DifyCompletionApi |
Text generation application client | Text generation, stop generation |
DifyChatFlowApi |
Workflow orchestrated conversation client | Workflow orchestrated conversations |
DifyWorkflowApi |
Workflow application client | Execute workflows, workflow management |
DifyDatasetsApi |
Knowledge base client | Knowledge base management, document management, retrieval |
| Mode | Enum Value | Description |
|---|---|---|
| Blocking | ResponseMode.BLOCKING |
Synchronous call, waiting for a complete response |
| Streaming | ResponseMode.STREAMING |
Receive real-time generated content via callbacks |
| Event Type | Description |
|---|---|
MessageEvent |
Message event, includes generated text fragments |
MessageEndEvent |
Message end event, includes complete message ID |
MessageFileEvent |
File message event, includes file information |
TtsMessageEvent |
Text-to-speech event |
TtsMessageEndEvent |
Text-to-speech end event |
MessageReplaceEvent |
Message replace event |
AgentMessageEvent |
Agent message event |
AgentThoughtEvent |
Agent thought event |
WorkflowStartedEvent |
Workflow started event |
NodeStartedEvent |
Node started event |
NodeFinishedEvent |
Node finished event |
WorkflowFinishedEvent |
Workflow finished event |
ErrorEvent |
Error event |
PingEvent |
Ping event |
// Create custom configuration
OkHttpClient customClient = new OkHttpClient.Builder()
.callTimeout(30, TimeUnit.SECONDS)
.pingInterval(15, TimeUnit.SECONDS)
.build();
DIfyApiServiceGenerator.configureHttpClient(customClient);
DIfyApiServiceGenerator.setHttpProxy("proxy.example.com", 8080, "username", "password");
Contributions, issue reports, and suggestions for improvements are welcome. Please participate in project development through GitHub Issues or Pull Requests.
This project is licensed under the Apache License 2.0.
$ claude mcp add dify-api-java-sdk \
-- python -m otcore.mcp_server <graph>