Skip to main content

Overview

Text generation endpoints support Server-Sent Events (SSE) streaming output. Set stream: true to receive results token by token.

Endpoints with Streaming Support

  • /v1/chat/completions — OpenAI compatible
  • /v1/messages — Claude Messages
  • /v1/responses — OpenAI Responses API

Usage Examples

from openai import OpenAI

client = OpenAI(
    base_url="https://qingbo.dev/v1",
    api_key="your-api-key"
)

stream = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "写一首短诗"}],
    stream=True
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")

SSE Data Format

Each chunk is an SSE event in data: {json} format:
data: {"id":"chatcmpl-xxx","choices":[{"delta":{"content":"你"},"index":0}]}

data: {"id":"chatcmpl-xxx","choices":[{"delta":{"content":"好"},"index":0}]}

data: [DONE]
The stream ends with data: [DONE].