You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I searched the LangChain.js documentation with the integrated search.
I used the GitHub search to find a similar question and didn't find it.
I am sure that this is a bug in LangChain.js rather than my code.
The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
Example Code
constattachmentsMessage=newHumanMessage({content: [{type: 'text',text: 'Here are the attachments from the email:'},{type: 'image',source: {type: 'base64',media_type: attachment.content_type,data: attachment.base64Data,},},],});
Sending the following message results in an Unsupported message content format error.
Error Message and Stack Trace (if applicable)
No response
Description
According to the Anthropic's documentation, sending images to the model is supported either by Base64, or a URL in the following ways:
base64:
constmessage=awaitanthropic.messages.create({model: "claude-3-7-sonnet-20250219",max_tokens: 1024,messages: [{role: "user",content: [{type: "image",source: {type: "base64",media_type: "image/jpeg",data: imageData,// Base64-encoded image data as string}},{type: "text",text: "Describe this image."}]}]});
Hey, @guypy! I'm here to help you out with any bugs or questions you have while waiting for a human maintainer. Let's see what's going on with the issue you've raised.
The Unsupported message content format error in the @langchain/anthropic package occurs because it currently only supports base64-encoded images. The _formatImage function in the package checks for base64-encoded images using a regular expression, and if the image does not match this format, it throws an error [1][2].
To resolve this issue, ensure that your image data is correctly formatted as a base64-encoded string. If you want to use URL formats as supported by Anthropic's documentation, the package would need to be updated to handle both base64 and URL formats. This would involve modifying the _formatImage function and related logic to accommodate URLs as well.
Checked other resources
Example Code
Sending the following message results in an
Unsupported message content format
error.Error Message and Stack Trace (if applicable)
No response
Description
According to the Anthropic's documentation, sending images to the model is supported either by Base64, or a URL in the following ways:
base64:
URL:
However, the code in the @langchain/anthropic package does not follow those examples, it expects an
image_url
type (@see https://github.com/langchain-ai/langchainjs/blob/main/libs/langchain-anthropic/src/utils/message_inputs.ts#L125-L136) and therefore throws anUnsupported message content format
error.Passing an
image_url
type, passes the content to_formatImage
which returns a format that does not match Anthropic's docs.System Info
The text was updated successfully, but these errors were encountered: