DifySDK.Extensions
0.2.1
dotnet add package DifySDK.Extensions --version 0.2.1
NuGet\Install-Package DifySDK.Extensions -Version 0.2.1
<PackageReference Include="DifySDK.Extensions" Version="0.2.1" />
<PackageVersion Include="DifySDK.Extensions" Version="0.2.1" />
<PackageReference Include="DifySDK.Extensions" />
paket add DifySDK.Extensions --version 0.2.1
#r "nuget: DifySDK.Extensions, 0.2.1"
#:package DifySDK.Extensions@0.2.1
#addin nuget:?package=DifySDK.Extensions&version=0.2.1
#tool nuget:?package=DifySDK.Extensions&version=0.2.1
DifySDK.Extensions
Registers all Dify Service API Refit clients with source-generated JSON serialization and Authorization: Bearer API-key authentication.
Install
dotnet add package DifySDK.Extensions
Register with dependency injection
using DifySDK.Extensions;
services.AddDifyApi(configuration);
{
"DifyApi": {
"BaseAddress": "https://api.dify.ai/v1/",
"ApiKey": "app-your-api-key"
}
}
Then inject a typed API interface and make requests:
using DifySDK.Chats;
using DifySDK.Models;
public sealed class ChatService(IDifyChatApi chat)
{
public async Task<string?> AskAsync(string question, CancellationToken cancellationToken)
{
var response = await chat.SendAsync(new ChatMessageRequest
{
Query = question,
User = "user-123"
}, cancellationToken: cancellationToken);
return response.Answer;
}
}
Select an application per request
For the default single application, AddDifyApi registers a resolver based on DifyApiOptions. When one process calls multiple Dify applications, register your own IDifyApplicationCredentialResolver to replace it. Passing DifyRequestContext through the Refit [Property] parameter selects that application's base address and API key for only this request.
using DifySDK;
using DifySDK.Chats;
using DifySDK.Models;
var response = await chat.SendAsync(
new ChatMessageRequest
{
Query = "Hello",
User = "user-123"
},
context: new DifyRequestContext { ApplicationId = "support-bot" },
cancellationToken: cancellationToken);
Create a client set for one application
IDifyClientFactory creates an isolated set of all typed API clients for an application:
using DifySDK.Extensions;
var client = await clientFactory.CreateAsync("support-bot", cancellationToken);
var info = await client.Application.GetInfoAsync(cancellationToken: cancellationToken);
var answer = await client.Chat.SendAsync(new ChatMessageRequest
{
Query = "Hello",
User = "user-123"
}, cancellationToken: cancellationToken);
| Product | Versions 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. |
-
net10.0
- DifySDK (>= 0.2.1)
- Microsoft.Extensions.Http (>= 10.0.9)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.9)
- Refit.HttpClientFactory (>= 13.1.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on DifySDK.Extensions:
| Package | Downloads |
|---|---|
|
DifySDK.ConsoleApi.Extensions
A typed .NET client for the Dify API |
GitHub repositories
This package is not used by any popular GitHub repositories.
fix dependency inject
**Full Changelog**: https://github.com/LGinC/DifySDK/compare/v0.2...v0.2.1