Streaming Chunks and Deltas
Streaming
Part of: Reading Model Outputs
Watch ChatGPT answer and the text appears word by word, like someone typing live. That isn't a UI animation faked on top of a finished answer, the model really is sending the text out in pieces as it generates them. Each piece is called a delta , and if you want that live feel in your own app, you have to learn to catch the pieces and glue them back together yourself. What it is In the lessons so far, the API handed you one complete response object with the whole answer sitting in content. Streaming flips that: instead of one big response, the API sends a sequence of small chunks , each carrying a tiny slice of the answer in a field called a delta . Your code receives chunk, chunk, chunk... and assembles the final text as they arrive. A delta is literally "the new bit since last time." The first chunk might carry "The", the next " capital", the next " of"... and so on. None of them is the full answer. The full answer only exists once you have concatenated every delta in order . How it works Each chunk looks a lot like a mini response object, but the text lives under delta instead of message, and it holds only the newest fragment. You loop over the chunks and append each fragment to
Challenge: Stream Assembler