1. Learn
  2. /
  3. Courses
  4. /
  5. Working with the OpenAI Responses API

Connected

Exercise

Streaming OpenAI Responses

You're building a cooking assistant app that generates recipes in real-time. The OpenAI client has been initialized and configured for you. You'll use the Responses API to stream recipe generation, displaying the text as it arrives to create a dynamic user experience.

Instructions

100 XP
  • Open a streaming context using client.responses.create() with the model "gpt-5-mini" and the prompt provided.
  • Loop through the stream events and check if the event type is "response.output_text.delta"; if it is, append event.delta to current_text and print the accumulated text.