> ## Documentation Index
> Fetch the complete documentation index at: https://wb-21fd5541-docs-hivemind-launch.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# ストリーミング応答を有効にする

> Serverless Inference でストリーミング出力を有効にすると、生成中のモデル応答を段階的に受け取れます。

モデルによっては、応答の生成に時間がかかることがあります。
`stream` オプションを true に設定すると、応答をチャンクのストリームとして受け取れるため、
応答全体の生成を待たずに、結果を段階的に表示できます。

ストリーミング出力は、すべての hosted モデルでサポートされます。特に
[reasoning models](./reasoning) での使用を推奨します。ストリーミングでないリクエストでは、モデルが出力を開始する前に
長時間考え込むとタイムアウトする可能性があるためです。

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    import openai

    client = openai.OpenAI(
        base_url='https://api.inference.wandb.ai/v1',
        api_key="<your-api-key>",  # https://wandb.ai/settings でAPIキーを作成します
    )

    stream = client.chat.completions.create(
        model="openai/gpt-oss-120b",
        messages=[
            {"role": "user", "content": "Tell me a rambling joke"}
        ],
        stream=True,
    )

    for chunk in stream:
        if chunk.choices:
            print(chunk.choices[0].delta.content or "", end="", flush=True)
        else:
            print(chunk) # CompletionUsage object を表示します
    ```
  </Tab>

  <Tab title="Bash">
    ```bash theme={null}
    curl https://api.inference.wandb.ai/v1/chat/completions \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer <your-api-key>" \
      -d '{
        "model": "openai/gpt-oss-120b",
        "messages": [
          { "role": "user", "content": "Tell me a rambling joke" }
        ],
        "stream": true
      }'
    ```
  </Tab>
</Tabs>
