I want to add cost allocation tags when I invoke Amazon Bedrock on-demand models.
Resolution
Assign tags to an application inference profile, and then link the profile to the on-demand model.
Note: You can't assign tags to on-demand models.
Create an application inference profile
Use the CreateInferenceProfile. The following example creates an application inference profile that's linked to amazon.nova-pro-v1:0 with the tag "key": "CostAllocateTag","value": "project123".
Example:
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"}]'
Example output:
{
"inferenceProfileArn": "arn:aws:bedrock:us-east-1:AccountId:application-inference-profile/y1pcpudi2mb7",
"status": "ACTIVE"
}
Activate a cost allocation tag
To activate a cost allocation tag, use the AWS Billing and Cost Management console.
Note: The tags appear within 24 hours on the cost allocation tags page.
Invoke the model
To invoke the model, use the application inference profile. For the model ID, specify the ARN of the application inference profile instead of the on-demand model ID.
Example:
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"}]}]'
Example output:
{
"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
}
}