Get your API key

Lesson 3 of 5

Streaming answers and choosing models

Word-by-word answers with Stop and friendly errors, a server-side model allow-list, and a 5-question eval to pick a model.

9 min Log in to open
One step at a time, like flipping pages.

By the end of this lesson your bot's answers will appear word by word with a Stop button and friendly errors, your server will choose the model from a short allow-list, and you will pick that model with a small test instead of a guess.

You need: the working chat from lesson 2, your key with Allow streaming responses ticked · Time: 9 minutes

  1. Right now the student taps Send and stares at "typing..." until the whole answer is ready. With a long answer that can be 5 to 10 seconds. Many people tap Send again, or leave.

    Streaming means the model sends the answer in small pieces as it writes them, and your page shows each piece at once. The total time is about the same. The wait feels much shorter, because the first words arrive in a second or two.

    Two timelines from 0 to 8 seconds. Without streaming, a blank grey bar until second 7, then the whole answer. With streaming, a short thinking block, then words appear one after another from about 1 second.
    Same answer, same total time. Streaming shows progress from the first second.
    Why?

    A user who sees words appearing trusts that the app works. A blank screen looks broken, and a second tap on Send means a second paid request.

Log in free to read the rest of this lesson

Every lesson is free. A free account unlocks all of them and saves your progress.

Still to come in this lesson:

  1. What a stream looks like
  2. Add streaming, Stop and friendly errors
  3. Let the server choose the model
  4. Test two models on the same 5 questions
  5. Recap