Bedrock - Use of TAGS for Billing

0

According to what we read in documentation, Bedrock does support the use of tags in API calls, similar to other AWS services. We use one tag, CustID, to tag various services so that we can bill accordingly each month for each service to the correct project and want to do this with Bedrock. Using the nodejs SDK we have tried various combinations of syntax in the API call but we are not seeing Bedrock services tagged like we do for EC2 or S3. Does Bedrock actually support tagging? If it does does anyone have a code sample they could share? Our current code for this is:

// Function to invoke Claude model const invokeClaude = async (context, query) => { const params = { modelId: 'anthropic.claude-3-sonnet-20240229-v1:0', contentType: "application/json", accept: "application/json", Tags: [ {"CustID": "dev010"}], body: JSON.stringify({ // Convert the body to a JSON string anthropic_version: 'bedrock-2023-05-31', max_tokens: 246, system: Please answer the question based solely on the provided context: "${context}" Also, list the sources used. If you cannot answer, reply with "I cannot answer", messages: [ { role: 'user', content: [ { type: 'text', text: the question is "${query}". } ] } ] }) };

asked 4 months ago673 views
1 Answer
1

Yes, Amazon Bedrock does support tagging, but there are a few important points to consider regarding your current approach:

  1. Tagging in Bedrock is supported, but it's not applied directly in the model invocation call. Instead, you tag the Bedrock resources themselves.

  2. The TagResource operation is used to add tags to Bedrock resources. This is a separate API call from the model invocation.

  3. Tags are applied to resources like agents, custom models, knowledge bases, etc., not to individual API calls.

  4. For billing purposes, you would typically tag the Bedrock resources when you create or manage them, not during each invocation.

To tag a Bedrock resource using the Node.js SDK, you would use something like this:

import { BedrockClient, TagResourceCommand } from "@aws-sdk/client-bedrock";

const client = new BedrockClient({ region: "YOUR_REGION" });

const params = {
  resourceArn: "arn:aws:bedrock:REGION:ACCOUNT_ID:RESOURCE_TYPE/RESOURCE_ID",
  tags: {
    CustID: "dev010"
  }
};

try {
  const command = new TagResourceCommand(params);
  const response = await client.send(command);
  console.log("Resource tagged successfully");
} catch (error) {
  console.error("Error tagging resource:", error);
}

Replace the resourceArn with the actual ARN of the Bedrock resource you want to tag.

For your model invocation, you don't need to include the Tags parameter. Your invokeModel function should work without the Tags line, focusing only on the model invocation parameters.

To see the tags applied to your Bedrock resources and verify they're being used for billing, you can use the AWS Cost Explorer or generate a cost allocation report in the AWS Billing Console.

Edit to add:

Specifically for tagging non-agentic invocation of base models, you may want to create and tag an application inference profile. If these tag-based cost allocation capabilities aren't appropriate for your use-case, you could also explore this custom cost tracking solution based on CloudWatch.

Sources
Tagging Amazon Bedrock resources - Amazon Bedrock
TagResource - Amazon Bedrock

profile picture
answered 4 months ago
AWS
EXPERT
reviewed 4 months ago
AWS
EXPERT
revised 4 months ago
  • Thanks we will starting looking at this approach; question where do you locate the ARN for the LLM model we are using?

  • I have that now via AWS CLi

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions