I use .NET sdk for Chatgpt responses API. And as a response I have just text, without new lines or lists, how I can handle at least new lines? I’m trying to replace \n with
but I don’t receive any \n symbols
The API does include line breaks, but depending on how you read the response in .NET, you might not see the literal \n characters.
A few things to check:
- .NET SDK returns actual newline characters, not the escaped \n text.
So instead of seeing \n in the string, the response contains real line breaks.
To verify, log the raw string like this:
Console.WriteLine(response.Content);
If the model produced multiple lines, you’ll see them here even if you don’t see \n literally.
- If your model output looks “flattened”, set response_format explicitly to preserve formatting:
response_format: new { type = "text" }
Or ensure you’re not post-processing the string somewhere (trimming, HTML encoding, replacing whitespace etc).
- If you really want the literal \n symbols, you can encode them yourself:
var normalized = response.Content
.Replace("\r\n", "\\n")
.Replace("\n", "\\n");
But again, the SDK doesn’t give escaped characters unless you create them manually.
In short:
The API is sending newlines, they’re just actual newlines, not printed \n sequences.
Check the raw output and ensure nothing in your pipeline strips or normalizes whitespace.
Will it work with streaming response too?
Yes, the same logic applies when streaming.
Streaming chunks also contain real newline characters, not the literal \n text.
So depending on how you read the chunks, you might not see \n, but the line breaks are still there.
A couple of notes for streaming:
• Each chunk may include partial text, so the newline can appear split across chunks.
• If you assemble the chunks into one string, you’ll see the actual line breaks.
• If you want literal \n sequences, you’ll still need to encode them manually after assembling the text.
So yes, everything I wrote above works for streaming too. The only difference is that you may receive the newline in pieces😊