AI / Core OpenAI Codex Application Fundamentals Interview Questions
What is streaming in the OpenAI API and how do you implement it?
Streaming delivers the model's output token by token as it is generated, rather than waiting for the complete response. This dramatically improves perceived performance in interactive applications by showing text appearing in real time.
from openai import OpenAI client = OpenAI() # Chat Completions streaming with client.chat.completions.stream( model="gpt-5.5", messages=[{"role": "user", "content": "Write a Python web scraper."}], ) as stream: for text in stream.text_stream: print(text, end="", flush=True) # Access final complete response: final = stream.get_final_completion() # Responses API streaming with client.responses.stream( model="gpt-5.5", input="Explain async/await in Python with examples.", ) as stream: for event in stream: # Events: response.created, response.in_progress, # response.output_item.added, response.content_part.delta, # response.completed, etc. if event.type == "response.output_text.delta": print(event.delta, end="", flush=True) final_response = stream.get_final_response() # Async streaming for FastAPI/async applications: async def stream_response(): async with client.responses.stream( model="gpt-5.5", input="Review this code: ...", ) as stream: async for text in stream.text_stream: yield text # SSE to browser
| Event | When it fires |
|---|---|
| response.created | Once at the start - response object initialised |
| response.output_text.delta | For each text token chunk as it arrives |
| response.output_item.added | When a new output item (text block, tool call) starts |
| response.completed | Once when the full response is finished |
Both APIs support streaming. The Responses API streaming events are more granular and expose tool call streaming - you can see tool call arguments being built token by token, enabling more sophisticated streaming UIs.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
