How do I show Max or Heavy's reasoning while streaming in JavaScript?
const stream = await client.chat.completions.create({
model: "supercosmos-max",
messages: [{ role: "user", content: "Plan a 3-step migration from REST to webhooks." }],
stream: true,
});
let thinking = "", answer = "";
for await (const chunk of stream) {
const d = chunk.choices[0]?.delta ?? {};
if (d.reasoning_content) thinking += d.reasoning_content; // show in a collapsible "thinking" box
if (d.content) answer += d.content; // the reply itself
}
console.log({ thinking: thinking.length, answer });
Reasoning tokens are billed as output whether or not you display them.
Good to know#
- Base URL:
https://api.gateway.clatterlabs.xyz/v1, withAuthorization: Bearer clsk_...andX-Clatter-Account: CL-...on every call. Quick reference - Every response has an
X-Request-Id; log it so a request can be found later. Why log it - Retry only
429and 5xx errors, with backoff; honourRetry-Afterwhen it's sent. Which errors to retry
Still need help?#
- General support: support@clatterlabs.com or team@clatterlabs.xyz
- Infrastructure questions, or permanent deletion of your data (your whole account or one service): infrastructure@clatterlabs.xyz
We usually reply within the first hour, and always within 24 hours. A full support team is with you.
Related articles
Still need help?
Tried the steps above and still stuck? Email us. We usually reply within the first hour, and always within 24 hours. A full support team is with you.
Infrastructure questions, or permanent deletion of your data
infrastructure@clatterlabs.xyzFor deleting your whole account or the data of one service.