Non-streaming chat completions fail against Anthropic-backed OpenAI-compatible endpoints on long-running turns (HTTP 400 "Streaming is required")
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 34.3k
- フォーク
- 4.3k
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
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
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
runtime/node/agent/providers/openai_provider.py から始め、call_model()、_build_chat_payload()、_build_request_payload()、および既存のレスポンスデシリアライザーを読みます。提案されているストリーミング完了処理と、ストリーミングされたチャンクをモックして content、tool calls、metadata、usage を保持するユニットテストを追加します。Anthropic をバックエンドとする長いターンが成功し、既存の GPT の動作とトークン追跡が変更されないことが完了の条件です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- api, backend
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 静か
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 55/100