Streaming answers
Answers start arriving in about a second. Send "stream": true to get them piece by piece instead of
waiting for the whole answer.
curl -N https://api.beru.airesearchlabs.si/v1/answer \ -H "Authorization: Bearer $BERU_API_KEY" \ -H "Content-Type: application/json" \ -d '{"query": "Is parking free?", "stream": true}'for event in beru.answer_stream("Is parking free?"): if event.type == "delta": print(event.text, end="", flush=True) else: print("\nSources:", event.answer["citations"])for await (const event of beru.answerStream({ query: "Is parking free?" })) { if (event.type === "delta") process.stdout.write(event.text); else console.log("\nSources:", event.answer.citations);}The events
Section titled “The events”The response is text/event-stream:
event: deltadata: {"text": "Yes, parking is "}
event: deltadata: {"text": "free behind the clinic [1]."}
event: donedata: {"answer": "Yes, parking is free behind the clinic [1].", "citations": [...], "answered": true, ...}delta: the next piece of text. Append them in order.done: the full answer object, the same as without streaming, includingcitationsandconversation_id. Show sources from here.error: something failed after streaming began, with the usual error envelope.
Errors before the first piece, such as an invalid key or a plan limit, are normal HTTP errors, not events.
- Citation markers like
[1]can arrive split across pieces. Render them oncedonearrives, or after each piece on the text so far. - A question is counted when it starts. If the reader disconnects mid-answer, it still counts.
- Behind a proxy, turn off response buffering for this route so pieces aren’t held back.