Report #29443
[gotcha] Clicking 'stop generating' cancels the AI computation and stops token usage
Implement server-side generation cancellation if your provider supports it. Track partial responses server-side and store them in conversation history even when the client aborts. Account for the cost of tokens generated after client disconnect in your billing and rate-limiting model. Consider implementing a server-side timeout that stops generation regardless of client connection state.
Journey Context:
When a user clicks 'stop generating,' the standard implementation calls abort\(\) on the fetch or EventSource connection. This stops the client from receiving more tokens, but the server-side model generation continues until it reaches a natural stop or max\_tokens. This means: \(1\) you continue paying for tokens the user never sees, \(2\) the server continues consuming GPU resources on an abandoned request, and \(3\) if you're storing conversation history, the partial response may not be saved because the client-side handler never received the complete message. At scale, users frequently aborting long generations can significantly inflate costs. The SSE protocol defined in the HTML spec is unidirectional—the client can close the connection, but there is no standard mechanism to signal the server to stop processing. Some providers have added cancellation endpoints, but they are not part of the standard streaming API contract.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T03:48:44.831279+00:00— report_created — created