Streaming
odnoga proxies SSE (Server-Sent Events) end-to-end. Add "stream": true and consume the OpenAI-shaped delta stream.
cURL
curl -N "$AIROUTER_BASE_URL/v1/chat/completions" \
-H "authorization: Bearer $AIROUTER_API_KEY" \
-H "content-type: application/json" \
-H "x-airouter-end-user: user_123" \
-d '{
"model": "gpt-4o-mini",
"stream": true,
"messages": [{"role":"user","content":"count to 5"}]
}'
You receive data: { … }\n\n chunks until a final data: [DONE].
Node (OpenAI SDK)
const stream = await client.chat.completions.create({
model: 'gpt-4o-mini',
stream: true,
messages: [{ role: 'user', content: 'count to 5' }],
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
}
Cancellation
Pass an AbortSignal. odnoga will cancel the upstream vendor call and bill only the tokens already produced.
const ctrl = new AbortController();
setTimeout(() => ctrl.abort(), 5000);
await client.chat.completions.create({ /* … */ }, { signal: ctrl.signal });
Streams are always OpenAI-shaped
Even when the workspace's response format is set to native (raw vendor bodies), streamed responses are delivered in the OpenAI delta shape — a raw vendor stream carries no usage frame to meter. The stream's x-airouter-response-format header always reads openai (plus an explanatory x-airouter-response-format-note when the workspace is on native mode), so a native-mode client never has to guess.
Headers on streams
Headers are sent at stream open, before any tokens exist, so streams carry routing evidence, not billing totals: x-airouter-vendor, x-airouter-model, x-airouter-fallback, x-airouter-service-tier, x-airouter-region, x-airouter-region-honored and x-airouter-response-format. Final tokens and cost are metered from the stream server-side and land on the request record — check the Requests page or requests.search over MCP, keyed by end-user id, model and time (streams carry no request-id header).
Don't double-buffer
If you proxy the stream to your own client, forward the chunks raw — don't reassemble and re-emit. Latency matters.