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

# Streaming

> Stream responses token-by-token for real-time UX.

## Why streaming?

Streaming lets your app display responses as they're generated, instead of waiting for the full response. Essential for chatbots and interactive UIs.

## Python

```python theme={null}
from openai import OpenAI

client = OpenAI(
    base_url="https://kymaapi.com/v1",
    api_key="ky-your-api-key"
)

stream = client.chat.completions.create(
    model="qwen-3.6-plus",
    messages=[{"role": "user", "content": "Write a poem about AI"}],
    stream=True
)

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

## JavaScript

```javascript theme={null}
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://kymaapi.com/v1",
  apiKey: "ky-your-api-key",
});

const stream = await client.chat.completions.create({
  model: "qwen-3.6-plus",
  messages: [{ role: "user", content: "Write a poem about AI" }],
  stream: true,
});

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

## cURL

```bash theme={null}
curl https://kymaapi.com/v1/chat/completions \
  -H "Authorization: Bearer ky-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen-3.6-plus",
    "messages": [{"role": "user", "content": "Write a poem about AI"}],
    "stream": true
  }'
```
