가이드
Streaming
Server-sent events for chat.
Chat supports server-sent events: set stream: true and the reply arrives as OpenAI-style chunks, terminated by data: [DONE]. Credits are flat per completion, so streaming costs exactly what buffering costs.
Watch the frames arrive
/v1/chat/completions
→ POST /v1/chat/completions
실행을 눌러 보세요 — 문서에 담긴 데이터로 실제 요청과 응답을 그대로 재현해요. 키도, 요청도, 요금도 없어요.
Reading the stream
node
const res = await fetch('https://eroq.ai/v1/chat/completions', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.EROQ_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ model: 'eroq-rp-plus', stream: true, messages }),
})
const reader = res.body.getReader()
const decoder = new TextDecoder()
let buffer = ''
while (true) {
const { done, value } = await reader.read()
if (done) break
buffer += decoder.decode(value, { stream: true })
const events = buffer.split('\n\n')
buffer = events.pop() ?? ''
for (const event of events) {
const data = event.replace(/^data: /, '')
if (data === '[DONE]') continue
const chunk = JSON.parse(data)
process.stdout.write(chunk.choices?.[0]?.delta?.content ?? '')
}
} Two eroq-specific details: a final chat.completion.usage event carries the meter before [DONE], and if the upstream fails before any content streamed, you get an error event and an automatic refund.