#7274·sub2api

[Compatibility] Chat Completions 流转换为 Responses 事件流时 EOF 状态处理异常

Author: OrangeymCreated Sep 17, 2026Updated Sep 17, 2026

{ "error": { "message": "Upstream stream ended without a terminal response event", "type": "api_error" } }

问题

使用仅支持 Chat Completions API 的上游渠道调用 /v1/responses 时,流式响应输出部分内容后结束,并返回:

json
{
  "error": {
    "message": "Upstream stream ended without a terminal response event",
    "type": "api_error"
  }
}

## 场景

客户端接口:POST /v1/responses
上游接口:POST /v1/chat/completions
请求模式:stream=true
模型:Kimi-K3

## 实际结果

上游 Chat Completions 流能够正常输出 delta,并可能以以下信号结束:

finish_reason: "stop"
data: [DONE]

兼容层结束输出时,没有发送 Responses API 所要求的终态事件:

response.completed
response.failed
response.incomplete

最终被判断为异常断流。

## 预期结果

Chat Completions 流正常结束时,应将其结束状态转换为 Responses API 终态事件:

finish_reason: "stop"       -> response.completed
finish_reason: "length"     -> response.incomplete
上游明确返回错误             -> response.failed

收到 [DONE] 后,应发送并刷新对应终态事件,再关闭连接。

## 建议排查位置

请检查 Chat Completions 到 Responses API 的流式转换逻辑:

- [DONE] 的处理
- finish_reason 的状态映射
- SSE 读取循环的 EOF 处理
- response.completed 的生成和 flush
- 工具调用及长度限制场景的终态映射
- 上游省略 [DONE] 时的兼容性处理

## 使用测试账号连接下的测试连接功能可以正常使用有返回

开始测试账号:k3-1 账号类型:apikey 已连接到 API 使用模型:moonshotai/Kimi-K3 发送测试消息:"hi" 响应: Hi! What can I help you with today? 测试完成!