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

# 流式传输

所有对话补全接口都支持通过 stream: true 开启流式传输。Token 会以 SSE（服务端推送事件）的形式实时返回。

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

client = OpenAI(
    base_url="https://api.cloudsome-inc.ai/v1",
    api_key="sk_live_...",
)

response = client.chat.completions.create(
    model="claude-sonnet-4-6",
    messages=[{"role": "user", "content": "Hello!"}],
    stream=True,
)

for chunk in response:
    for choice in chunk.choices:
        if choice.delta.content:
            print(choice.delta.content, end="")
```

## 流式计费规则

* 如果上游在数据流开始前返回错误，将全额退款。
* 如果数据流开始后断开连接，将优先按已产生的实际用量结算；无法取得准确用量时，将根据已生成内容估算。
* 如果上游在传输中出错，将按已产生的实际用量结算；无法取得准确用量时，将根据已接收的部分响应估算。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.