
Product
Introducing Repository Access Permissions and Custom Roles
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.
@beedick/dify-ai-provider
Advanced tools
A provider for Dify.AI to work with Vercel AI SDK.
This provider allows you to easily integrate Dify AI's application workflow with your applications using the Vercel AI SDK.
<think>...</think> tags for AI reasoning processTo use this provider, you'll need:
https://cloud.dify.ai/app/${dify-application-id}/workflownpm install dify-ai-provider
# pnpm
pnpm add dify-ai-provider
# yarn
yarn add dify-ai-provider
import { generateText } from "ai";
import { difyProvider } from "dify-ai-provider";
process.env.DIFY_API_KEY = "dify-api-key"; // app-...
// Create a Dify provider instance
const dify = difyProvider("dify-application-id", {
responseMode: "blocking",
});
// Generate text using Dify AI
const { text, providerMetadata } = await generateText({
model: dify,
messages: [{ role: "user", content: "Hello, how are you today?" }],
headers: { "user-id": "test-user" },
});
const { conversationId, messageId } = providerMetadata.difyWorkflowData;
console.log(text);
console.log("conversationId", conversationId);
console.log("messageId", messageId);
You can continue a conversation by providing a chat-id and user-id in request header:
const { text: followUpText } = await generateText({
model: dify,
messages: [
{ role: "user", content: "That's great! What can you help me with?" },
],
headers: { "user-id": "test-user", "chat-id": conversationId },
});
console.log("followUpText", followUpText);
import { streamText } from "ai";
import { difyProvider } from "dify-ai-provider";
const dify = difyProvider("dify-application-id");
const result = streamText({
model: dify,
messages: [{ role: "user", content: "Explain quantum computing with deep thinking." }],
headers: { "user-id": "user-123" }
});
// Monitor the complete AI process
for await (const part of result.fullStream) {
switch (part.type) {
case 'reasoning-start':
console.log('🤔 AI is thinking...');
break;
case 'reasoning-delta':
console.log(`💭 Thought: ${part.delta}`);
break;
case 'text-delta':
process.stdout.write(part.delta); // Real-time answer
break;
case 'raw':
const event = part.rawValue as any;
if (event.difyEvent === 'workflow_started') {
console.log(`🚀 Workflow started: ${event.workflow_run_id}`);
} else if (event.difyEvent === 'node_finished') {
console.log(`✅ Node completed in ${event.duration}s`);
}
break;
case 'finish':
const execution = part.providerMetadata?.dify?.workflowExecution;
console.log(`🎉 Complete! Workflow took ${execution?.duration}s`);
break;
}
}
import { createDifyProvider } from "dify-ai-provider";
const difyProvider = createDifyProvider({
baseURL: "your-base-url",
});
const dify = difyProvider("dify-application-id", {
responseMode: "blocking",
apiKey: "dify-api-key",
});
Next.js AI Chatbot is a full-featured, hackable Next.js AI chatbot built by Vercel. If you want to use it as a chatbot frontend for a Dify application, follow the guidelines below:
You can retrieve the Dify conversation ID from the onFinish callback:
onFinish: async ({ response, providerMetadata }) => {
const conversationId = providerMetadata?.difyWorkflowData?.conversationId as string;
const messageId = providerMetadata?.difyWorkflowData?.messageId as string;
// Save conversationId for future use
}
Pass the user ID and conversation ID in the headers when calling streamText:
Important: The
conversation_idmust be obtained from a Dify response. Using an invalid conversation ID will result in an error stating that the conversation does not exist.
const stream = createDataStream({
execute: (dataStream) => {
const headers = {
'user-id': session.user.id,
'chat-id': conversation_id_returned_from_dify
};
const result = streamText({
model: myProvider.languageModel(selectedChatModel),
headers,
// ... other options
});
// ... rest of implementation
}
// ... other options
});
The provider emits various event types through the AI SDK's streaming interface:
text-start / text-delta / text-end - Answer contentreasoning-start / reasoning-delta / reasoning-end - AI thinking process (from <think> tags)response-metadata - Basic response informationfinish - Completion with usage statistics and execution reportraw type)workflow_started - Workflow execution beginsworkflow_finished - Workflow execution completesnode_started / node_finished - Individual node executionagent_thought - Agent reasoning and tool usagedifyProvider(modelId, settings?)Creates a Dify chat model instance.
baseURL (string): The base URL for the Dify API. Default is https://api.dify.ai/v1headers (Record<string, string>): Additional headers for API requestsinputs (object): Additional inputs to send with the requestresponseMode (string): Response mode, defaults to "streaming"apiKey (string): Your Dify application API key. If not provided, uses DIFY_API_KEY environment variableuser-id (required): Unique identifier for the end userchat-id (optional): Conversation ID to continue existing conversationsFAQs
Dify provider for Vercel AI SDK
We found that @beedick/dify-ai-provider demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.

Product
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.