openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/fix-codeinterpretertoolcontainer

Branches

Tags

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

Clone

HTTPS

Download ZIP

docs/quickstart/responses/stream_responses_build_realtime_apps.cs

25lines · modecode

1// SAMPLE: Generate streaming response for realtime apps through Responses API
2// PAGE: https://platform.openai.com/docs/quickstart#stream-responses-and-build-realtime-apps
3// GUIDANCE: Instructions to run this code: https://aka.ms/oai/net/start
4#pragma warning disable OPENAI001
5
6#:package System.Linq.Async@6.*
7#:package OpenAI@2.*
8
9using OpenAI.Responses;
10
11string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
12ResponsesClient client = new(key);
13
14var responses = client.CreateResponseStreamingAsync(
15 "gpt-5.2",
16 "Say 'double bubble bath' ten times fast."
17);
18
19await foreach (var response in responses)
20{
21 if (response is StreamingResponseOutputTextDeltaUpdate delta)
22 {
23 Console.Write(delta.Delta);
24 }
25}
26