Skip to content

Skip stream_options injection for Anthropic Messages routes regardless of provider - #7210

Draft
lpcox with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-stream-options-injection
Draft

Skip stream_options injection for Anthropic Messages routes regardless of provider#7210
lpcox with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-stream-options-injection

Conversation

Copilot AI commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Streaming requests to /v1/messages routed through the Copilot provider (which fronts the Anthropic Messages API) get stream_options: { include_usage: true } injected into the body. The Messages endpoint rejects this field, causing upstream 400 stream_options: Extra inputs are not permitted errors.

Root cause

injectStreamOptions only skipped injection when provider was anthropic/gemini, or for the OpenAI /responses path. Requests with provider === 'copilot' and path /v1/messages matched neither guard, so injection proceeded into a body shape the Messages API rejects.

Fix

  • containers/api-proxy/body-transform.js: Added a path-based guard (mirroring the existing /responses guard) that skips injection for /messages and /vN/messages routes regardless of provider, since the Messages API can be served by multiple providers (including Copilot).
  • containers/api-proxy/body-transform.test.js: Added coverage confirming injection is skipped for Copilot on /v1/messages (and path variants), while still applied for Copilot on /v1/chat/completions.
// The Anthropic Messages API rejects stream_options.include_usage.
// Skip injection for /messages and /vN/messages routes regardless of
// provider, since the Copilot provider also fronts the Messages API.
if (/^\/?(?:v\d+\/)?messages(?:\/|$)/.test(pathOnly)) return null;

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix stream_options injection for Copilot Messages API Skip stream_options injection for Anthropic Messages routes regardless of provider Aug 10, 2026
Copilot AI requested a review from lpcox August 10, 2026 17:59
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.

api-proxy injects stream_options into Copilot Messages API (/v1/messages) requests, causing 400

3 participants