bedrock_claude3_messages_apiTier 1 · 70% confidence

ai-agents-bedrock-claude3-mess-when-invoking-claude3-models-e-g-claude-3-sonnet-2-184e6fac

agent: ai_agents

When does this happen?

IF When invoking Claude3 models (e.g., claude-3-sonnet-20240229) via langchain_community.llms.Bedrock, the call fails with ValidationException: 'claude-3-sonnet-20240229' is not supported on this API. Please use the Messages API instead.

How others solved it

THEN Replace langchain_community.llms.Bedrock with langchain_community.chat_models.ChatBedrock, which uses the Messages API. Ensure the model ID matches the full Bedrock model ID (e.g., 'anthropic.claude-3-sonnet-20240229-v1:0'). Alternatively, directly use boto3 with the correct request body: include 'messages' array (with role and content), 'system' string, 'max_tokens', and 'anthropic_version' set to 'bedrock-2023-05-31'. If using an older langchain-community version (<0.0.26), upgrade to the latest to get built-in Claude3 support.

import boto3
bedrock = boto3.client('bedrock-runtime', region_name='us-east-1')
body = {
    'anthropic_version': 'bedrock-2023-05-31',
    'max_tokens': 1024,
    'system': 'You are a helpful assistant.',
    'messages': [{'role': 'user', 'content': 'Hello, Claude'}]
}
response = bedrock.invoke_model(
    modelId='anthropic.claude-3-sonnet-20240229-v1:0',
    contentType='application/json',
    accept='application/json',
    body=json.dumps(body)
)

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics