Documentation Index
Fetch the complete documentation index at: https://docs.apigo.ai/llms.txt
Use this file to discover all available pages before exploring further.
推奨エンドポイント
最低限のお願い
{
"model": "gemini-2.5-flash",
"contents": [
{
"role": "user",
"parts": [{ "text": "Explain SSE streaming while streaming the answer." }]
}
]
}
cURLの例
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:streamGenerateContent?alt=sse" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-N \
-d '{
"contents": [
{
"role": "user",
"parts": [{ "text": "Explain SSE streaming while streaming the answer." }]
}
]
}'
Python の例
from google import genai
client = genai.Client(api_key="<GEMINI_API_KEY>")
stream = client.models.generate_content_stream(
model="gemini-2.5-flash",
contents="Explain SSE streaming while streaming the answer.",
)
for chunk in stream:
if chunk.text:
print(chunk.text, end="")
Node.js の例
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const stream = await ai.models.generateContentStream({
model: "gemini-2.5-flash",
contents: "Explain SSE streaming while streaming the answer."
});
for await (const chunk of stream) {
if (chunk.text) process.stdout.write(chunk.text);
}
ベストプラクティス
- チャンクごとに完全な文を想定するのではなく、
parts[].text を段階的に蓄積します。
- 構造化された出力もストリーミングできますが、部分的な JSON サーバー側で解析されます。
- 通常、Flash クラスのモデルは、遅延に敏感なストリーミング チャットに最適です。