Claude Platform Docs

Create External Key

beta.organization.external_keys.create(**kwargs) -> BetaExternalKey
POST/v1/organizations/external_keys

Create an external key config owned by the caller's organization.

Parameters

KMS provider identity and auth coordinates.

One of the following:
class BetaAWSExternalKeyConfig { type: :aws, kms_arn, region, role_arn }
type: :aws
kms_arn: String

Full ARN of the AWS KMS key. On Claude Platform on AWS, alias ARNs are rejected, and your organization's own key must be a single-Region key in your organization's AWS account.

maxLength2048
region: optional String | nil

AWS region. Derived from kms_arn if omitted.

role_arn: optional String | nil⁠Deprecated

IAM role ARN. Deprecated; this field is ignored.

class BetaGCPExternalKeyConfig { type: :gcp, key_name }
type: :gcp
key_name: String

Full resource name of the Cloud KMS key.

class BetaAzureExternalKeyConfigParam { type: :azure, key_name, tenant_id, 2 more }

Azure Key Vault provider configuration.

type: :azure
key_name: String

Name of the key within the vault.

tenant_id: String

Azure AD tenant ID.

vault_uri: String

Key Vault data-plane URI — https://{vault-name}.vault.azure.net or https://{hsm-name}.managedhsm.azure.net.

client_id: optional String | nil

Azure AD application (client) ID. Omit to use Anthropic's multitenant app. Provide only if using a single-tenant app registration in the customer's directory.

display_name: optional String | nil

Human-friendly display name.

minLength1
maxLength255
geo: optional :us

Data residency geo. Only us is supported.

user_profile_id: optional String | nil

ID of a user profile to bind the key to. A user profile represents one of your customers: bind a customer's key to that customer's user profile. A key bound to a user profile can only be attached to a Workspace that has the same user profile, and the binding cannot be changed later. Omit this field only for your organization's own key, because a key created without a user profile ID can be attached to any Workspace, including another customer's.

Returns
class BetaExternalKey { type: :external_key, id, attachment, 6 more }

CMEK external key config belonging to the caller's organization.

Configs are organization-scoped. Workspaces attach to a config; once any workspace references it, the provider fields become effectively immutable (existing encrypted data needs the config for decrypt).

Errors

Any method can also return the general HTTP errors.

UserProfileNotFoundErrorHTTP status 400error code user_profile_not_found

The request depends on a user profile that does not exist in the organization or is no longer active. The request either names this user profile by ID, or names a resource, such as an External Key, that is bound to it.

SandboxEgressRestrictedErrorHTTP status 403error code sandbox_egress_restricted

The request came from a Claude sandbox with restricted network access, which is not allowed to make this change. Send it from outside the sandbox, or from a sandbox with unrestricted network access.

Create External Key
require "anthropic"

anthropic = Anthropic::Client.new(api_key: "my-anthropic-api-key")

beta_external_key = anthropic.beta.organization.external_keys.create(
  provider_config: {kms_arn: "arn:aws:kms:us-east-1:111122223333:key/abcd1234-5678-90ab-cdef-000011112222", type: :aws}
)

puts(beta_external_key)
Returns Examples
Response 200
{
  "id": "ekey_01SDCCSbTxrXDpWc1phhtcfK",
  "attachment": {
    "type": "attached"
  },
  "created_at": "2024-10-30T23:58:27.427722Z",
  "display_name": "prod-us-key",
  "geo": "us",
  "provider_config": {
    "kms_arn": "arn:aws:kms:us-east-1:111122223333:key/abcd1234-5678-90ab-cdef-000011112222",
    "type": "aws",
    "region": "us-east-1",
    "role_arn": "arn:aws:iam::111122223333:role/anthropic-cmek"
  },
  "type": "external_key",
  "updated_at": "2024-10-30T23:58:27.427722Z",
  "user_profile_id": "uprof_01SDCCSbTxrXDpWc1phhtcfK"
}