Raon
문서

스트리밍

생성되는 답변을 서버 전송 이벤트(SSE)로 실시간 수신합니다.

세 API 모두 stream을 true로 설정하면 답변이 생성되는 대로 서버 전송 이벤트(SSE)로 전달됩니다. Python 예제는 Chat Completions나 Messages에서 만든 클라이언트를 사용합니다.

stream = client.chat.completions.create(
    model="raon-1-mini-preview",
    messages=[{"role": "user", "content": "Hello!"}],
    stream=True,
    stream_options={"include_usage": True},
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)
  • Chat Completions에서 stream_options.include_usage를 설정하면 마지막 청크에 토큰 사용량이 포함됩니다.
  • curl로 확인할 때는 출력이 버퍼링되지 않도록 -N 옵션을 추가하세요.