2.26Official DeepSeek Integration

Created on Aug 17, 2026~6 min read

DeepSeek is a multifunctional artificial intelligence model developed by DeepSeek, capable of chat, writing, programming, data analysis, translation, and educational tutoring. Its powerful understanding ability and fast learning speed make it suitable for a variety of scenarios, with great potential for future development.

Before integrating the DeepSeek AI model, you need to first register an account and create an API key on the DeepSeek development platform. After obtaining the API key, you can integrate the DeepSeek AI model into your project. The framework provides several ways to integrate the DeepSeek AI model:

1. Standard output (non-streaming)

Standard output (non-streaming) means sending the user prompt all at once and returning the final result. The result is presented all at once, which is suitable for scenarios that require complete output:

cs
[HttpGet]public async Task<string> DeepSeek(CancellationToken cancellationToken){    var result = await httpRemoteService.PostAsStringAsync("https://api.deepseek.com/chat/completions", HttpRequestBuilder.Setup        .AddBearerAuthentication("your-api-key")        .SetJsonContent("""                        {                            "model": "deepseek-v4-pro",                            "messages": [                                {"role": "system", "content": "You are a professional C# domain expert."},                                {"role": "user", "content": "What is the future of the Furion framework?"}                            ],                            "stream": false                        }                        """), cancellationToken);    // Parse the JSON content (using a mutable object is recommended)    var node = JsonNode.Parse(result!);    var content = node?["choices"]?[0]?["message"]?["content"]?.GetValue<string?>();    return content ?? string.Empty;}

2. Streaming output (Server-Sent Events)

Streaming output can simulate the effect of a typewriter and is ideal for scenarios that require progressively displaying results. The main difference from the standard output mode is that you need to set the stream parameter to true and use Server-Sent Events to implement unidirectional communication. The framework has built-in support for Server-Sent Events and can be used directly:

cs
[HttpGet]public async Task<string> DeepSeek_Stream(CancellationToken cancellationToken){    var builder = HttpRequestBuilder.ServerSentEvents("https://api.deepseek.com/chat/completions")        .AddBearerAuthentication("your-api-key")        .SetJsonContent("""                        {                            "model": "deepseek-v4-pro",                            "messages": [                                {"role": "system", "content": "You are a professional C# domain expert."},                                {"role": "user", "content": "Who is the author of the Furion framework?"}                            ],                            "stream": true                        }                        """);    await foreach (var data in httpRemoteService.SendAsAsyncEnumerable(builder, cancellationToken))    {        // Output complete        if (data.IsDone)        {            Console.WriteLine("++++++++++++ End ++++++++++++");            break;        }        // Parse the JSON content (using a mutable object is recommended)        var node = JsonNode.Parse(data.Data);        var content = node?["choices"]?[0]?["delta"]?["content"]?.GetValue<string?>();        if (!string.IsNullOrEmpty(content))        {            Console.WriteLine(content);        }    }    return "OK";}

3. Streaming output (Server-Sent Events) via the browser URL address (Web)

You can also achieve the streaming output effect by accessing a URL address in the browser:

cs
[HttpGet]public async Task DeepSeekChat([FromServices] IHttpContextAccessor httpContextAccessor, [FromQuery] string message, CancellationToken cancellationToken){    var httpContext = httpContextAccessor.HttpContext!;    // Configure the standard Server-Sent Events (SSE) streaming response format    httpContext.Response.EnableServerSentEvents();    var builder = HttpRequestBuilder.ServerSentEvents("https://api.deepseek.com/chat/completions")        .AddBearerAuthentication("your-api-key")        .SetJsonContent($$"""                            {                            "model": "deepseek-v4-pro",                            "messages": [                                {"role": "system", "content": "You are a professional C# domain expert."},                                {"role": "user", "content": "{{message}}"}                            ],                            "stream": true                            }                            """);    await foreach (var data in httpRemoteService.SendAsAsyncEnumerable(builder, cancellationToken))    {        // DeepSeek output completion flag        if (data.IsDone) return;        // Parse the JSON content (using a mutable object is recommended)        var node = JsonNode.Parse(data.Data);        var content = node?["choices"]?[0]?["delta"]?["content"]?.GetValue<string?>();        // Write a message to the client and flush the response stream immediately        await httpContext.Response.WriteAndFlushAsync(content, cancellationToken);    }    await httpContext.Response.CompleteAsync();}

Open a browser and visit the following address to experience the streaming output effect: https://localhost:7044/GetStart/DeepSeekChat?message=How is the Furion framework. As shown in the image below: