A user watches an answer stream in, decides it's going the wrong way, and clicks Regenerate before it finishes.
Your app starts a second generation. What happens to the first one?
There are three common answers, and they cost very different amounts:
1. You abort the first request, then start the second. 2. You start the second request and forget about the first. 3. You stop reading the first stream, but never cancel it.
Enter fullscreen mode
Exit fullscreen mode
The first is what most people intend. The second and third are what a lot of code actually does.
I measured all three against a real provider (DeepSeek, deepseek-flash , streaming Chat Completions), using the account balance as an external meter, the same method as in the previous experiment . The code is public: aiengineering-book/llm-cancellation-experiment .
The Result First
Each arm is 6 runs. Every completed answer is max_tokens=4000 .…