> ## Documentation Index
> Fetch the complete documentation index at: https://docs.blackbox.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Streaming

> Stream responses token by token using the Responses API for real-time output

The Responses API supports streaming to receive tokens as they're generated instead of waiting for the complete response. Set `stream: true` in your request, then read the response body as a stream of server-sent events (SSE). Each event contains a response chunk that you can display incrementally.

<Tip>
  The Responses API is best supported on the **Enterprise plan**. Use `https://enterprise.blackbox.ai` as the base URL for full model availability and production reliability. The API is also available on standard plans at `https://api.blackbox.ai`, where it is currently experimental.
</Tip>

## Basic Streaming Request

<CodeGroup>
  ```typescript TypeScript theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
  const response = await fetch('https://enterprise.blackbox.ai/v1/responses', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      Authorization: `Bearer ${process.env.BLACKBOX_API_KEY}`,
    },
    body: JSON.stringify({
      model: 'openai/gpt-5.3-codex',
      input: [
        {
          type: 'message',
          role: 'user',
          content: 'Write a haiku about debugging code.',
        },
      ],
      stream: true,
    }),
  });

  const reader = response.body.getReader();
  const decoder = new TextDecoder();

  while (true) {
    const { done, value } = await reader.read();
    if (done) break;

    const chunk = decoder.decode(value);
    const lines = chunk.split('\n');

    for (const line of lines) {
      if (line.startsWith('data:')) {
        const data = line.substring(6).trim();
        if (data) {
          const event = JSON.parse(data);
          if (event.type === 'response.output_text.delta') {
            process.stdout.write(event.delta);
          }
        }
      }
    }
  }
  ```

  ```python Python theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
  import os
  import json
  import requests

  response = requests.post(
      'https://enterprise.blackbox.ai/v1/responses',
      headers={
          'Content-Type': 'application/json',
          'Authorization': f"Bearer {os.environ['BLACKBOX_API_KEY']}",
      },
      json={
          'model': 'openai/gpt-5.3-codex',
          'input': [
              {
                  'type': 'message',
                  'role': 'user',
                  'content': 'Write a haiku about debugging code.',
              },
          ],
          'stream': True,
      },
      stream=True
  )

  for line in response.iter_lines():
      if line:
          decoded = line.decode('utf-8')
          if decoded.startswith('data:'):
              data = decoded[6:].strip()
              if data:
                  event = json.loads(data)
                  if event.get('type') == 'response.output_text.delta':
                      print(event['delta'], end='', flush=True)
  ```

  ```bash cURL theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
  curl https://enterprise.blackbox.ai/v1/responses \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $BLACKBOX_API_KEY" \
    -d '{
      "model": "openai/gpt-5.3-codex",
      "input": [
        {
          "type": "message",
          "role": "user",
          "content": "Write a haiku about debugging code."
        }
      ],
      "stream": true
    }'
  ```
</CodeGroup>

## Streaming Events

The stream emits server-sent events in the following sequence:

| Event                        | Description                                                      |
| ---------------------------- | ---------------------------------------------------------------- |
| `response.created`           | Response initialized — signals the stream has started            |
| `response.output_text.delta` | Text chunk received — contains a `delta` field with the new text |
| `response.output_text.done`  | Text generation complete for the current output item             |
| `response.completed`         | Full response complete, includes final usage statistics          |

### Event Payloads

**`response.output_text.delta`**

```json theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
{
  "type": "response.output_text.delta",
  "delta": "Null pointer—"
}
```

**`response.completed`**

```json theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
{
  "type": "response.completed",
  "response": {
    "id": "resp_abc123",
    "object": "response",
    "model": "openai/gpt-5.3-codex",
    "output": [
      {
        "type": "message",
        "role": "assistant",
        "content": [
          {
            "type": "output_text",
            "text": "Null pointer—\nthe stack trace unfolds at dawn,\ncoffee grows cold."
          }
        ]
      }
    ],
    "usage": {
      "input_tokens": 12,
      "output_tokens": 20
    }
  }
}
```

## Request Parameters

<ParamField body="stream" type="boolean" required>
  Set to `true` to enable streaming. The response will be a stream of server-sent events instead of a single JSON object.
</ParamField>

<ParamField body="model" type="string" required>
  The model identifier to use. Example: `openai/gpt-5.3-codex`
</ParamField>

<ParamField body="input" type="array" required>
  Array of input messages with `type`, `role`, and `content` fields.
</ParamField>

## Next Steps

<CardGroup cols={2}>
  <Card title="Text Generation" icon="text" href="/api-reference/responses/text-generation">
    Learn about basic non-streaming text generation
  </Card>

  <Card title="Tool Calling" icon="wrench" href="/api-reference/responses/tool-calling">
    Stream responses that include tool calls
  </Card>
</CardGroup>
