0Pricing
Prompt Engineering & LLM Optimization for Developers · 강의

사용자에게 LLM 응답 스트리밍

사용자에게 토큰을 실시간으로 전달합니다. 스트리밍의 작동 방식과 체감 지연 시간을 개선하는 이유, 스트리밍된 완성 결과를 코드에서 소비하는 방법을 배웁니다.

사용자에게 LLM 응답 스트리밍은(는) CoddyKit의 무료 Prompt Engineering & LLM Optimization for Developers 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Prompt Engineering & LLM Optimization for Developers 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Prompt Engineering & LLM Optimization for Developers 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Why Stream?

By default an LLM call returns the entire response only after generation finishes. For long answers this feels slow.

Streaming sends tokens as they are produced, so the user sees text appear word-by-word — drastically improving perceived responsiveness.

Time to First Token

Two latency numbers matter:

  • TTFT (time to first token): how long until the first word appears
  • Total time: until the full answer is ready

Streaming barely changes total time but makes TTFT the number your users actually feel.

Server-Sent Events

Most LLM APIs stream over Server-Sent Events (SSE): a long-lived HTTP response where each chunk is a small JSON event prefixed with data:.

The stream ends with a special [DONE] marker.

Enabling Streaming

You opt in by setting a flag on the request. The API then returns an iterable stream instead of a single object.

const stream = await client.chat.completions.create({
  model: "gpt-4o-mini",
  messages: messages,
  stream: true
});

Reading Chunks

Each chunk carries a delta — the new piece of text. You concatenate deltas to rebuild the full message.

let full = "";
for await (const chunk of stream) {
  const piece = chunk.choices[0].delta.content || "";
  full += piece;
  process.stdout.write(piece);
}

Updating the UI

On the frontend you append each delta to the visible message. A simple approach: keep state and re-render on every token.

function onToken(token, setText) {
  setText(prev => prev + token);
}

Handling the Done Signal

When the stream closes, finalize: stop the typing indicator, persist the full message, and re-enable the input box.

stream.on("end", () => {
  saveMessage(full);
  hideTypingIndicator();
});

Errors Mid-Stream

A stream can fail halfway. Always wrap consumption in try/catch and show whatever partial text you already received rather than discarding it.

try {
  for await (const c of stream) { /* ... */ }
} catch (e) {
  showPartial(full);
  reportError(e);
}

Cancellation

Users may want to stop a long answer. Pass an AbortController signal so you can cancel the request and free server resources.

const controller = new AbortController();
client.chat.completions.create({ ...opts, signal: controller.signal });
// later
controller.abort();

Streaming with Tools

When the model is calling a function, tool-call arguments also arrive as deltas. Buffer them until the call is complete before executing the tool.

Cost & Token Counting

Streaming does not change cost — you still pay per token. To count usage, sum the tokens you received, or request a final usage event if the API supports it.

Quick Check

Test your streaming knowledge.

Recap

You learned to stream LLM responses: opt in with a stream flag, read incremental delta chunks over SSE, update the UI per token, handle the done signal, manage errors and cancellation, and remember streaming improves perceived latency without changing cost.

자주 묻는 질문

“사용자에게 LLM 응답 스트리밍” 강의는 무료인가요?

네 — “사용자에게 LLM 응답 스트리밍” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Prompt Engineering & LLM Optimization for Developers 강의 전체를 잠금 해제할 수 있습니다. Prompt Engineering & LLM Optimization for Developers 강의에는 총 4개의 강의가 포함되어 있습니다.

“사용자에게 LLM 응답 스트리밍”에서 뭘 배우나요?

사용자에게 토큰을 실시간으로 전달합니다. 스트리밍의 작동 방식과 체감 지연 시간을 개선하는 이유, 스트리밍된 완성 결과를 코드에서 소비하는 방법을 배웁니다. 브라우저에서 직접 실행하는 실습 코드로 Prompt Engineering & LLM Optimization for Developers을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Prompt Engineering & LLM Optimization for Developers을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Prompt Engineering & LLM Optimization for Developers은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.

“사용자에게 LLM 응답 스트리밍” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Prompt Engineering & LLM Optimization for Developers 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Prompt Engineering & LLM Optimization for Developers 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 검색 증강 생성(RAG)
  2. 함수 호출 및 도구 사용
  3. 간단한 LLM 에이전트 구축
  4. 사용자에게 LLM 응답 스트리밍
← Prompt Engineering & LLM Optimization for Developers(으)로 돌아가기