HridaSpro Docs

Advanced

Streaming

Stream responses in real time — with guardrails applied before the first token.

Spro supports streaming on both the Chat Completions API and the Responses API. Set stream: true and tokens arrive as server-sent events as they are generated — the same behavior as calling the provider directly.

Streaming with guardrails

Guardrails and streaming work together. Input guardrails run before the stream starts — if an input guardrail blocks the request, you get an immediate 403 and no stream is ever opened. Output guardrails run on the content as it streams, and the stream begins only once input checks pass:

from openai import OpenAI
client = OpenAI(    base_url="https://spro.hridaai.com/v1",    api_key="YOUR_SPRO_API_KEY",)
response = client.chat.completions.create(    model="gpt-oss-20b",    messages=[        {"role": "system", "content": "You are a helpful assistant."},        {"role": "user", "content": "Introduce yourself"},    ],    temperature=0.7,    stream=True,)
for chunk in response:    if chunk.choices:        delta = chunk.choices[0].delta        if delta.content:            print(delta.content, end="", flush=True)
    if chunk.usage is not None:        print("\nUSAGE:", chunk.usage)

Streaming on the Responses API

Responses API streaming sends typed events — response.created, incremental response.output_text.delta events, and response.completed:

response = client.responses.create(    model="gpt-oss-20b",    input="Write a short bedtime story about a robot.",    stream=True,)
for event in response:    if event.type == "response.output_text.delta":        print(event.delta, end="", flush=True)

Getting usage from streams

What's Next