Stream Generation
curl --request POST \
--url https://api.example.com/api/v2/generate/streamimport requests
url = "https://api.example.com/api/v2/generate/stream"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://api.example.com/api/v2/generate/stream', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/v2/generate/stream",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/v2/generate/stream"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/api/v2/generate/stream")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v2/generate/stream")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_bodyGenerate
Stream Generation
Stream text generation in real-time via Server-Sent Events
POST
/
api
/
v2
/
generate
/
stream
Stream Generation
curl --request POST \
--url https://api.example.com/api/v2/generate/streamimport requests
url = "https://api.example.com/api/v2/generate/stream"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://api.example.com/api/v2/generate/stream', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/v2/generate/stream",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/v2/generate/stream"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/api/v2/generate/stream")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v2/generate/stream")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_bodyStream text responses token-by-token using Server-Sent Events. Only available for text/LLM models.
Request
Same as Create Generation —model, prompt, optional params.
import requests
response = requests.post(
"https://elumenta.ru/api/v2/generate/stream",
headers={
"Authorization": "Bearer nb_YOUR_API_KEY",
"Accept": "text/event-stream"
},
json={
"model": "gpt-5",
"prompt": "Write a short story about a robot learning to paint"
},
stream=True
)
for line in response.iter_lines():
if line:
line = line.decode("utf-8")
if line.startswith("data: ") and line != "data: [DONE]":
import json
chunk = json.loads(line[6:])
if chunk.get("type") == "content_delta":
print(chunk["delta"], end="", flush=True)
const response = await fetch("https://elumenta.ru/api/v2/generate/stream", {
method: "POST",
headers: {
"Authorization": "Bearer nb_YOUR_API_KEY",
"Content-Type": "application/json"
},
body: JSON.stringify({
model: "gpt-5",
prompt: "Write a short story about a robot learning to paint"
})
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const lines = decoder.decode(value).split("\n");
for (const line of lines) {
if (line.startsWith("data: ") && line !== "data: [DONE]") {
const chunk = JSON.parse(line.slice(6));
if (chunk.type === "content_delta") {
process.stdout.write(chunk.delta);
}
}
}
}
SSE Event Format
data: {"type": "generation_start", "id": 18473, "model": "gpt-5"}
data: {"type": "content_delta", "delta": "Once"}
data: {"type": "content_delta", "delta": " upon"}
data: {"type": "content_delta", "delta": " a time"}
data: {"type": "generation_end", "id": 18473, "tokens_spent": 3}
data: [DONE]
| Event type | Fields | Description |
|---|---|---|
generation_start | id, model | Generation begun |
content_delta | delta | Token chunk |
generation_end | id, tokens_spent | Done, billing info |
error | message | Something went wrong |
Streaming is only available for text/LLM models. Image, video, and audio models do not support streaming.
⌘I

