To specify which foundation model to use in a request to Amazon Bedrock, you include the modelId
parameter in your API call. Each model in Bedrock has a unique identifier (e.g., amazon.titan-text-express-v1
or anthropic.claude-v2
), which determines the underlying model used for processing. When sending a request—whether through the AWS SDK, CLI, or REST API—you explicitly set this parameter to select the desired model. For example, in the InvokeModel
API, you’d structure the request body or SDK method call to include the modelId
alongside other parameters like input text and inference configurations.
To illustrate, here’s a simplified example using the AWS SDK for Python (Boto3):
import boto3
bedrock = boto3.client(service_name='bedrock-runtime')
response = bedrock.invoke_model(
modelId='anthropic.claude-v2',
body=json.dumps({
"prompt": "Explain how to choose a model in Bedrock.",
"max_tokens_to_sample": 300
})
)
In this snippet, modelId
is set to anthropic.claude-v2
, which selects Claude v2. Similarly, using amazon.titan-text-express-v1
would invoke Amazon’s Titan Text Express model. The structure of the request body (e.g., prompt
vs. inputText
) may vary slightly between models, so you must follow the input format required by the selected model. The Bedrock documentation provides exact specifications for each model’s input parameters.
When choosing a model, ensure it’s available in your AWS region and aligns with your use case. For instance, Titan Text Express is optimized for general text generation, while Claude v2 supports longer contexts. You can list available models in your region using the ListFoundationModels
API. Always verify the modelId
spelling and version (e.g., v1
vs. v2
), as incorrect IDs will result in errors. Additionally, some models may require specific permissions or have usage limits, so review Bedrock’s service quotas and IAM policies to avoid interruptions.
Zilliz Cloud is a managed vector database built on Milvus perfect for building GenAI applications.
Try FreeLike the article? Spread the word