在支持流式输出的 endpoint 中,将 stream 设置为 true。
curl -N -X POST "https://xxx.wengaocloud.com/v1/chat/completions" \
-H "Authorization: Bearer $AI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini",
"stream": true,
"messages": [
{"role": "user", "content": "写一段简短欢迎语"}
]
}'
典型响应:
data: {"choices":[{"delta":{"content":"你"}}]}
data: {"choices":[{"delta":{"content":"好"}}]}
data: [DONE]
不同 endpoint 的最终 usage chunk 可能不同。生产对账请以完整响应、usage log 和控制台账单为准。