Module 2 of 11 · AWS Bedrock — Build with Foundation Models · Intermediate

Available Models & Selection

Duration: 50 min

Bedrock provides access to foundation models from multiple providers. Each model has different strengths, speeds, and costs. This module covers the available models, their capabilities, and how to choose the right one for your use case.

Model Providers & Families

Anthropic Claude

Claude is a family of large language models known for safety, reasoning, and instruction-following.

Claude 3 Family:

import boto3
import json

client = boto3.client('bedrock-runtime', region_name='us-east-1')

# Using Claude 3 Sonnet
response = client.invoke_model(
    modelId='anthropic.claude-3-sonnet-20240229-v1:0',
    body=json.dumps({
        "anthropic_version": "bedrock-2023-06-01",
        "max_tokens": 1024,
        "messages": [
            {"role": "user", "content": "Explain quantum computing"}
        ]
    })
)

print(json.loads(response['body'].read())['content'][0]['text'])

Meta Llama

Open-source models optimized for speed and cost.

Llama 2 & Llama 3:

# Using Llama 3 70B
response = client.invoke_model(
    modelId='meta.llama3-70b-instruct-v1:0',
    body=json.dumps({
        "prompt": "What is machine learning?",
        "max_gen_len": 512,
        "temperature": 0.7,
        "top_p": 0.9
    })
)

result = json.loads(response['body'].read())
print(result['generation'])

Mistral AI

Fast, efficient models with strong performance on reasoning tasks.

Mistral Models:

# Using Mistral Large
response = client.invoke_model(
    modelId='mistral.mistral-large-2402-v1:0',
    body=json.dumps({
        "prompt": "Explain RAG systems",
        "max_tokens": 512,
        "temperature": 0.7
    })
)

result = json.loads(response['body'].read())
print(result['outputs'][0]['text'])

Amazon Titan

AWS-native models optimized for Bedrock integration.

Titan Models:

# Using Titan Text Express
response = client.invoke_model(
    modelId='amazon.titan-text-express-v1:0',
    body=json.dumps({
        "inputText": "Summarize AWS Bedrock",
        "textGenerationConfig": {
            "maxTokenCount": 512,
            "temperature": 0.7,
            "topP": 0.9
        }
    })
)

result = json.loads(response['body'].read())
print(result['results'][0]['outputText'])

Stability AI

Image generation and manipulation models.

Stable Diffusion:

import base64

# Generate an image
response = client.invoke_model(
    modelId='stability.stable-diffusion-xl-v1:0',
    body=json.dumps({
        "text_prompts": [
            {"text": "A futuristic AI assistant", "weight": 1.0}
        ],
        "cfg_scale": 10,
        "steps": 50,
        "seed": 0
    })
)

result = json.loads(response['body'].read())
image_data = base64.b64decode(result['artifacts'][0]['base64'])
with open('generated_image.png', 'wb') as f:
    f.write(image_data)

Model Comparison Matrix

Model Speed Cost Reasoning Code Creativity
Claude 3 Opus Slow High ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐ ⭐⭐⭐⭐
Claude 3 Sonnet Medium Medium ⭐⭐⭐⭐ ⭐⭐⭐⭐ ⭐⭐⭐⭐
Claude 3 Haiku Fast Low ⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐
Llama 3 70B Medium Low ⭐⭐⭐⭐ ⭐⭐⭐⭐ ⭐⭐⭐
Mistral Large Medium Low ⭐⭐⭐⭐ ⭐⭐⭐⭐ ⭐⭐⭐
Titan Text Express Fast Low ⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐

How to Choose a Model

For customer support chatbots:

For complex reasoning & analysis:

For code generation:

For high-volume, cost-sensitive tasks:

For image generation:

Listing Available Models

# List all available models
aws bedrock list-foundation-models --region us-east-1

# Filter by provider
aws bedrock list-foundation-models \
  --by-provider anthropic \
  --region us-east-1

# Filter by capability
aws bedrock list-foundation-models \
  --by-customization-type FINE_TUNING \
  --region us-east-1

Model IDs Reference

{
  "claude": {
    "opus": "anthropic.claude-3-opus-20240229-v1:0",
    "sonnet": "anthropic.claude-3-sonnet-20240229-v1:0",
    "haiku": "anthropic.claude-3-haiku-20240307-v1:0"
  },
  "llama": {
    "llama3_70b": "meta.llama3-70b-instruct-v1:0",
    "llama3_8b": "meta.llama3-8b-instruct-v1:0",
    "llama2_70b": "meta.llama2-70b-chat-v1:0"
  },
  "mistral": {
    "large": "mistral.mistral-large-2402-v1:0",
    "7b": "mistral.mistral-7b-instruct-v0:2"
  },
  "titan": {
    "text_premier": "amazon.titan-text-premier-v1:0",
    "text_express": "amazon.titan-text-express-v1:0",
    "embeddings": "amazon.titan-embed-text-v2:0"
  }
}

❓ Which Claude 3 model offers the best balance of speed and capability?

❓ Which model family is best for cost-sensitive, high-volume tasks?

❓ What is Titan Embeddings used for?

❓ Which model would you choose for complex multi-step reasoning?

← Previous Continue interactively → Next →

Related Courses