fix: streamText fails with 400 Invalid prompt due to invalid ModelMessage structure in convertFromAnthropicMessages
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:
- Tool calls were passing arguments under
inputinstead of the expectedargskey required byToolCallPart. - Anthropic
tool_resultcontent blocks were not mapped to propertool-resultobjects in the returned messages. - 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
- Route a request containing a standard user message or tool call through the proxy.
- Pass the result of
convertFromAnthropicMessages(body.messages)tostreamText({ messages: ... }). - Notice the
400 Invalid promptvalidation 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from coder/anyclaude
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
-
Ollama support Open
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Added Ollama Support Open
Difficulty 3/5 1-2 days Newbie friendliness 35/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
danielmiessler/LifeOS#2218 ·