# Streaming

Get responses in real-time as they're generated.

## Enable Streaming

Get responses in real-time as they're generated. Set `stream=True` (Python) or `stream: true` (JavaScript):

```python
# Enable streaming
stream = client.chat.completions.create(
    model="bizora-1.0",
    messages=[{"role": "human", "content": "What is section 179?"}],
    stream=True
)

# Process chunks as they arrive
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)
```

```javascript
// Enable streaming
const stream = await client.chat.completions.create({
  model: 'bizora-1.0',
  messages: [{ role: 'human', content: 'What is section 179?' }],
  stream: true
});

// Process chunks as they arrive
for await (const chunk of stream) {
  if (chunk.choices[0]?.delta?.content) {
    process.stdout.write(chunk.choices[0].delta.content);
  }
}
```

```bash
# Use -N flag for streaming, -X POST for method
curl -X POST -N https://api-bizora.ai/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk_live_YOUR_API_KEY" \
  -d '{
    "model": "bizora-1.0",
    "messages": [
      {"role": "human", "content": "What is section 179?"}
    ],
    "stream": true
  }'
```

## Multi-Turn Conversations with Streaming

Include conversation history to provide context:

```python
# Include conversation history
messages = [
    {"role": "human", "content": "What is section 179?"},
    {"role": "assistant", "content": "Section 179 allows businesses to deduct..."},
    {"role": "human", "content": "What are the requirements?"}
]

# Stream the response
stream = client.chat.completions.create(
    model="bizora-1.0",
    messages=messages,
    stream=True
)

for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)
```

```javascript
// Include conversation history
const messages = [
  { role: 'human', content: 'What is section 179?' },
  { role: 'assistant', content: 'Section 179 allows businesses to deduct...' },
  { role: 'human', content: 'What are the requirements?' }
];

// Stream the response
const stream = await client.chat.completions.create({
  model: 'bizora-1.0',
  messages: messages,
  stream: true
});

for await (const chunk of stream) {
  if (chunk.choices[0]?.delta?.content) {
    process.stdout.write(chunk.choices[0].delta.content);
  }
}
```

## Response Format

Each chunk contains incremental content:

```json
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion.chunk",
  "created": 1677652288,
  "model": "bizora-1.0",
  "choices": [{
    "index": 0,
    "delta": {
      "content": "text chunk"
    },
    "finish_reason": null
  }]
}
```

The stream ends with:

```
data: [DONE]
```
