Back to the knowledge base
ArticlesBuild with AICurioFuse editorial

Collect a streamed DeepSeek answer

The chat API delivers partial message pieces; inspect its final chunk separately from the assembled text.

Two separate glass channels hold amber curls and joined teal pieces, with one teal piece isolated in a round recess.
CurioFuse · AI-generated illustration
In this article

Prepare a small request

Use the setup guide if you can edit a short Python script. Obtain a DeepSeek API key, install the OpenAI SDK and configure its client with the documented base URL, reading the key from DEEPSEEK_API_KEY. Choose deepseek-flash. Our suggested practice input is: “Rewrite this notice in one sentence: The workshop opens on Tuesday; booking is required.” Keep that original notice beside your output for comparison; this is an illustrative task, not a recorded model test.

Keep two separate buffers

Follow the thinking guide’s streaming example: set stream=True and enable thinking through extra_body. Start with empty reasoning_content and content buffers. For each incoming chunk, accumulate delta.reasoning_content in the former and delta.content in the latter, following the sample’s branch. Our suggested inspection is to examine the final-answer buffer on its own. Compare its wording with your notice: both Tuesday and the booking requirement should remain. Do not mix the reasoning buffer into the answer you are assessing.

Inspect the last chunk

The stream reference places usage statistics on the last content chunk before data: [DONE]. That chunk has no new content and a non-null finish_reason; there is no separate usage-only chunk. Check these fields separately from the accumulated answer. A stop reason means natural completion or a supplied stop sequence, not that the notice was rewritten correctly. This exercise checks assembly and interpretation, not response speed.

Sources(3)

Original CurioFuse editorial. A guide to explore and evaluate AI, without an implied product test.

Sources & standardsReport a correction