

# Register a third-party guardrail provider

To use a third-party provider, store your provider API key in AgentCore Identity, give the gateway’s execution role permission to read it, and register the provider on your policy engine.

**Topics**
+ [Prerequisites](#policy-3p-setup-prerequisites)
+ [Step 1: Store the provider API key](#policy-3p-setup-store-key)
+ [Step 2: Let the gateway read the key](#policy-3p-setup-permissions)
+ [Step 3: Register the provider on the policy engine](#policy-3p-setup-register)
+ [Step 4: Check the configuration](#policy-3p-setup-verify)
+ [Configuration rules](#policy-3p-setup-rules)

## Prerequisites
<a name="policy-3p-setup-prerequisites"></a>
+ An account with the provider, and an API key for the provider’s guardrail API. To get a key, follow the provider’s documentation. For links, see [Supported providers](policy-third-party-guardrails.md#policy-3p-supported-providers).
+ A policy engine attached to a gateway. For more information, see [Create a policy engine](policy-create-engine.md).

## Step 1: Store the provider API key
<a name="policy-3p-setup-store-key"></a>

Store the key as an API key credential provider in AgentCore Identity. For console steps, see [Add API key](identity-add-api-key.md).

**Example**  

```bash
aws bedrock-agentcore-control create-api-key-credential-provider \
  --name my-guardrail-provider-key \
  --api-key "<your provider API key>"
```

```python
import boto3

client = boto3.client("bedrock-agentcore-control")

response = client.create_api_key_credential_provider(
    name="my-guardrail-provider-key",
    apiKey="<your provider API key>",
)
print(response["credentialProviderArn"])
```

Keep the `credentialProviderArn` from the response. You use it when you register the provider.

Store the credential that your provider uses to authenticate its guardrail API. For which credential to use, see the provider’s documentation.

If you store the key in your own AWS Secrets Manager secret instead (**Provide API key via Secrets Manager** in the console), tag the secret with `BedrockAgentCoreThirdPartyGuardrailsSecret` = `true`, so that the permissions in Step 2 let the gateway read it.

## Step 2: Let the gateway read the key
<a name="policy-3p-setup-permissions"></a>

Policy in AgentCore reads the API key with credentials derived from the gateway’s execution role, the same way it calls Amazon Bedrock Guardrails. Use the following permission policy for the gateway’s execution role. It includes the permissions to evaluate policies and Amazon Bedrock Guardrails checks, and the permissions for third-party providers.

**Important**  
Replace these placeholders:  
 {{us-east-1}} with the AWS Region
 {{123456789012}} with the AWS account ID
 {{<gateway-name>}} with the gateway name
 {{<policy-engine-id>}} with the policy engine ID

```json
{
  "Version": "2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "EvaluatePoliciesForGateway",
      "Effect": "Allow",
      "Action": [
        "bedrock-agentcore:AuthorizeAction",
        "bedrock-agentcore:PartiallyAuthorizeActions"
      ],
      "Resource": [
        "arn:aws:bedrock-agentcore:us-east-1:123456789012:gateway/<gateway-name>-*",
        "arn:aws:bedrock-agentcore:us-east-1:123456789012:policy-engine/<policy-engine-id>"
      ]
    },
    {
      "Sid": "GetPolicyEngineForValidation",
      "Effect": "Allow",
      "Action": [
        "bedrock-agentcore:GetPolicyEngine"
      ],
      "Resource": [
        "arn:aws:bedrock-agentcore:us-east-1:123456789012:policy-engine/<policy-engine-id>"
      ]
    },
    {
      "Sid": "EvaluatePoliciesGuardrailsForGateway",
      "Effect": "Allow",
      "Action": [
        "bedrock:InvokeGuardrailChecks"
      ],
      "Resource": "*"
    },
    {
      "Sid": "GetWorkloadAccessTokenForThirdPartyGuardrails",
      "Effect": "Allow",
      "Action": [
        "bedrock-agentcore:GetWorkloadAccessToken"
      ],
      "Resource": [
        "arn:aws:bedrock-agentcore:us-east-1:123456789012:workload-identity-directory/default",
        "arn:aws:bedrock-agentcore:us-east-1:123456789012:workload-identity-directory/default/workload-identity/*"
      ]
    },
    {
      "Sid": "GetResourceApiKeyForThirdPartyGuardrails",
      "Effect": "Allow",
      "Action": [
        "bedrock-agentcore:GetResourceApiKey"
      ],
      "Resource": [
        "arn:aws:bedrock-agentcore:us-east-1:123456789012:token-vault/default",
        "arn:aws:bedrock-agentcore:us-east-1:123456789012:token-vault/default/apikeycredentialprovider/*",
        "arn:aws:bedrock-agentcore:us-east-1:123456789012:workload-identity-directory/default",
        "arn:aws:bedrock-agentcore:us-east-1:123456789012:workload-identity-directory/default/workload-identity/*"
      ]
    },
    {
      "Sid": "GetManagedThirdPartyGuardrailApiKeySecrets",
      "Effect": "Allow",
      "Action": [
        "secretsmanager:GetSecretValue"
      ],
      "Resource": "arn:aws:secretsmanager:us-east-1:123456789012:secret:bedrock-agentcore-identity!default/apikey/*"
    },
    {
      "Sid": "GetTaggedExternalThirdPartyGuardrailApiKeySecrets",
      "Effect": "Allow",
      "Action": [
        "secretsmanager:GetSecretValue"
      ],
      "Resource": "arn:aws:secretsmanager:us-east-1:123456789012:secret:*",
      "Condition": {
        "StringEquals": {
          "secretsmanager:ResourceTag/BedrockAgentCoreThirdPartyGuardrailsSecret": "true"
        }
      }
    }
  ]
}
```

The statements do the following:
+  `EvaluatePoliciesForGateway` and `GetPolicyEngineForValidation` let the gateway evaluate the policies of its policy engine.
+  `EvaluatePoliciesGuardrailsForGateway` lets Policy in AgentCore call Amazon Bedrock Guardrails checks.
+  `GetWorkloadAccessTokenForThirdPartyGuardrails` and `GetResourceApiKeyForThirdPartyGuardrails` let Policy in AgentCore get the provider API key from AgentCore Identity.
+  `GetManagedThirdPartyGuardrailApiKeySecrets` lets it read API keys that AgentCore Identity stores for you.
+  `GetTaggedExternalThirdPartyGuardrailApiKeySecrets` lets it read API keys that you store in your own Secrets Manager secrets. It applies only to secrets tagged `BedrockAgentCoreThirdPartyGuardrailsSecret` = `true`. If you don’t use your own secrets, you can omit this statement.

For the trust policy and the other permissions of the execution role, see [AgentCore Gateway and Policy in AgentCore IAM Permissions](policy-permissions.md). If the role can’t read the key, every request that reaches a third-party check is denied.

### If the secret uses a customer managed key
<a name="policy-3p-setup-permissions-kms"></a>

If the Secrets Manager secret that holds the API key is encrypted with a customer managed AWS KMS key, the gateway’s execution role also needs permission to decrypt with that key, through Secrets Manager.

Add the following statement to the gateway’s execution role:

```json
{
  "Sid": "DecryptThirdPartyGuardrailApiKeySecrets",
  "Effect": "Allow",
  "Action": "kms:Decrypt",
  "Resource": "arn:aws:kms:us-east-1:123456789012:key/1234abcd-12ab-34cd-56ef-1234567890ab",
  "Condition": {
    "StringEquals": {
      "kms:ViaService": "secretsmanager.us-east-1.amazonaws.com"
    }
  }
}
```

The key policy must also allow the gateway’s execution role to use the key. Add a statement like the following to the key policy:

```json
{
  "Sid": "AllowGatewayExecutionRoleDecryptViaSecretsManager",
  "Effect": "Allow",
  "Principal": {
    "AWS": "arn:aws:iam::123456789012:role/my-gateway-execution-role"
  },
  "Action": "kms:Decrypt",
  "Resource": "*",
  "Condition": {
    "StringEquals": {
      "kms:ViaService": "secretsmanager.us-east-1.amazonaws.com"
    }
  }
}
```

This applies to your own secrets that use a customer managed key. To use a customer managed key on the AgentCore Identity token vault, see [Set customer managed key policy](kms-key-policy-configuration.md).

## Step 3: Register the provider on the policy engine
<a name="policy-3p-setup-register"></a>

To register a provider, add it to the engine’s `policyInformationProviderConfiguration` map. The key is the provider ID. For each provider’s ID, see [Supported providers](policy-third-party-guardrails.md#policy-3p-supported-providers). The value names the credential provider and, optionally, your provider URL.

 `credentialProvider`   
The ARN of the API key credential provider from Step 1, as `{"apiKey": {"arn": "…​"}}`.

 `url`   
Your provider URL. If you omit it, the provider’s default URL is used. Set it if your provider account uses a different Region or deployment. For the URL to use, see the provider’s documentation. The URL must use `https`, its host must be one of the provider’s allowed hosts, and it must not include a port. For each provider’s rule, see [Third-party guardrail reference](policy-third-party-guardrails-reference.md).

You can register providers on an existing engine, or when you create the engine. The two operations use different shapes for each entry:
+  `CreatePolicyEngine` takes `credentialProvider` and `url` directly in the entry. `url` is a string.
+  `UpdatePolicyEngine` wraps the fields in `providerConfiguration`, and `url` is an object, `{"optionalValue": "<URL>"}`. The wrapper lets an update change only the fields that you name.

**Example**  

1. Open the [AgentCore console](https://console.aws.amazon.com/bedrock-agentcore/home?region=us-east-1#), choose **Policy**, and then choose your policy engine.

1. In the **Guardrail providers** section, choose **Register guardrail provider**. The list already includes **Bedrock Guardrails (provided by default)**.  
![Policy engine details page showing the Guardrail providers section with Bedrock Guardrails provided by default and the Register guardrail provider button.](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/images/policy/3p-guardrail-providers-section.png)

1. For **Provider**, choose the provider.

1. (Optional) For **Detection endpoint**, enter your provider URL. Leave it blank to use the provider’s default URL. The URL must start with `https://`.

1. For **API key**, choose the API key credential provider that you created in Step 1. To create one now, choose **create new**.  
![Register guardrail provider page with the Provider, Detection endpoint, and API key fields.](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/images/policy/3p-register-guardrail-provider.png)

1. Choose **Register guardrail provider**.

   The provider appears in the **Guardrail providers** list with its endpoint and the authentication type **API key**.  
![Guardrail providers list showing Bedrock Guardrails provided by default and Check Point registered with endpoint https://api.lakera.ai and authentication type API key.](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/images/policy/3p-guardrail-providers-registered.png)
To register a provider on an existing engine:  

```bash
aws bedrock-agentcore-control update-policy-engine \
  --policy-engine-id my_policy_engine-a1b2c3d4e5 \
  --policy-information-provider-configuration '{
    "<ProviderId>": {
      "providerConfiguration": {
        "credentialProvider": {
          "apiKey": {
            "arn": "arn:aws:bedrock-agentcore:us-east-1:123456789012:token-vault/default/apikeycredentialprovider/my-guardrail-provider-key"
          }
        },
        "url": {"optionalValue": "https://<provider endpoint>"}
      }
    }
  }'
```
To register a provider when you create the engine:  

```bash
aws bedrock-agentcore-control create-policy-engine \
  --name my_policy_engine \
  --policy-information-provider-configuration '{
    "<ProviderId>": {
      "credentialProvider": {
        "apiKey": {
          "arn": "arn:aws:bedrock-agentcore:us-east-1:123456789012:token-vault/default/apikeycredentialprovider/my-guardrail-provider-key"
        }
      },
      "url": "https://<provider endpoint>"
    }
  }'
```

```python
import boto3

client = boto3.client("bedrock-agentcore-control")

ENGINE_ID = "my_policy_engine-a1b2c3d4e5"
KEY_ARN = ("arn:aws:bedrock-agentcore:us-east-1:123456789012:"
           "token-vault/default/apikeycredentialprovider/my-guardrail-provider-key")

client.update_policy_engine(
    policyEngineId=ENGINE_ID,
    policyInformationProviderConfiguration={
        "<ProviderId>": {
            "providerConfiguration": {
                "credentialProvider": {"apiKey": {"arn": KEY_ARN}},
                "url": {"optionalValue": "https://<provider endpoint>"},
            }
        }
    },
)
# UpdatePolicyEngine returns 202 - wait until the engine is ACTIVE again
client.get_waiter("policy_engine_active").wait(policyEngineId=ENGINE_ID)
```

An update changes only the providers and fields that you name. To register another provider, call `UpdatePolicyEngine` with that provider’s ID and a `credentialProvider`. To change the URL back to the provider’s default URL, send `"url": {}`.

### Remove a provider
<a name="policy-3p-setup-remove"></a>

To remove a provider from an engine, call `UpdatePolicyEngine` with an empty object for the provider ID:

```bash
aws bedrock-agentcore-control update-policy-engine \
  --policy-engine-id my_policy_engine-a1b2c3d4e5 \
  --policy-information-provider-configuration '{"<ProviderId>": {}}'
```

You can’t remove a provider while a policy of the engine calls its checks. Delete or update those policies first. Otherwise the request fails with a `ConflictException`. You can’t remove `BedrockGuardrails`.

### Verifying the API key
<a name="policy-3p-setup-key-check"></a>

When you register a provider, AgentCore verifies your API key by sending a short test request to the provider. If the provider rejects the key, can’t be reached, or the URL isn’t found, the registration fails. The engine status becomes `CREATE_FAILED` or `UPDATE_FAILED`, and `statusReasons` names the provider and the reason, for example:

```text
<ProviderId>: Invalid credentials for provider <ProviderId> (HTTP 401)
```

Fix the API key or URL and register the provider again.

## Step 4: Check the configuration
<a name="policy-3p-setup-verify"></a>

In the console, the **Guardrail providers** section of the policy engine lists each registered provider with its endpoint and authentication type. With the API, `GetPolicyEngine` returns each registered provider with its credential provider, URL, settings, and the checks it offers. `BedrockGuardrails` always appears in the list. It’s built in and managed by the service.

```bash
aws bedrock-agentcore-control get-policy-engine \
  --policy-engine-id my_policy_engine-a1b2c3d4e5 \
  --query 'policyInformationProviderConfiguration'
```

## Configuration rules
<a name="policy-3p-setup-rules"></a>
+ The URL must be an absolute `https` URL without a port, credentials, or whitespace, and its host must be one of the provider’s allowed hosts. Other URLs are rejected with a `ValidationException`, for example `URL host is not an endpoint of this provider` or `URL must not set a port`.
+  `settings.windowSize` is set by the service for each provider. It appears in `GetPolicyEngine` output, but you can’t set it. A request that includes it is rejected. The gateway uses the window size when it screens a streamed response. For more information, see [When you receive the text](policy-guardrails-streaming.md#policy-guardrails-streaming-timing).
+ You can’t configure `BedrockGuardrails` in `policyInformationProviderConfiguration`. A request that includes it is rejected with `The BedrockGuardrails configuration is managed by the service and cannot be modified`.

Next, write policies that call the provider. See [Write policies with third-party checks](policy-third-party-guardrails-policies.md).