fix: drop assistant prefill for Claude Sonnet 5.5

Closed
SC
1mo ago
+171-0

Fixes #3064

What

global.anthropic.claude-sonnet-5-5 returns 400 "This model does not support assistant message prefill. The conversation must end with a user message." A trailing text-only assistant message is now removed before the request is sent, on both the native /v1/messages and the translated paths, with a warning log. A trailing assistant turn carrying a tool call is not a prefill and is kept; a conversation that would end up empty is left alone.

Scoped to Sonnet 5.5 (rejectsAssistantPrefill), the only model confirmed to reject prefill; extend the regex as others are verified.

The reasoning_effort + function tools part of the #3064 title is the GPT case handled in the #3065 PR.

Tests

Unit tests for the helper plus native and translated forward tests. Backend src/routing: 164 suites, 4631 tests pass; tsc and eslint clean.

🤖 Generated with Claude Code


Summary by cubic

Fixes #3064: Claude Sonnet 5.5 rejects conversations that end with an assistant message. This change strips trailing text-only assistant messages before sending on both the native /v1/messages and translated paths, and logs a warning when it drops one.

  • Only claude-sonnet-5-5 model names (plain, us., global., and anthropic/ forms) match rejectsAssistantPrefill; extend the regex as other models are confirmed to reject prefill.
  • A trailing assistant turn carrying a tool call is a real turn and is kept, and a conversation that would end up empty is left untouched rather than left with a still-rejected trailing message.