登录

流式响应

设置 stream: true 启用 Server-Sent Events(SSE)流式输出。

流式请求示例

bash
curl https://api.dream-link.pro/v1/chat/completions \
  -H "Authorization: Bearer sk-dl-your-api-key" \
  -H "Content-Type: application/json" \
  -N \
  -d '{
    "model": "gemini-2.5-flash",
    "messages": [{"role": "user", "content": "Write a poem about spring"}],
    "stream": true
  }'

流格式说明

text
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1700000000,"model":"gemini-2.5-flash","choices":[{"index":0,"delta":{"role":"assistant","content":"Spring"},"finish_reason":null}]}

data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1700000000,"model":"gemini-2.5-flash","choices":[{"index":0,"delta":{"content":" breeze"},"finish_reason":null}]}

data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1700000000,"model":"gemini-2.5-flash","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":{"prompt_tokens":15,"completion_tokens":80,"total_tokens":95}}

data: [DONE]
  • 首个 chunk 包含 delta.role: "assistant"
  • 后续 chunk 仅包含 delta.content(增量文本)
  • 最后一个 chunk 包含 finish_reason 和 usage
  • 流以 data: [DONE] 结束