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, ... } Read next
Still stuck? Talk to us and we'll help.