fix: streamText fails with 400 Invalid prompt due to invalid ModelMessage structure in convertFromAnthropicMessages
- Dominant language
- TypeScript
- Stars
- 292
- Forks
- 42
- PR merge metrics
- No merged PRs in 30d
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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.