Fixed Anthropic Messages API code samples and switched model-card OpenAI-SDK samples to bedrock-runtime: Fixed the Anthropic Messages API Python sample on the Overview page, which previously used anthropic.Anthropic() with no base URL and failed with a val

Anthropic Messages API for AWS Bedrock
The Anthropic Messages API provides native access to Claude models using the Anthropic request and response format. Use the Messages API on the bedrock-runtime or bedrock-mantle endpoints for flexibility in authentication and integration.
Endpoints
- bedrock-runtime:
https://bedrock-runtime.{region}.amazonaws.com/anthropic- Recommended for new applications with AWS SDK integrations, IAM authentication, and invocation logging. - bedrock-mantle:
https://bedrock-mantle.{region}.api.aws/anthropic/v1/messages- Supports Amazon Bedrock API key authentication and Workspaces.
Prerequisites
- Model access: Request access to Claude models in the Amazon Bedrock console.
- Authentication:
- bedrock-runtime: Use AWS SigV4 credentials through the AWS SDK or a short-term Bedrock bearer token.
- bedrock-mantle: Use an Amazon Bedrock API key or AWS SigV4 credentials.
Basic Request
To send a message to a Claude model:
- Set the API version header:
- bedrock-runtime: Include
"anthropic_version": "bedrock-2023-05-31"in the request body. - bedrock-mantle: Include
anthropic-version: 2023-06-01as an HTTP header.
- bedrock-runtime: Include
- Use the appropriate method to send the message:
- Python (Anthropic SDK): Use the Anthropic SDK with a short-term Bedrock bearer token.
- Python (boto3): Use the AWS SDK to invoke the model.
- AWS CLI: Use the
invoke-modelcommand with the necessary parameters. - curl: Send the request with AWS SigV4 signing.
Stream Responses
To receive response tokens incrementally:
- Use the streaming methods provided by the Anthropic SDK or boto3.
- For
curl, include thestream: trueparameter in the request body.
Supported Features
- System prompts, multi-turn conversations, tool use, vision, and prompt caching.
Count Tokens
Use the count_tokens path on the bedrock-mantle endpoint to count input tokens before inference.
Source: AWS release notes
If you need further guidance on AWS, our experts are available at AWS@westloop.io. You may also reach us by submitting the Contact Us form.



