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

# Claude streaming chat example

> Streaming chat example for Claude Messages API.

## Recommended endpoint

* [Claude /v1/messages](/en/api-reference/endpoints/claude/text)

## Minimal request

```json theme={null}
{
  "model": "claude-sonnet-4-20250514",
  "max_tokens": 1024,
  "stream": true,
  "messages": [
    {
      "role": "user",
      "content": [{ "type": "text", "text": "Explain SSE streaming while streaming the answer." }]
    }
  ]
}
```

## cURL example

```bash theme={null}
curl https://api.anthropic.com/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -N \
  -d '{
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 1024,
    "stream": true,
    "messages": [
      {
        "role": "user",
        "content": [{ "type": "text", "text": "Explain SSE streaming while streaming the answer." }]
      }
    ]
  }'
```

## Python example

```python theme={null}
from anthropic import Anthropic

client = Anthropic(api_key="<ANTHROPIC_API_KEY>")

with client.messages.stream(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    messages=[
        {
            "role": "user",
            "content": [{"type": "text", "text": "Explain SSE streaming while streaming the answer."}],
        }
    ],
) as stream:
    for text in stream.text_stream:
        print(text, end="")
```

## Node.js example

```js theme={null}
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  apiKey: process.env.ANTHROPIC_API_KEY,
});

const stream = await client.messages.stream({
  model: "claude-sonnet-4-20250514",
  max_tokens: 1024,
  messages: [
    {
      role: "user",
      content: [{ type: "text", text: "Explain SSE streaming while streaming the answer." }]
    }
  ]
});

for await (const text of stream.textStream) {
  process.stdout.write(text);
}
```

## Best practices

* Claude returns SSE events rather than one final JSON payload
* Preserve content-block boundaries when parsing streamed output
* If you also enable tools or thinking, your event parser must support more than plain text deltas
