copilot-bridge icon indicating copy to clipboard operation
copilot-bridge copied to clipboard

Feature request: support claude-sonnet-5

Open mihailmariusiondev opened this issue 5 months ago • 5 comments

Thanks for the great work adding model-by-model support (opus 4.8, opus 4.6/4.7 1m, etc.)!

Since Claude Sonnet 5 was released, using it via Claude Code through copilot-bridge fails with:

API Error: 400 This model does not support assistant message prefill. The conversation must end with a user message.

Confirmed on v0.20.16 (latest): claude-sonnet-5 is listed as an available Copilot model (GET /v1/models returns it), and works fine for simple single-turn requests via raw HTTP to /v1/messages. The 400 only happens with real Claude Code sessions, which is consistent with the same pattern that affected opus-4.6/opus-4.7/sonnet-4.6 before they got the fallback: "chat-completions" treatment in MODEL_CAPABILITIES.

Would it be possible to add claude-sonnet-5 to MODEL_CAPABILITIES with the same chat-completions fallback used for the other Claude models? Happy to test a pre-release build if useful.

mihailmariusiondev avatar Jul 01 '26 09:07 mihailmariusiondev

Update / correction: I tested this further and it looks like it might NOT be a "missing MODEL_CAPABILITIES entry" issue after all.

I sent an identical hand-crafted request with a trailing assistant message (prefill pattern) to both claude-sonnet-4.6 and claude-sonnet-5 directly against /v1/messages:

{"model":"<model>","max_tokens":20,"messages":[
  {"role":"user","content":[{"type":"text","text":"Count to 3."}]},
  {"role":"assistant","content":[{"type":"text","text":"1, 2,"}]}
]}

Both models return the identical 400:

{"error":{"message":"This model does not support assistant message prefill. The conversation must end with a user message.","code":"invalid_request_body"}}

So this looks like a Copilot backend-level restriction that applies uniformly to Claude models via the chat-completions translation path, not something gated by MODEL_CAPABILITIES/fallback. In real Claude Code sessions, claude-sonnet-4.6 doesn't seem to trigger this (simple -p prompts work fine), but claude-sonnet-5 does — my guess is Claude Code adds some extended-thinking/continuation scaffolding specifically for sonnet-5 that results in a trailing assistant message, which sonnet-4.6 sessions don't hit under the same simple usage.

Not sure this is fixable purely bridge-side if the root cause is (a) Copilot's backend rejecting prefill for this endpoint regardless of model, combined with (b) Claude Code's own request shaping for this specific model. Flagging in case it's useful context — happy to help test if you have ideas.

mihailmariusiondev avatar Jul 01 '26 09:07 mihailmariusiondev

Found the root cause and a working local patch, sharing in case it helps.

Root cause: confirmed via raw request testing that Copilot's own backend returns 400 (This model does not support assistant message prefill) for any request whose translated OpenAI messages array ends in an assistant-role message, regardless of model — reproduced identically on both claude-sonnet-4.6 and claude-sonnet-5. This isn't a MODEL_CAPABILITIES/fallback gap; the bridge does zero validation of its own here (no match for the error string anywhere in src/), it's a pure passthrough of Copilot's rejection.

The reason claude-sonnet-4.6 "just works" in real Claude Code sessions while claude-sonnet-5 doesn't seems to be that Claude Code's own request-shaping is more likely to end a turn with a trailing assistant message for sonnet-5 (e.g. continuation after a truncated/thinking-heavy turn) — sonnet-4.6 usage apparently just doesn't hit that shape as often.

Workaround patch (happy to open a PR if useful): in translateAnthropicMessagesToOpenAI (src/bridges/claude/non-stream-translation.ts), if the last translated message has role assistant and no pending tool_calls, append a minimal synthetic user message ("Continue exactly from where you left off.") so the outgoing request legally ends in user role:

const lastMessage = otherMessages.at(-1)
if (lastMessage?.role === "assistant" && !lastMessage.tool_calls) {
  otherMessages.push({ role: "user", content: "Continue exactly from where you left off." })
}

Verified end-to-end: raw curl prefill test ("1, 2," → correctly continues "3, 4, 5", stop_reason: end_turn) and a real headless Claude Code session against claude-sonnet-5 through this patched build, both working. Regression-tested normal (non-prefill) requests and a full tool-use round trip — both unaffected.

mihailmariusiondev avatar Jul 01 '26 17:07 mihailmariusiondev

Thanks, this was very helpful. 👍

Your root-cause analysis matches what I found: this is a chat-completions backend restriction on conversations ending with an assistant prefill, not just a missing model entry.

This should be fixed in the latest version. Please try npx betahi-copilot-bridge@latest start.

betaHi avatar Jul 02 '26 05:07 betaHi

@betaHi Do we have plan to support opus-5 models? Thanks for your great work on this!

alnzng avatar Aug 05 '26 17:08 alnzng

Thanks @alnzng for asking! I’d like to support Opus-5, but I currently don’t have access to Opus models for testing. I’ll consider adding support once I have a way to verify the integration. PRs or testing feedback are welcome.

betaHi avatar Aug 06 '26 05:08 betaHi