Skip to content
bestokens

스트리밍

SSE, 사용량 프레임, 과금.

최종 업데이트: 2026-10-27

Set stream: true to receive server-sent events. The transport is plain SSE over HTTP/2 and works through any standard OpenAI client.

              stream = client.chat.completions.create(
    model="gpt-5-mini",
    messages=[{"role": "user", "content": "Count to five."}],
    stream=True,
)

for chunk in stream:
    delta = chunk.choices[0].delta.content
    if delta:
        print(delta, end="", flush=True)
            

Usage on streams

We always request stream_options.include_usage from upstream, so the final event before [DONE] carries a usage object. If the upstream provider omits it, we fall back to an estimated count and flag the request in your usage log.

              data: {"choices":[{"delta":{"content":"One"}}]}

data: {"choices":[{"delta":{"content":", two"}}]}

data: {"choices":[],"usage":{"prompt_tokens":12,"completion_tokens":7}}

data: [DONE]
            

Billing is settled after the stream flushes, not per chunk. A client that disconnects early is still charged for tokens already generated upstream.

기술 문서는 영어로 제공됩니다.