Skip to main content
POST
/
api
/
v2
/
generate
/
stream
Stream Generation
curl --request POST \
  --url https://api.example.com/api/v2/generate/stream
Stream text responses token-by-token using Server-Sent Events. Only available for text/LLM models.

Request

Same as Create Generationmodel, prompt, optional params.
import requests

response = requests.post(
    "https://neuralbox.top/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)

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 typeFieldsDescription
generation_startid, modelGeneration begun
content_deltadeltaToken chunk
generation_endid, tokens_spentDone, billing info
errormessageSomething went wrong
Streaming is only available for text/LLM models. Image, video, and audio models do not support streaming.