In this lesson, you split the assistant’s streamed answers into the wait for the first words and the generation after them, and measured which part a recorded day’s slowest answers spent their time on.
Key Points
- The question: in Cut the Cost per Question, you asked for shorter answers. Do they make the assistant faster too? The answer depends on what happens inside a model call.
- The recorded day is the hundred questions from Cut the Cost per Question, replayed after your cuts with every timing kept. The slowest answer took 12.5 seconds. It made three tool rounds, checking hut after hut, the slow step your traces found. Then one more model call streamed a 40-token answer.
- The replay used the app’s earlier cap of three tool rounds, before Cut the Cost per Question settled on 12, and the conclusion still holds: tool rounds lead the slowest answers’ time.
- The first words split a model call in two. The answer’s span records when they arrived, in
firstChunkMs. Before them is the wait: your request crosses the network and waits its turn, the model reads the prompt, and it may reason before writing. After them is generation: the answer streams in one token at a time. - The wait moves less than generation. The answer role’s waits that day sat near a median of 0.9 seconds, and most fell between 0.6 and 1.3 seconds (p5 to p95 over 70 answers).
- Generation grows with the tokens. Three of the answer role’s answers each waited about 0.9 seconds. Their generation took three tenths of a second for 20 tokens, nearly a second for 58 and 1.2 seconds for 79.
- At these sizes, a longer prompt barely moved the wait. You ran the Col de Fenêtre question five times each way. A random first line kept the prompt cache out, so every run read the whole prompt.
- The whole reports block made the prompt about four times longer (424 to 1,741 input tokens). The wait went from 931 to 967 milliseconds, less than it drifts between runs. Most of the wait isn’t reading your prompt.
- A longer answer took longer to generate. Asking for about two hundred words grew the answer from 82 to 201 tokens and generation from 1.4 to 4.0 seconds. Much larger prompts, the cache and reasoning can change that balance, so measure your own requests.
- The script below weighs the two parts across a day. It reads the request log and the traces. For each answer, it keeps the total time and the wait, then the generation and the output tokens from the last model span, the call that streamed the answer.
- Then it sums the slowest answers. It takes the answers slower than the p95 and gives each part’s share of their time. Last, it divides the answer role’s generation time by its output tokens.
- On the recorded day, the wait was 15% of the slowest answers’ time. Five answers were slower than the 7.5-second p95. Generation took 7% of their time, and tool rounds and the other model calls before the answer took the remaining 78% (the script’s “Tool rounds and the rest”).
- Generation came to about 16 milliseconds per output token on the answer role. That’s rough, because the output count includes a few hidden reasoning tokens the hiker never sees. Counting visible tokens only, it’s about 17.
- These are limited numbers. The replay ran in about eighty seconds on one provider’s models, so it shows one provider’s load at one moment, and only five answers make the tail. Run the script on your own logs to see which part to cut on your provider.
- Cut the bigger part. Halving the slowest answer’s 40 tokens saves about 0.3 seconds (20 tokens at about 16 milliseconds each). Its three tool rounds took almost eleven. Each round is a whole model call with its own wait.
- The rule: split each model call at its first words. When generation leads, ask for shorter answers. When calls in a row lead, make fewer of them. So shorter answers help a little, but in the slowest answers, tool rounds lead.
Final Code
Save this as scripts/wait-split.js. It reads a day’s request log and trace file, given as its two arguments. readJsonLines() and percentile() are the same as in scripts/latency.js: