Skip to content

Conversation

thewh1teagle
Copy link

@thewh1teagle thewh1teagle commented Aug 26, 2025

Background

To be able to convert messages type to acceptable type of Anthropic SDKs

Summary

export convertToAnthropicMessagesPrompt from @ai-sdk/anthropic

Manual Verification

Tasks

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • Formatting issues have been fixed (run pnpm prettier-fix in the project root)
  • I have reviewed this pull request (self-review)

Related Issues

closes #7526
closes #7522

@abhi-slash-git
Copy link

PR looks good, should we get this merged and released?

Copy link
Collaborator

@gr2m gr2m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is a new feature, can you add docs for it? Best place is probably a new section in https://github.com/vercel/ai/blob/ae859ceb7aacd17cd72f6d32ed335babf3fc5c3b/content/providers/01-ai-sdk-providers/05-anthropic.mdx. You can add the example from #7526 or something similar?

@gr2m gr2m self-assigned this Sep 12, 2025
@thewh1teagle
Copy link
Author

@gr2m thanks for the review! I documented the new feature and fixed the prettier CI check.

Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
@gr2m gr2m requested a review from nicoalbanese September 12, 2025 23:20

console.log(`Estimated tokens: ${tokenCount.input_tokens}`);
```

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is in the right place, it's in the middle of the Language Models section:
https://ai-sdk.dev/providers/ai-sdk-providers/anthropic#language-models

Maybe add a whole new section to the bottom, below ## Code Execution? I requested a review by @nicoalbanese to help with the docs

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gr2m
I moved it after ## Code Execution
I would love to enhance it more if needed. is there a way to run the docs website locally?

@gr2m gr2m changed the title Feat/convert ai message to anthropic message feat(provider/anthropic): export convertToAnthropicMessagesPrompt Sep 12, 2025
Copy link
Collaborator

@lgrammel lgrammel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the assumption that you can export the convertToAnthropicMessagesPrompt and pass in model messages is wrong.

have you tested this to check if it works at all? or is the intention that is should be used with LanguageModelV2Prompt?

@gr2m
Copy link
Collaborator

gr2m commented Sep 14, 2025

end-to-end meaning where does messages come from? The example you added to the docs happens to work, but the original issue asks to pass through convertToModelMessages(uiImessages), and that is incompatible

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[AI SDK v5] Add ability to convert ModelMessage to Anthropic model message
4 participants