Movatterモバイル変換


[0]ホーム

URL:


OpenAI Developers
API Dashboard
Primary navigation

Legacy APIs

API Dashboard

By default, when you make a request to the OpenAI API, we generate the model’s entire output before sending it back in a single HTTP response. When generating long outputs, waiting for a response can take time. Streaming responses lets you start printing or processing the beginning of the model’s output while it continues generating the full response.

Enable streaming

To start streaming responses, setstream=True in your request to the Responses endpoint:

1234567891011121314151617import { OpenAI }from"openai";const client =new OpenAI();const stream =await client.responses.create({model:"gpt-5",input: [        {role:"user",content:"Say 'double bubble bath' ten times fast.",        },    ],stream:true,});forawait (const eventof stream) {console.log(event);}
12345678910111213141516from openaiimport OpenAIclient = OpenAI()stream = client.responses.create(    model="gpt-5",input=[        {"role":"user","content":"Say 'double bubble bath' ten times fast.",        },    ],    stream=True,)for eventin stream:print(event)
123456789101112131415161718using OpenAI.Responses;string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;OpenAIResponseClient client =new(model:"gpt-5", apiKey: key);var responses = client.CreateResponseStreamingAsync([    ResponseItem.CreateUserMessageItem([        ResponseContentPart.CreateInputTextPart("Say 'double bubble bath' ten times fast."),    ]),]);awaitforeach (var responsein responses){if (responseis StreamingResponseOutputTextDeltaUpdate delta)    {        Console.Write(delta.Delta);    }}

The Responses API uses semantic events for streaming. Each event is typed with a predefined schema, so you can listen for events you care about.

For a full list of event types, see theAPI reference for streaming. Here are a few examples:

12345678910111213141516171819202122232425type StreamingEvent =| ResponseCreatedEvent| ResponseInProgressEvent| ResponseFailedEvent| ResponseCompletedEvent| ResponseOutputItemAdded| ResponseOutputItemDone| ResponseContentPartAdded| ResponseContentPartDone| ResponseOutputTextDelta| ResponseOutputTextAnnotationAdded| ResponseTextDone| ResponseRefusalDelta| ResponseRefusalDone| ResponseFunctionCallArgumentsDelta| ResponseFunctionCallArgumentsDone| ResponseFileSearchCallInProgress| ResponseFileSearchCallSearching| ResponseFileSearchCallCompleted| ResponseCodeInterpreterInProgress| ResponseCodeInterpreterCallCodeDelta| ResponseCodeInterpreterCallCodeDone| ResponseCodeInterpreterCallInterpreting| ResponseCodeInterpreterCallCompleted| Error

Read the responses

Advanced use cases

For more advanced use cases, like streaming tool calls, check out the following dedicated guides:

Moderation risk

Note that streaming the model’s output in a production application makes it more difficult to moderate the content of the completions, as partial completions may be more difficult to evaluate. This may have implications for approved usage.


[8]
ページ先頭

©2009-2026 Movatter.jp