How to Use Streaming

How to Use Streaming

Streaming returns provider output incrementally over Server-Sent Events (SSE). Use it only with models whose schema declares streaming support.

Endpoint

Append /stream to the complete model endpoint:

POST /api/v3/{vendor}/{model}/stream
POST /api/v3/{vendor}/{model}/{variant}/stream

Do not add "stream": true to an ordinary model submission. The /stream path selects streaming mode.

cURL Example

This MiniMax speech endpoint is a supported non-LLM streaming model:

curl --fail-with-body --no-buffer --connect-timeout 10 --max-time 600 \
  --request POST 'https://api.wavespeed.ai/api/v3/minimax/speech-02-turbo/stream' \
  --header "Authorization: Bearer ${WAVESPEED_API_KEY}" \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "text": "Hello world! This is a streaming speech example.",
    "voice_id": "Energetic_Girl",
    "emotion": "happy",
    "speed": 1,
    "volume": 1
  }'

The server responds with Content-Type: text/event-stream. Each event is written as a data: line. The JSON inside that line is model-specific; for example, MiniMax speech can return encoded audio chunks. Do not assume every streaming model emits progress percentages or the same event fields.

JavaScript Example

The parser below preserves incomplete lines between network chunks:

const apiKey = process.env.WAVESPEED_API_KEY;
if (!apiKey) throw new Error('Set WAVESPEED_API_KEY');
 
const response = await fetch(
  'https://api.wavespeed.ai/api/v3/minimax/speech-02-turbo/stream',
  {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${apiKey}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      text: 'Hello world! This is a streaming speech example.',
      voice_id: 'Energetic_Girl',
      emotion: 'happy',
      speed: 1,
      volume: 1
    }),
    signal: AbortSignal.timeout(600_000)
  }
);
 
if (!response.ok) {
  throw new Error(`HTTP ${response.status}: ${await response.text()}`);
}
if (!response.body) throw new Error('Response body is not available');
 
const reader = response.body.getReader();
const decoder = new TextDecoder();
let buffer = '';
 
while (true) {
  const { done, value } = await reader.read();
  buffer += decoder.decode(value || new Uint8Array(), { stream: !done });
 
  const lines = buffer.split('\n');
  buffer = done ? '' : lines.pop() || '';
 
  for (const rawLine of lines) {
    const line = rawLine.replace(/\r$/, '');
    if (!line.startsWith('data:')) continue;
 
    const payload = line.slice(5).trimStart();
    if (!payload) continue;
    const event = JSON.parse(payload);
    console.log(event); // Handle the selected model's documented payload here.
  }
 
  if (done) break;
}

Python Example

import json
import os
import requests
 
api_key = os.environ["WAVESPEED_API_KEY"]
 
with requests.post(
    "https://api.wavespeed.ai/api/v3/minimax/speech-02-turbo/stream",
    headers={"Authorization": f"Bearer {api_key}"},
    json={
        "text": "Hello world! This is a streaming speech example.",
        "voice_id": "Energetic_Girl",
        "emotion": "happy",
        "speed": 1,
        "volume": 1,
    },
    stream=True,
    timeout=(10, 600),
) as response:
    response.raise_for_status()
    for line in response.iter_lines(decode_unicode=True):
        if not line or not line.startswith("data:"):
            continue
        event = json.loads(line[5:].lstrip())
        print(event)  # Handle the selected model's documented payload here.

Operational Notes

  • A streaming request is still authenticated, billed, and associated with a prediction.
  • Network failure after submission can be ambiguous. Do not automatically replay the POST unless duplicate work is acceptable.
  • Set a client deadline appropriate for the model. The API closes a stream that produces no data for 10 minutes.
  • Handle SSE error events and client disconnects.
  • Use ordinary asynchronous submission plus polling or webhooks when incremental output is not required.

See the Streaming API reference for supported model families and the request contract.

© 2026 WaveSpeedAI. All rights reserved.