@@ -399,6 +399,45 @@ describe("AnthropicHandler", () => {
399399 expect ( endChunk ) . toBeDefined ( )
400400 } )
401401
402+ it ( "should strip reasoning_details and reasoning_content from messages before sending to API" , async ( ) => {
403+ setupStreamTextMock ( [ { type : "text-delta" , text : "test" } ] )
404+
405+ // Simulate messages with extra legacy fields that survive JSON deserialization
406+ const messagesWithExtraFields = [
407+ {
408+ role : "user" ,
409+ content : [ { type : "text" as const , text : "Hello" } ] ,
410+ } ,
411+ {
412+ role : "assistant" ,
413+ content : [ { type : "text" as const , text : "Hi" } ] ,
414+ reasoning_details : [ { type : "thinking" , thinking : "some reasoning" } ] ,
415+ reasoning_content : "some reasoning content" ,
416+ } ,
417+ {
418+ role : "user" ,
419+ content : [ { type : "text" as const , text : "Follow up" } ] ,
420+ } ,
421+ ] as any
422+
423+ const stream = handler . createMessage ( systemPrompt , messagesWithExtraFields )
424+
425+ for await ( const _chunk of stream ) {
426+ // Consume stream
427+ }
428+
429+ // Verify streamText was called exactly once
430+ expect ( mockStreamText ) . toHaveBeenCalledTimes ( 1 )
431+ const callArgs = mockStreamText . mock . calls [ 0 ] ! [ 0 ]
432+ for ( const msg of callArgs . messages ) {
433+ expect ( msg ) . not . toHaveProperty ( "reasoning_details" )
434+ expect ( msg ) . not . toHaveProperty ( "reasoning_content" )
435+ }
436+ // Verify the rest of the message is preserved
437+ expect ( callArgs . messages [ 1 ] . role ) . toBe ( "assistant" )
438+ expect ( callArgs . messages [ 1 ] . content ) . toEqual ( [ { type : "text" , text : "Hi" } ] )
439+ } )
440+
402441 it ( "should pass system prompt via system param when no systemProviderOptions" , async ( ) => {
403442 setupStreamTextMock ( [ { type : "text-delta" , text : "test" } ] )
404443
0 commit comments