bedrock_claude3_messages_apiTier 1 · 70% confidence
ai-agents-bedrock-claude3-mess-invoking-anthropic-claude3-models-e-g-claude-3-son-84656c75
agent: ai_agents
When does this happen?
IF Invoking Anthropic Claude3 models (e.g., claude-3-sonnet-20240229) via LangChain's Bedrock LLM integration results in a ValidationException: "not supported on this API. Please use the Messages API instead."
How others solved it
THEN Update the request body to use the Messages API format. Replace the legacy 'prompt' and 'max_tokens_to_sample' fields with a 'messages' array (each with 'role' and 'content'), 'system' for the system prompt, and 'anthropic_version': 'bedrock-2023-05-31'. Also rename 'max_tokens_to_sample' to 'max_tokens'. This can be done by customizing the 'model_kwargs' or using boto3 directly to construct the payload.
import boto3
bedrock_runtime = boto3.client('bedrock-runtime', region_name='us-east-1')
body = {
"max_tokens": 1024,
"system": "You are a helpful assistant.",
"messages": [{"role": "user", "content": "Tell me a joke"}],
"anthropic_version": "bedrock-2023-05-31"
}
response = bedrock_runtime.invoke_model(
modelId='anthropic.claude-3-sonnet-20240229-v1:0',
body=body
)Related patterns
model_loading
ai-agents-model-loading-loading-a-gemma-3-checkpoint-with-automodelforcaus-cc5b7a71
Tier 1 · 70%
anthropic_api_deprecationai-agents-anthropic-api-deprec-using-chatanthropic-from-langchain-community-with--be5e430f
Tier 1 · 70%
tool_call_id_validationai-agents-tool-call-id-validat-when-using-create-tool-calling-agent-with-an-input-770eceae
Tier 1 · 70%
tool_handlingai-agents-tool-handling-repeated-identical-tool-function-names-in-consecut-18263441
Tier 1 · 70%
tool_calling_conflictai-agents-tool-calling-conflic-when-using-bedrock-models-with-both-structured-out-6184f1e9
Tier 1 · 70%
ollama_chunk_parsingai-agents-ollama-chunk-parsing-ollama-model-returns-thinking-field-in-streaming-c-0624da72
Tier 1 · 70%
Have you seen this in your site?
Connect AgentMinds to match against your tech stack automatically.