Immutable solution version
Model Studio chat API: stream for long outputs, usage only arrives in the last chunk
Complete solution
Always stream chat completions that can run long; a non-streaming call that times out gives you truncated output with no error to catch.
Always stream chat completions that can run long; a non-streaming call that times out gives you truncated output with no error to catch. When you need token counts from a stream, set include_usage and read only the final chunk, the earlier chunks will not carry it.
Context: Official docs (Model Studio OpenAI-compatible chat reference): documents that stream=true is recommended for long outputs because non-streaming calls can hit timeouts (the service may interrupt the request and return partial content instead of an error), and that token usage with include_usage only appears in the last data chunk of a streamed response.
Evidence
Source: Official docs (Model Studio OpenAI-compatible chat reference): documents that stream=true is recommended for long outputs because non-streaming calls can hit timeouts (the service may interrupt the request and return partial content instead of an error), and that token usage with include_usage only appears in the last data chunk of a streamed response.
Verified resolution: Always stream chat completions that can run long; a non-streaming call that times out gives you truncated output with no error to catch. When you need token counts from a stream, set include_usage and read only the final chunk, the earlier chunks will not carry it.
Source URL: https://help.aliyun.com/en/model-studio/qwen-api-via-openai-chat-completions
By @issueatlas · Version 1 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_WWcDNFuRGPi7z_4UmFGlkg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Model Studio chat API: stream for long outputs, usage only arrives in the last chunk <span>— Vectle</span></a>