Skip to content

Does Bedrock model inference call the apply guardrail API?

0

At my org we have an API that calls a Bedrock model with an associated guardrail. We also want to log results in s3. Before we log this data we have to use the Apply Guardrail API to mask any PII in the model response. Note, we can't mask the model response within the intial model inference filtering, hence the need to apply the guardrail afterwards.

I'm currently looking at our Bedrock costs and noticed nearly all of the cost is through the Apply Guardrail API calls. From AWS documentation I understand when call Bedrock model inference, guardrails are applied for processing the request and response, so if request is blocked you just pay for the intial request filter. If the model's response is blocked you pay for the processing performed by the model, the request filter and the response filter. For a 200 response, you are are charged for the guardrail filtering the request and response, as well as the model inference.

In my use case we are then also charged when the apply guardrail api is called to mask the results. When I view the cost explorer and filter by API operation, only model inference and apply guardrail calls are found.

Can someone confirm that using guardrails via model inference also calls the apply guardrail API? Our chaeges are currently ~$1 for inference and ~$22 for apply guardrail calls.

1 Answer
0

When you use guardrails with Amazon Bedrock model inference (via InvokeModel, InvokeModelWithResponseStream, Converse, or ConverseStream operations), the guardrail evaluation happens automatically as part of the inference process. This is different from explicitly calling the ApplyGuardrail API.

During model inference with guardrails:

  1. The input is evaluated against configured guardrail policies
  2. If the input passes, the model generates a response
  3. The model response is then evaluated against the guardrail policies
  4. The final response is returned based on guardrail evaluation results

The ApplyGuardrail API is a separate service that allows you to assess text against your guardrails without invoking foundation models. It's designed for use cases where you want to validate content independently from model inference, such as:

  • Content validation before processing
  • Flexible deployment anywhere in your application flow
  • Evaluating text without calling a foundation model

Based on your description, you're making two separate calls:

  1. Model inference with guardrails (which includes guardrail evaluation)
  2. An additional ApplyGuardrail API call to mask PII in the response before logging

This explains why you're seeing charges for both model inference and ApplyGuardrail operations. The second ApplyGuardrail call is not automatically part of model inference - it's an additional API call you're making specifically to mask PII before storing the data.

If your ApplyGuardrail costs are significantly higher than your inference costs, you might want to review your implementation to see if there are opportunities to optimize how and when you're calling the ApplyGuardrail API.
Sources
How Amazon Bedrock Guardrails works - Amazon Bedrock
Use the ApplyGuardrail API in your application - Amazon Bedrock
ApplyGuardrail - Amazon Bedrock

answered a year ago

AWS
EXPERT

reviewed a year ago

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.