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

# Streaming

> Stream Anthropic-style Messages API events.

Set `stream: true` to receive Anthropic-style event streams.

Use this when your client already expects `message_start`, `content_block_delta`, and `message_stop` events.

## Enable Streaming

<CodeGroup>
  ```python Python theme={null}
  from anthropic import Anthropic

  client = Anthropic(
      base_url="https://api.naga.ac",
      api_key="YOUR_API_KEY",
  )

  with client.messages.stream(
      model="claude-sonnet-4.5",
      max_tokens=256,
      messages=[
          {"role": "user", "content": "Stream a short explanation of retries."}
      ],
  ) as stream:
      for text in stream.text_stream:
          print(text, end="", flush=True)
  ```

  ```javascript Node.js theme={null}
  import Anthropic from '@anthropic-ai/sdk';

  const client = new Anthropic({
    baseURL: 'https://api.naga.ac',
    apiKey: 'YOUR_API_KEY',
  });

  const stream = client.messages
    .stream({
      model: 'claude-sonnet-4.5',
      max_tokens: 256,
      messages: [
        { role: 'user', content: 'Stream a short explanation of retries.' },
      ],
    })
    .on('text', (text) => {
      process.stdout.write(text);
    });

  await stream.finalMessage();
  ```

  ```bash cURL theme={null}
  curl -N https://api.naga.ac/v1/messages \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "claude-sonnet-4.5",
      "max_tokens": 256,
      "messages": [
        {
          "role": "user",
          "content": "Stream a short explanation of retries."
        }
      ],
      "stream": true
    }'
  ```
</CodeGroup>

## Event Lifecycle

Per the protocol tests, a normal text stream begins with `message_start` and ends with `message_stop`.

```text theme={null}
event: message_start
data: {...}

event: content_block_start
data: {...}

event: content_block_delta
data: {"delta":{"type":"text_delta","text":"Hello"}}

event: message_delta
data: {"delta":{"stop_reason":"end_turn","stop_sequence":null}}

event: message_stop
data: {...}
```

## Tool Streaming

Tool argument deltas appear as `content_block_delta` with `type: input_json_delta`.

## Thinking Streaming

Thinking-related data can appear before text blocks, including `signature_delta` events.

## What to listen for

* `message_start` for the initial message frame and input usage
* `content_block_start` and `content_block_delta` for text, tool, and thinking blocks
* `message_delta` for stop reason and final output usage
* `message_stop` for stream completion

## Common mistakes

* assuming every `content_block_delta` is text
* ignoring `message_delta` and losing final usage information
* treating Messages streams like chat chunks or Responses semantic events

## Related Docs

* [Capability-level Streaming Comparison](/build/streaming)
* [Messages API](/api/messages)
