DEVUP Docs
Back to Dashboard
Server-Sent Events

Streaming

Stream responses incrementally using server-sent events (SSE). By setting stream: true, the application processes delta events as they arrive, significantly reducing time to first token. Streaming is available only for models and endpoints that support it.

Request
SSE connection
Delta events
Completed response

Examples

from openai import OpenAI

openai = OpenAI(
    api_key="$DEVUP_API_KEY",
    base_url="https://api.devupai.com/v1",
)

stream = openai.chat.completions.create(
    model="deepseek-ai/DeepSeek-V4-Pro",
    messages=[{"role": "user", "content": "Hello!"}],
    stream=True,
)

for chunk in stream:
    content = chunk.choices[0].delta.content
    if content is not None:
        print(content, end="", flush=True)
print()

SSE format

Each streamed chunk is a data: event containing a JSON payload. The text delta normally arrives through choices[0].delta.content. The stream ends when the server closes the SSE connection. OpenAI-compatible clients may also receive a data: [DONE] terminal event when provided by the upstream stream.

Illustrative stream output. The data: [DONE] terminal event appears only when it is provided by the upstream stream.

json
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","choices":[{"delta":{"content":"Hello"}}]}

data: {"id":"chatcmpl-...","object":"chat.completion.chunk","choices":[{"delta":{"content":" World"}}]}

data: [DONE]

Errors and cancellation

Stopping a stream

The client may abort the HTTP request at any time using an AbortController (in JS) or the SDK's supported cancellation mechanism.

Stream errors

Errors may occur before or during streaming. Applications should handle network interruptions gracefully, keeping in mind that partial output may have already been received.

What's Next