# 流式传输

流式传输是改善聊天、copilot 和交互式生成流程中感知延迟的最简单方式。

## 已发布的流式传输接入点

| 接口          | 如何启用                                               |
| ----------- | -------------------------------------------------- |
| OpenAI 兼容聊天 | 设置 `stream: true` 开启 `/openai/v1/chat/completions` |
| Gemini 流式传输 | 调用 `streamGenerateContent?alt=sse`                 |

## 何时使用流式传输

* 聊天界面
* 在 IDE 或 copilot 中进行渐进式生成
* 长时间运行的答案生成，其中首个 token 延迟很重要

## 流的样子

* 兼容 OpenAI 的聊天会返回 SSE 分块，格式为 `chat.completion.chunk` 格式
* Gemini 流式传输使用已发布的 `streamGenerateContent?alt=sse` 路由
* 在流关闭之前，不应将任何一个流视为最终答案

## 实现提示

* 将每个分块视为部分状态，而不是最终答案
* 让服务器能够容忍连接中断
* 如果需要审计或回放，请存储最终组装后的输出
* 将 UI 渲染与业务侧完成逻辑分离

## 相关页面

* [OpenAI 兼容 API](/docs/zh/api-can-kao/jian-rong-openai.md)
* [Gemini 兼容 API](/docs/zh/api-can-kao/jian-rong-gemini.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://anyint.gitbook.io/docs/zh/gong-neng/liu-shi-chuan-shu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
