Jump to content
CodeRelayHub

← All digest entries

Does Streaming Change What You Pay?

1. Separate delivery from billing

Streaming answers a delivery question: should your application receive output incrementally or wait for the completed response? Token billing answers an accounting question: how much billable input and output did the request consume? Receiving many small events does not mean you purchased many separate completions. Streaming changes how output arrives, not the basic token-accounting model. ([developers.openai.com](https://developers.openai.com/api/docs/guides/streaming-responses?utm_source=openai))

For a pay-as-you-go integration through CodeRelay Hub, start with this distinction rather than assuming that a faster-looking response is cheaper. Check the selected model’s applicable rates and billing terms; do not infer a streaming surcharge or discount from the transport setting alone.

2. Build the bill from usage categories

For straightforward text requests, estimate cost by multiplying input tokens by the input rate and output tokens by the output rate. If rates are quoted per million tokens, divide each token count by one million before multiplying. Where cached input has a separate rate, split it from uncached input rather than charging both categories for the same tokens. ([developers.openai.com](https://developers.openai.com/api/docs/pricing))

Compare equivalent requests. Keep the model, prompt, conversation history, tools, output limit, and reasoning settings fixed when testing streaming against non-streaming. Record actual usage for each run instead of assuming that two generated answers will have identical lengths.

3. Never count network chunks as tokens

A stream event is a protocol message, not a billing unit. It may carry text, metadata, or a completion signal. OpenAI’s streaming documentation explicitly notes that a delta can contain content, a role, or nothing. Counting events, characters, or rendered words therefore does not produce an authoritative token count. ([developers.openai.com](https://developers.openai.com/api/docs/guides/streaming-responses?utm_source=openai))

Make your stream handler responsible for rendering and event handling. Make a separate accounting path responsible for usage. This separation also gives you somewhere to record incomplete requests without pretending their visible text represents the final bill.

4. Capture the authoritative usage record

For OpenAI Chat Completions, request streaming usage with stream_options.include_usage set to true. The API can then send an additional usage-bearing chunk before the stream ends. Other chunks normally have null usage. If the stream is interrupted, that final usage chunk may never arrive. ([developers.openai.com](https://developers.openai.com/api/reference/resources/chat/subresources/completions/methods/create))

Do not assume every endpoint or provider exposes the same event structure. Check compatibility for the route you actually use, then normalize the returned accounting into an internal record:

  • Request identifier, model, and attempt number.
  • Input, output, and available cache or reasoning details.
  • Completion status and whether authoritative usage arrived.
  • The rate configuration used for your estimate.

5. Treat cancellation as an accounting edge case

A missing final usage event does not establish that a request cost nothing. Interrupted streams can lose their usage summary, leaving your application without complete accounting. Mark that state as unknown rather than recording zero. ([developers.openai.com](https://developers.openai.com/api/reference/resources/chat/subresources/completions/methods/create))

Design cancellation to propagate beyond the interface. A practical test should verify what happens when a user presses Stop, closes the tab, or loses connectivity. Reconcile interrupted attempts against available provider or hub usage records before promising that the visible stopping point determines the charge.

6. Look beyond the visible answer

For reasoning models, visible output can be only part of the billable generation. OpenAI documents reasoning tokens as billed output tokens, even though they are not exposed as ordinary answer text. Do not add them again if they are already included in the output total. ([developers.openai.com](https://developers.openai.com/api/docs/guides/reasoning))

Track retries as separate attempts under one logical task. If a partial response triggers a replacement request, retain both records. Otherwise, a dashboard that keeps only the successful response can conceal the work performed before recovery.

7. Optimize the task, not the typing effect

Use streaming when incremental output improves the experience. For cost control, review prompt size, requested answer length, reasoning settings, and retry behavior. Compare reconciled cost per completed task, not the number of events your interface displayed.

Open a free CodeRelay Hub workspace.

Try it on a real task: open a workspace and spend the trial credit.

Sign up