openai/openai-dotnet

Public

mirrored from https://github.com/openai/openai-dotnetAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
typespec/update-http-client-csharp-1.0.0-alpha.20260516.1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

examples/Responses/Example02_SimpleResponseStreamingAsync.cs

34lines · modecode

1using NUnit.Framework;
2using OpenAI.Responses;
3using System;
4using System.ClientModel;
5using System.Threading.Tasks;
6
7namespace OpenAI.Examples;
8
9// This example uses experimental APIs which are subject to change. To use experimental APIs,
10// please acknowledge their experimental status by suppressing the corresponding warning.
11
12#pragma warning disable OPENAI001
13
14public partial class ResponseExamples
15{
16 [Test]
17 public async Task Example02_SimpleResponseStreamingAsync()
18 {
19 ResponsesClient client = new(apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
20
21 AsyncCollectionResult<StreamingResponseUpdate> responseUpdates = client.CreateResponseStreamingAsync("gpt-5", "Say 'this is a test.'");
22
23 Console.Write($"[ASSISTANT]: ");
24 await foreach (StreamingResponseUpdate update in responseUpdates)
25 {
26 if (update is StreamingResponseOutputTextDeltaUpdate outputTextUpdate)
27 {
28 Console.Write(outputTextUpdate.Delta);
29 }
30 }
31 }
32}
33
34#pragma warning restore OPENAI001