AWS Bedrock pricing
PREREQUISITES
Python 3.8+AWS account with Bedrock accessAWS credentials configured (e.g., ~/.aws/credentials)pip install boto3
Setup
Install the boto3 library and configure your AWS credentials to access AWS Bedrock. Ensure your AWS user has permissions for bedrock-runtime API calls.
pip install boto3 Step by step
Use the boto3 bedrock-runtime client to invoke a Bedrock model and monitor token usage for pricing estimation. Pricing is based on the total tokens processed (input + output) multiplied by the model's per-1,000-token rate.
import boto3
import json
import os
# Initialize Bedrock client
client = boto3.client('bedrock-runtime', region_name='us-east-1')
# Example: invoke Claude 3.5 Sonnet model
model_id = 'anthropic.claude-3-5-sonnet-20241022-v2:0'
messages = [
{"role": "user", "content": [{"type": "text", "text": "Hello, what is AWS Bedrock pricing?"}]}
]
response = client.converse(
modelId=model_id,
messages=messages
)
# Extract response text
output_text = response['output']['message']['content'][0]['text']
print("Model response:", output_text)
# Pricing info (example rates, check AWS for current prices)
# Claude 3.5 Sonnet: $0.003 per 1,000 tokens
# To estimate cost:
# total_tokens = input_tokens + output_tokens
# cost = (total_tokens / 1000) * 0.003
# Note: AWS Bedrock pricing varies by model and region. Always verify current pricing at AWS official site. Model response: AWS Bedrock pricing depends on the model and tokens processed. You pay per 1,000 tokens.
Common variations
You can use different foundation models on AWS Bedrock such as amazon.titan-text-express-v1 or meta.llama3-1-70b-instruct-v1:0. Pricing varies accordingly. For asynchronous or streaming calls, use AWS SDK features or AWS Lambda integrations. Always check the latest pricing on the AWS Bedrock pricing page.
| Model | Example Price per 1,000 tokens (USD) |
|---|---|
| anthropic.claude-3-5-sonnet-20241022-v2:0 | $0.003 |
| amazon.titan-text-express-v1 | $0.0015 |
| meta.llama3-1-70b-instruct-v1:0 | $0.004 |
Troubleshooting
- If you receive
AccessDeniedException, verify your AWS IAM permissions include Bedrock access. - If you see
ThrottlingException, reduce request rate or request a quota increase. - For unexpected costs, monitor token usage carefully and use AWS Cost Explorer to track Bedrock charges.
Key Takeaways
- AWS Bedrock pricing is token-based and varies by foundation model.
- Use the boto3 bedrock-runtime client to invoke models and track usage.
- Always verify current pricing on the official AWS Bedrock pricing page.
- Proper IAM permissions are required to access Bedrock APIs.
- Monitor token usage to control and estimate your costs effectively.