A fake model that streams, timed with a simulated clock
Each language uses its own idiom for "one piece at a time": a generator in Python and JavaScript, an Iterator in Java.
Every key example runs on the page in Python, Java and JavaScript and prints the same output, using small scripted fake models so runs are free and repeatable. Real-model labs send your own requests to a free hosted model and show the real reply, tokens, timing and limits.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 5 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write a Python generator fake_stream(text, size) that yields the text in pieces of size characters, and print how many pieces "Hello! How can I help?" makes with size 5.
Write seeded_numbers(seed, n) that returns n numbers between 0 and 1 using state = state * 48271 % 2147483647, and print the first three for seed 42 to 4 decimal places.
Explain it without notes
Why does this course use fake models in runnable examples instead of real ones?
Why must an API key never be in browser code, and how does this site's lab avoid it?
What is the max_tokens trap with reasoning models?
Expected output
[ 340 ms] "Hel"
[ 380 ms] "lo"
[ 420 ms] "!"
[ 460 ms] " How"
[ 500 ms] " can"
[ 540 ms] " I"
[ 580 ms] " help"
[ 620 ms] "?"
reply: Hello! How can I help?
first piece after 340 ms, finished after 620 ms
average: 70.0 ms per extra word