© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
5 replies
Vortac

How to use Server Sent Events with HttpClient

I'm working with an API framework (https://docs.mistral.ai/api/#operation/createChatCompletion) in which you send a chat request. If you set the stream parameter to true:

tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message. Otherwise, the server will hold the request open until the timeout or until completion, with the response containing the full result as JSON.
tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message. Otherwise, the server will hold the request open until the timeout or until completion, with the response containing the full result as JSON.


To handle this, I created an SssEvent class with the following properties:

public string EventType { get; set; }
public string Data { get; set; }
public string EventType { get; set; }
public string Data { get; set; }

I have the code working for non-streaming calls, but I'm confused as to how to send my initial message and then stream back the response. My code currently looks like this:

https://paste.mozilla.org/BD3gMX5o
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ DI with HttpClient / HttpClientFactory
C#CC# / help
3y ago
how to set HttpClientHandler when registering typed HttpClient?
C#CC# / help
13mo ago
How to use certificate on HttpClient
C#CC# / help
4y ago
How to use the same HttpClient instance with different session cookies / proxies?
C#CC# / help
2y ago