메인 콘텐츠로 건너뛰기
Gemini generateContent 엔드포인트의 스트리밍 버전입니다. Server-Sent Events를 반환합니다.

경로 파라미터

model
string
필수
모델 이름 (예: gemini-2.5-pro, gemini-3.5-flash).

쿼리 파라미터

key
string
API 키 (헤더 인증의 대안).

요청 본문

콘텐츠 생성과 동일합니다. 스트리밍 요청에서는 generationConfig.candidateCount를 생략하거나 1로 유지하세요. 더 큰 값은 추가 후보를 조용히 버리는 대신 거부됩니다.

응답

각각 부분적인 응답을 포함하는 JSON 객체의 스트림을 반환합니다.
curl -X POST "https://api.tokenlab.sh/v1beta/models/gemini-2.5-pro:streamGenerateContent?key=sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "parts": [{"text": "Tell me a story"}]
      }
    ]
  }'
import google.generativeai as genai

genai.configure(
    api_key="sk-your-api-key",
    transport="rest",
    client_options={"api_endpoint": "api.tokenlab.sh"}
)

model = genai.GenerativeModel("gemini-2.5-pro")
response = model.generate_content("Tell me a story", stream=True)

for chunk in response:
    print(chunk.text, end="")
const response = await fetch(
  'https://api.tokenlab.sh/v1beta/models/gemini-2.5-pro:streamGenerateContent?key=sk-your-api-key',
  {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      contents: [{ parts: [{ text: 'Tell me a story' }] }]
    })
  }
);

const reader = response.body.getReader();
const decoder = new TextDecoder();

while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  console.log(decoder.decode(value));
}
package main

import (
    "bufio"
    "bytes"
    "encoding/json"
    "fmt"
    "net/http"
)

func main() {
    payload := map[string]interface{}{
        "contents": []map[string]interface{}{
            {"parts": []map[string]string{{"text": "Tell me a story"}}},
        },
    }

    jsonData, _ := json.Marshal(payload)
    req, _ := http.NewRequest("POST",
        "https://api.tokenlab.sh/v1beta/models/gemini-2.5-pro:streamGenerateContent?key=sk-your-api-key",
        bytes.NewBuffer(jsonData))
    req.Header.Set("Content-Type", "application/json")

    client := &http.Client{}
    resp, _ := client.Do(req)
    defer resp.Body.Close()

    scanner := bufio.NewScanner(resp.Body)
    for scanner.Scan() {
        fmt.Println(scanner.Text())
    }
}
<?php
$payload = [
    'contents' => [
        ['parts' => [['text' => 'Tell me a story']]]
    ]
];

$ch = curl_init('https://api.tokenlab.sh/v1beta/models/gemini-2.5-pro:streamGenerateContent?key=sk-your-api-key');

curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
    CURLOPT_POSTFIELDS => json_encode($payload),
    CURLOPT_WRITEFUNCTION => function($ch, $data) {
        echo $data;
        return strlen($data);
    }
]);

curl_exec($ch);
curl_close($ch);
비전 입력 예시
스트리밍 비전 요청은 비스트리밍 엔드포인트와 동일한 contents[].parts[] 구조를 사용합니다.
{
  "contents": [
    {
      "role": "user",
      "parts": [
        { "text": "Please describe this image." },
        {
          "inline_data": {
            "mime_type": "image/jpeg",
            "data": "/9j/4AAQSkZJRgABAQ..."
          }
        }
      ]
    }
  ]
}
{
  "candidates": [
    {
      "content": {
        "role": "model",
        "parts": [
          {"text": "Once upon a time"}
        ]
      }
    }
  ]
}