Skip to content

fix(openai): stream chat completions for long Anthropic-backed turns#655

Open
Solaris-star wants to merge 1 commit into
OpenBMB:mainfrom
Solaris-star:fix/653-openai-provider-stream-long-turns
Open

fix(openai): stream chat completions for long Anthropic-backed turns#655
Solaris-star wants to merge 1 commit into
OpenBMB:mainfrom
Solaris-star:fix/653-openai-provider-stream-long-turns

Conversation

@Solaris-star

Copy link
Copy Markdown

Summary

OpenAIProvider always called client.chat.completions.create without stream=True. Against Anthropic-backed OpenAI-compatible endpoints (Anthropic Cloud, Bedrock, enterprise gateways), long-running turns fail with:

HTTP 400 — Streaming is required for operations that may take longer than 10 minutes

Change

  • Add _chat_completion() that forces stream=True (+ stream_options.include_usage when supported)
  • Aggregate streamed deltas (content + tool_calls by index + final usage) into the classic non-stream object graph so _deserialize_chat_response / _track_token_usage stay unchanged
  • Route both chat-mode and Responses-API-fallback chat paths through the helper

Test plan

  • Unit tests mock a multi-chunk stream (content + tool_calls + usage)
  • Manual: Claude via OpenAI-compat gateway on a multi-minute turn completes without HTTP 400

Fixes #653

Non-streaming chat.completions.create fails against Anthropic-backed
OpenAI-compatible endpoints with HTTP 400 "Streaming is required for
operations that may take longer than 10 minutes". Always stream and
reassemble content / tool_calls / usage into the classic response shape
consumed by existing deserializers.

Fixes OpenBMB#653
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Non-streaming chat completions fail against Anthropic-backed OpenAI-compatible endpoints on long-running turns (HTTP 400 "Streaming is required")

1 participant