Non-streaming chat completions fail against Anthropic-backed OpenAI-compatible endpoints on long-running turns (HTTP 400 "Streaming is required")
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 34.3k
- Fork
- 4.3k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
Summary
runtime/node/agent/providers/openai_provider.py issues every client.chat.completions.create(**payload) call without setting stream=True. The OpenAI Python SDK defaults to stream=False in that case, and the full response is awaited over a single non-streaming HTTP call.
When ChatDev is pointed at an OpenAI-compatible endpoint that is backed by Anthropic Claude models (either Anthropic's own API or an intermediary such as AWS Bedrock or an enterprise LLM gateway), long-running turns hit an upstream policy limit and fail with:
Error code: 400 — {
"type": "invalid_request",
"status": 400,
"message": "Streaming is required for operations that may take longer than 10 minutes",
"instance": "/v1/chat/completions"
}
The 10-minute non-streaming cap is enforced by Anthropic (documented at https://github.com/anthropics/anthropic-sdk-python#long-requests). Any workflow that produces a large output in a single turn — big JSON aggregations, full-page renders, long structured summaries — will trip it.
Environment
- ChatDev branch:
main(commit4fd4da6at time of report) - Provider:
openai(built-inOpenAIProvider) - Upstream: OpenAI-compatible API serving
claude-sonnet-4-6/claude-opus-4-7 - Python: 3.12
openaiSDK: shipped with ChatDev'suv.lock
Reproduction
A workflow with a single agent node that:
- Uses
provider: openaiwith a Claude model (model: claude-sonnet-4-6or similar) against an Anthropic-backed OpenAI-compatible endpoint. - Receives a large input via
edges:from upstream nodes (a few hundred KB of JSON is enough). - Emits a large output in one turn (e.g. rendering full-page Confluence storage XML, ~15 KB / ~5–10k output tokens, ~3–5 min wall-time at typical Claude Sonnet speeds).
Result: HTTP 400 with the message above. The node's final_message becomes the error text and the workflow exits completed with the error surfaced instead of the intended output.
The same workflow succeeds against GPT-family models under identical conditions, because Azure OpenAI does not enforce the 10-minute non-streaming cap.
Root cause
OpenAIProvider._build_chat_payload() and _build_request_payload() do not set stream=True, and call_model() calls client.chat.completions.create(**payload) / client.responses.create(**payload) directly. The OpenAI Python SDK defaults stream to False, so ChatDev's LLM traffic is entirely non-streaming.
For GPT-shaped upstreams this is fine — for Anthropic-shaped ones (either Anthropic Cloud, Bedrock, or any OpenAI-compat gateway that proxies to Anthropic and inherits its policies) it is a hard failure on any turn that could exceed 10 min.
Suggested solution
Force stream=True at the provider level and aggregate the chunks back into an object with the same attribute shape used by the existing deserializer, so that the rest of the provider code (_track_token_usage, _deserialize_chat_response, _append_chat_response_output) is unchanged.
Two concrete places to change in runtime/node/agent/providers/openai_provider.py:
- In
call_model(), replace the two directclient.chat.completions.create(**request_payload)calls with a helperself._chat_completion(client, payload). - Implement
_chat_completion()as:- Set
payload[\"stream\"] = Trueandpayload.setdefault(\"stream_options\", {\"include_usage\": True}). - Iterate the returned stream, concatenating
delta.contentand reassemblingdelta.tool_calls[]by index. - Track the final
usageobject from the last chunk (OpenAI streams it whenstream_options.include_usage=true). - Return a lightweight object graph exposing
choices[0].message.{content, tool_calls},.id,.model,.usage— the exact shape the rest of the file consumes.
- Set
I have a working patch running against an Anthropic-backed OpenAI-compatible LLM gateway (Bedrock Claude Sonnet 4-6 + Claude Opus 4-7). It reduces a 10+ min hanging turn to a ~4 min streamed completion with no behavior change for GPT models. Happy to open a PR with the patch + a small unit test that mocks the streamed chunk shape, if the maintainers are open to it.
Impact / severity
- Blocking for any ChatDev workflow using Claude via an OpenAI-compat gateway on turns > ~10 min.
- Silent for smaller turns — the same code path works and gives no warning that it will break at scale.
- Not caught by existing tests since the streaming vs. non-streaming distinction is upstream-policy-driven, not detected client-side.
Related upstream references
- Anthropic long-request policy: https://github.com/anthropics/anthropic-sdk-python#long-requests
- OpenAI SDK
stream_options.include_usage: https://platform.openai.com/docs/api-reference/chat/create#chat-create-stream_options
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu trong runtime/node/agent/providers/openai_provider.py, đọc call_model(), _build_chat_payload(), _build_request_payload() và các bộ giải tuần tự phản hồi hiện có. Thêm phần xử lý hoàn tất qua streaming được đề xuất và một unit test mô phỏng các chunk được streaming, bảo toàn content, tool calls, metadata và usage. Công việc được xem là hoàn tất khi các lượt dài sử dụng Anthropic thành công, trong khi hành vi GPT hiện có và việc theo dõi token vẫn không thay đổi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- api, backend
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 55/100