Streaming, token budgets and cost 00:00:01 The sentence starts before the bill arrives Four tenths of a second after Priya sends her prompt, three words appear on the terminal. The customer thinks the job is done. The meter is still running, the remaining text is unknown, and the first network read did not even contain a full event. Streaming reveals progress before generation is complete. A transport emits framed events, a renderer decides what is safe to display, and final accounting uses completed usage records. Token counts, wall-clock latency and dollars measure different parts of that lifecycle. Use fictional prices for this receipt. Twelve hundred input tokens at two dollars per million cost twenty-four hundredths of a cent. Three hundred output tokens at eight dollars per million cost the same. Together that is forty-eight hundredths of one cent. 00:00:54 Three clocks on the response Reserve enough context for the answer. For this example use fictional prices of 2 dollars per million input tokens and 8 dollars per million output tokens. The UI receives several complete events. A partial network chunk is buffered before it becomes a text update. The visible prefix is still provisional. The terminal event confirms completion. Input costs 0.0024 dollars and output costs another 0.0024 dollars. Record actual usage separately from the original reservation. n counts tokens and r is a price in dollars per million tokens. At the example rates 2 and 8, 1200 input tokens and 300 output tokens cost 0.0048 dollars. 00:01:49 Account for every token Server-sent events carry a sequence of framed messages over an H T T P response. A network chunk can contain part of an event or several events. Buffer until a full event has arrived, parse its type and handle the terminal event. A closed connection can mean interruption rather than a complete answer. Split a single server sent events event across two simulated reads, then place two events in one read. The parser should emit the same ordered event sequence. A typing interface appends content deltas as they arrive. It must also handle cancellation, interrupted output and text boundaries correctly. Measure time to first visible text separately from time to validated completion. Never treat a partially streamed structured object as a confirmed application record. Cancel a stream after its first sentence. Verify the UI distinguishes that partial draft from the completed response stored in history. Compute input and output charges separately because the unit prices may differ. Multiply each token count by its price per million and divide by one million. Distinguish this illustrative estimate from the invoice, which can account for caching, batch discounts or additional billable features. At fictional rates of 2 and 8 dollars per million tokens, replacing 100 output tokens with 100 input tokens reduces cost by 0.0006 dollars. Streaming can improve perceived responsiveness without reducing total service time. A service should measure time to first text, time to complete validated output and spend per successful task. Billing rates in the worked example are illustrative. 00:03:44 If the cable drops now The connection drops after the first text event. Is the displayed prefix a completed result? The application has evidence that generation began, not that the response finished or passed validation. Priya lets the interface show the draft as it arrives. Only a confirmed finish turns it into the completed answer, and the actual usage on that completed run supplies the final charge.