Orq MCP is live: Use natural language to interrogate traces, spot regressions, and experiment your way to optimal AI configurations. Available in Claude Desktop, Claude Code, Cursor, and more. Start now →
Enable real-time response streaming for better user experience.
curl -N -X POST https://api.orq.ai/v3/router/responses \ -H "Authorization: Bearer $ORQ_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "openai/gpt-5.4", "input": "Write a story about space exploration", "stream": true }'
import OpenAI from "openai";const client = new OpenAI({ apiKey: process.env.ORQ_API_KEY, baseURL: "https://api.orq.ai/v3/router",});const stream = await client.responses.create({ model: "openai/gpt-5.4", input: "Write a story about space exploration", stream: true,});for await (const event of stream) { if (event.type === "response.output_text.delta") { process.stdout.write(event.delta); }}
from openai import OpenAIimport osclient = OpenAI( api_key=os.environ.get("ORQ_API_KEY"), base_url="https://api.orq.ai/v3/router",)stream = client.responses.create( model="openai/gpt-5.4", input="Write a story about space exploration", stream=True,)for event in stream: if event.type == "response.output_text.delta": print(event.delta, end="", flush=True)
import OpenAI from "openai";const client = new OpenAI({ apiKey: process.env.ORQ_API_KEY, baseURL: "https://api.orq.ai/v3/router",});const stream = await client.chat.completions.create({ model: "openai/gpt-5.4", messages: [ { role: "user", content: "Write a story about space exploration" }, ], stream: true,});for await (const chunk of stream) { const content = chunk.choices[0]?.delta?.content || ""; if (content) { process.stdout.write(content); }}
from openai import OpenAIimport osclient = OpenAI( api_key=os.environ.get("ORQ_API_KEY"), base_url="https://api.orq.ai/v3/router",)stream = client.chat.completions.create( model="openai/gpt-5.4", messages=[{"role": "user", "content": "Write a story about space exploration"}], stream=True,)for chunk in stream: if chunk.choices and chunk.choices[0].delta.content is not None: print(chunk.choices[0].delta.content, end="", flush=True)
import OpenAI from "openai";const client = new OpenAI({ apiKey: process.env.ORQ_API_KEY, baseURL: "https://api.orq.ai/v3/router",});const stream = await client.responses.create({ model: "openai/gpt-5.4", input: "Write a detailed explanation of quantum computing", stream: true,});for await (const event of stream) { if (event.type === "response.output_text.delta") { process.stdout.write(event.delta); }}
from openai import OpenAIimport osclient = OpenAI( api_key=os.environ.get("ORQ_API_KEY"), base_url="https://api.orq.ai/v3/router",)stream = client.responses.create( model="openai/gpt-5.4", input="Write a detailed explanation of quantum computing", stream=True,)for event in stream: if event.type == "response.output_text.delta": print(event.delta, end="", flush=True)
import OpenAI from "openai";const client = new OpenAI({ apiKey: process.env.ORQ_API_KEY, baseURL: "https://api.orq.ai/v3/router",});const stream = await client.chat.completions.create({ model: "openai/gpt-5.4", messages: [ { role: "user", content: "Write a detailed explanation of quantum computing", }, ], stream: true,});for await (const chunk of stream) { process.stdout.write(chunk.choices[0]?.delta?.content || "");}
from openai import OpenAIimport osclient = OpenAI( api_key=os.environ.get("ORQ_API_KEY"), base_url="https://api.orq.ai/v3/router",)stream = client.chat.completions.create( model="openai/gpt-5.4", messages=[ { "role": "user", "content": "Write a detailed explanation of quantum computing", } ], stream=True,)for chunk in stream: if chunk.choices and chunk.choices[0].delta.content is not None: print(chunk.choices[0].delta.content, end="")
The examples in this section use the Chat Completions endpoint. The same patterns apply to the Responses API: replace chat.completions.create(...) with responses.create(...), update the endpoint to /v3/router/responses, and handle response.output_text.delta events instead of choices[0].delta.content.
Guard against network drops and unexpected errors by wrapping the stream loop in a try/except. The TypeScript example additionally resets a timeout on each chunk.
const updateUI = (content: string) => { process.stdout.write(content); }; // replace with your UI update logicconst robustStreamProcessing = async (stream) => { try { let response = ""; const timeout = setTimeout(() => { throw new Error("Stream timeout"); }, 30000); for await (const chunk of stream) { clearTimeout(timeout); if (chunk.choices[0]?.delta?.content) { response += chunk.choices[0].delta.content; // Update UI with new content updateUI(chunk.choices[0].delta.content); } if (chunk.choices[0]?.finish_reason) { break; } } return response; } catch (error) { console.error("Streaming error:", error); throw error; }};
import sysdef update_ui(content: str) -> None: sys.stdout.write(content) # replace with actual UI update logicdef robust_stream_processing(stream) -> str: try: response = "" for chunk in stream: if chunk.choices and chunk.choices[0].delta.content: response += chunk.choices[0].delta.content update_ui(chunk.choices[0].delta.content) if chunk.choices and chunk.choices[0].finish_reason: break return response except Exception as error: print(f"Streaming error: {error}", file=sys.stderr) raise
The examples in this section use the Chat Completions endpoint. The same patterns apply to the Responses API: replace chat.completions.create(...) with responses.create(...). For cURL, use /v3/router/responses.
Fire multiple streams concurrently using Promise.all in TypeScript and asyncio.gather in Python to get independent responses without waiting for each to finish.