Skip to content

기본적으로 스트리밍으로 응답을 반환하는 API 엔드포인트가 있으며, 예를 들어 /api/generate가 있습니다. 이러한 응답은 줄바꿈으로 구분된 JSON 형식(즉, application/x-ndjson 콘텐츠 유형)으로 제공됩니다. 예시는 다음과 같습니다:

json
{"model":"gemma4","created_at":"2025-10-26T17:15:24.097767Z","response":"That","done":false}
{"model":"gemma4","created_at":"2025-10-26T17:15:24.109172Z","response":"'","done":false}
{"model":"gemma4","created_at":"2025-10-26T17:15:24.121485Z","response":"s","done":false}
{"model":"gemma4","created_at":"2025-10-26T17:15:24.132802Z","response":" a","done":false}
{"model":"gemma4","created_at":"2025-10-26T17:15:24.143931Z","response":" fantastic","done":false}
{"model":"gemma4","created_at":"2025-10-26T17:15:24.155176Z","response":" question","done":false}
{"model":"gemma4","created_at":"2025-10-26T17:15:24.166576Z","response":"!","done":true, "done_reason": "stop"}

스트리밍 비활성화

스트리밍을 지원하는 모든 엔드포인트의 요청 본문에 {"stream": false}를 제공하여 스트리밍을 비활성화할 수 있습니다. 이 경우 응답은 대신 application/json 형식으로 반환됩니다:

json
{"model":"gemma4","created_at":"2025-10-26T17:15:24.166576Z","response":"That's a fantastic question!","done":true}

스트리밍과 비스트리밍 사용 시점

스트리밍 (기본값):

  • 실시간 응답 생성
  • 체감 지연 시간 감소
  • 긴 생성 결과에 적합

비스트리밍:

  • 처리 과정이 더 간단함
  • 짧은 응답이나 구조화된 출력에 적합
  • 일부 애플리케이션에서 처리하기 쉬움