fix: streamText fails with 400 Invalid prompt due to invalid ModelMessage structure in convertFromAnthropicMessages

Open Beginner friendly
#22 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
typescript
Domain
api

Research direction

Start by locating convertFromAnthropicMessages and inspect how tool calls and Anthropic tool_result blocks are converted before the result is passed to streamText. Reproduce the proxy request described in the issue, then verify the returned array is explicitly typed as ModelMessage[] and that streamText no longer reports an invalid prompt.

Written by the indexing model from the issue text.

Description

Description

When proxying messages through streamText, the AI SDK throws a 400 Bad Request validation error:

API Error: 400 {"type":"error","error":"Invalid prompt: The messages must be a ModelMessage[]. If you have passed a UIMessage[], you can use convertToModelMessages to convert them."}

Cause

convertFromAnthropicMessages outputs message objects that do not fully conform to Vercel AI SDK's strict ModelMessage[] schema:

  1. Tool calls were passing arguments under input instead of the expected args key required by ToolCallPart.
  2. Anthropic tool_result content blocks were not mapped to proper tool-result objects in the returned messages.
  3. The function lacked explicit return typing (: ModelMessage[]), allowing non-compliant object shapes to pass TypeScript checks.

Expected Behavior

convertFromAnthropicMessages should convert incoming Anthropic message arrays into a strictly compliant ModelMessage[] array that passes streamText validation seamlessly.

Reproduction Steps

  1. Route a request containing a standard user message or tool call through the proxy.
  2. Pass the result of convertFromAnthropicMessages(body.messages) to streamText({ messages: ... }).
  3. Notice the 400 Invalid prompt validation error returned by the AI SDK.
Dominant language
TypeScript
Stars
291
Forks
42
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from coder/anyclaude

All issues in coder/anyclaude

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.