const response = await fetch("https://api.tinytalk.ai/v1/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
"api-key": "tiny_sk_your_key_here"
},
body: JSON.stringify({
botId: "your-agent-id",
messages: [
{ role: "user", content: "What are your business hours?" }
]
})
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value);
const lines = chunk.split("\n").filter((line) => line.startsWith("data: "));
for (const line of lines) {
const data = line.replace("data: ", "");
if (data === "[DONE]") break;
const parsed = JSON.parse(data);
const content = parsed.choices?.[0]?.delta?.content;
if (content) process.stdout.write(content);
}
}