Add and attach an encryption key with the Admin API
Create, validate, and attach a customer-managed encryption key with three Admin API calls.
These calls work on Claude Platform. On Claude Enterprise or Claude Platform on AWS, follow your setup page.
Creating an external key is what Add key does in the Claude Console, and validating it is what Verify does.
Before you start
- Customer-managed encryption keys (CMEK) are turned on for your organization.
- You have an Admin API key. The samples read it from
ANTHROPIC_API_KEY. - You've created your key in AWS KMS, Google Cloud KMS, or Azure Key Vault, and kept the values the setup steps tell you to copy.
- You have a workspace that retains data, ideally a new one, because existing data stays under Anthropic's key.
Create, validate, and attach the key
Create the external key
Replace
<friendly-name>with a display name and<key-arn-from-create-key-step>with the key ARN.Pythonclient = anthropic.Anthropic() external_key = client.organization.external_keys.create( display_name="<friendly-name>", geo="us", provider_config={"type": "aws", "kms_arn": "<key-arn-from-create-key-step>"}, ) print(f"id: {external_key.id}") print(f"display_name: {external_key.display_name}")Replace
<friendly-name>with a display name. Replace the value that starts withprojects/with the full key resource name.Pythonclient = anthropic.Anthropic() external_key = client.organization.external_keys.create( display_name="<friendly-name>", geo="us", provider_config={ "type": "gcp", "key_name": "projects/<your-project-id>/locations/<region>/keyRings/<your-keyring-name>/cryptoKeys/<your-key-name>", }, ) print(f"id: {external_key.id}") print(f"display_name: {external_key.display_name}")Replace the placeholders:
<friendly-name>: a display namehttps://<your-vault-name>.vault.azure.net/: the vault URI<your-key-name>: the key name<your-tenant-id>: the vault's tenant ID
Pythonclient = anthropic.Anthropic() external_key = client.organization.external_keys.create( display_name="<friendly-name>", geo="us", provider_config={ "type": "azure", "vault_uri": "https://<your-vault-name>.vault.azure.net/", "key_name": "<your-key-name>", "tenant_id": "<your-tenant-id>", }, ) print(f"id: {external_key.id}") print(f"display_name: {external_key.display_name}")The
idin the response is the external key ID. Copy it for the next two steps.{ "type": "external_key", "id": "ekey_<id>", "display_name": "<friendly-name>" }Validate the key
Replace
ekey_<id>with the external key ID.Pythonclient = anthropic.Anthropic() validation = client.organization.external_keys.validate("ekey_<id>") print(f"status: {validation.status}") print(f"error: {validation.error}")A successful response looks like this:
{ "type": "external_key_validation", "status": "success", "error": null }If
statusisfailure, theerrorfield says why. See Troubleshoot CMEK.Attach the key to a workspace
Replace
<workspace-id>with the workspace ID, which starts withwrkspc_, andekey_<id>with the external key ID.Pythonclient = anthropic.Anthropic() workspace = client.organization.workspaces.update( "<workspace-id>", external_key_id="ekey_<id>" ) print(f"id: {workspace.id}") print(f"external_key_id: {workspace.external_key_id}")The response shows the attached key's ID in
external_key_id. If the request is refused, look up the error.
Was this page helpful?