我想在调用 Amazon Bedrock 按需模型时添加成本分配标签。
解决方法
为应用程序推理配置文件分配标签,然后将该配置文件链接到按需模型。
**注意:**无法为按需模型分配标签。
创建应用程序推理配置文件
使用 CreateInferenceProfile。以下示例创建了一个应用程序推理配置文件,该配置文件链接到 amazon.nova-pro-v1:0,标签为 "key": "CostAllocateTag","value": "project123"。
示例:
aws bedrock create-inference-profile --region 'us-east-1' \
--inference-profile-name 'profile-project123' \
--description 'profile-project123' \
--model-source '{"copyFrom": "arn:aws:bedrock:us-east-1::foundation-model/amazon.nova-pro-v1:0"}' \
--tags '[{"key": "CostAllocateTag","value": "project123"}]'
输出示例:
{
"inferenceProfileArn": "arn:aws:bedrock:us-east-1:AccountId:application-inference-profile/y1pcpudi2mb7",
"status": "ACTIVE"
}
激活成本分配标签
要激活成本分配标签,请使用 AWS 账单与成本管理控制台。
**注意:**这些标签将在 24 小时内显示在成本分配标签页面上。
调用模型
要调用模型,请使用应用程序推理配置文件。对于模型 ID,请指定应用程序推理配置文件的 ARN,而不是按需模型 ID。
示例:
aws bedrock-runtime converse --region 'us-east-1' \
--model-id 'arn:aws:bedrock:us-east-1:AccountId:application-inference-profile/y1pcpudi2mb7' \
--messages '[{"role": "user", "content": [{"text": "Hello"}]}]'
输出示例:
{
"output": {
"message": {
"role": "assistant",
"content": [
{
"text": "Hello! It's nice to have you here. I'm here to help with whatever you might need. Whether you have a question, need assistance with a topic, or just want to chat, feel free to ask. What can I assist you with today?"
}
]
}
},
"stopReason": "end_turn",
"usage": {
"inputTokens": 1,
"outputTokens": 54,
"totalTokens": 55
},
"metrics": {
"latencyMs": 889
}
}