Streaming
Streaming
CryptGPT supports Server-Sent Events (SSE) streaming for chat completions.
Enable Streaming
Set stream: true in your request:
{ "model": "gemma-4-26b", "messages": [{"role": "user", "content": "Hello"}], "stream": true}Response Format
The response is a series of SSE events:
data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","choices":[{"delta":{"role":"assistant"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","choices":[{"delta":{"content":"Hello"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","choices":[{"delta":{"content":"!"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","choices":[{"delta":{},"finish_reason":"stop"}]}
data: [DONE]Python Example
stream = client.chat.completions.create( model="gemma-4-26b", messages=[{"role": "user", "content": "Tell me a story"}], stream=True)
for chunk in stream: if chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="")Node.js Example
const stream = await client.chat.completions.create({ model: 'gemma-4-26b', messages: [{ role: 'user', content: 'Tell me a story' }], stream: true,});
for await (const chunk of stream) { process.stdout.write(chunk.choices[0]?.delta?.content || '');}