DifySDK 0.2.1

dotnet add package DifySDK --version 0.2.1
                    
NuGet\Install-Package DifySDK -Version 0.2.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DifySDK" Version="0.2.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DifySDK" Version="0.2.1" />
                    
Directory.Packages.props
<PackageReference Include="DifySDK" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DifySDK --version 0.2.1
                    
#r "nuget: DifySDK, 0.2.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DifySDK@0.2.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DifySDK&version=0.2.1
                    
Install as a Cake Addin
#tool nuget:?package=DifySDK&version=0.2.1
                    
Install as a Cake Tool

DifySDK

Native AOT-compatible Refit interfaces and source-generated System.Text.Json metadata for the Dify API.

For dependency-injection registration and API-key authentication, install DifySDK.Extensions.

Install

dotnet add package DifySDK

Create a client directly

using System.Net.Http.Headers;
using System.Text.Json;
using DifySDK.Chats;
using DifySDK.Models;
using DifySDK.Serialization;
using Refit;

var httpClient = new HttpClient
{
    BaseAddress = new Uri("https://api.dify.ai/v1/")
};
httpClient.DefaultRequestHeaders.Authorization =
    new AuthenticationHeaderValue("Bearer", "app-your-api-key");

var settings = new RefitSettings(
    new SystemTextJsonContentSerializer(new JsonSerializerOptions(JsonSerializerDefaults.Web)
    {
        TypeInfoResolver = DifyJsonSerializerContext.Default
    }));

var chat = RestService.For<IDifyChatApi>(httpClient, settings);
var response = await chat.SendAsync(new ChatMessageRequest
{
    Query = "What can you do?",
    User = "user-123",
    InputValues = new Dictionary<string, object?>
    {
        ["language"] = "en"
    }
});

Console.WriteLine(response.Answer);

InputValues lets callers use ordinary .NET values. The SDK converts them to the Dictionary<string, JsonElement> shape required by Dify without reflection, which is suitable for Native AOT.

Consume streaming responses

Use the IAsyncEnumerable<DifyStreamEvent> extension for all supported SSE endpoints.

using DifySDK.Chats;
using DifySDK.Models;
using DifySDK.Streaming;

await foreach (var streamEvent in chat.StreamAsync(new ChatMessageRequest
{
    Query = "Write a haiku about APIs",
    User = "user-123"
}))
{
    if (streamEvent is DifyMessageStreamEvent message)
        Console.Write(message.Answer);

    if (streamEvent is DifyErrorStreamEvent error)
        Console.Error.WriteLine(error.Message);
}

The same pattern is available for completions, workflows, workflow event reconnection, knowledge-base pipeline runs, and datasource-node runs.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

NuGet packages (1)

Showing the top 1 NuGet packages that depend on DifySDK:

Package Downloads
DifySDK.Extensions

A typed .NET client for the Dify API

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.1 124 7/13/2026
0.2.0 124 7/11/2026
0.1.1 119 7/11/2026

fix dependency inject
**Full Changelog**: https://github.com/LGinC/DifySDK/compare/v0.2...v0.2.1