const response = await fetch('https://api.illa.io/api/v1/chat', {
method: 'POST',
headers: {
'content-type': 'application/json',
accept: 'text/event-stream',
'x-api-key': process.env.ILLA_API_KEY!,
},
body: JSON.stringify(body),
})
if (!response.body) throw new Error('No stream body')
for await (const event of parseSSEStream(response.body)) {
if (event.type === 'telemetry' && event.data.type === 'text_delta') {
process.stdout.write(event.data.data.delta)
}
if (event.type === 'result') {
console.log('\nfinal text:', event.data.text)
}
}