Stream replies as they're written
Show words as they arrive instead of waiting for the whole reply.
Pass stream: true and read the reply piece by piece. .result gives you the finished reply with its cost.
stream.js
const parts = charge.ai.chat('Write a short product description for a steel water bottle', { stream: true })
out.textContent = ''
for await (const part of parts) {
out.textContent += part
}
const reply = await parts.result // { text, route, costPaise, ... } Cloud replies stream, and so do on-device ones when you pass mode: 'auto'. The first few words of an on-device reply are checked before they appear; if the device model is slow to start or answers in the wrong language, the cloud answers instead.
Read next
Still stuck? Talk to us and we'll help.