For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to the page URL.
Primary navigation

Decrypt PSP records

Read retained customer content using your cloud-managed key

PSP decryption lets you read the content of PSP records stored in your connected cloud storage using an asymmetric key that you control.

Once you have the record and its original key metadata, decryption uses your cloud key-management service and local code. You don’t need to call an OpenAI API.

This guide applies to ZDR with PSP. It does not apply to Private Retention with PSP, which stores records in OpenAI-managed infrastructure.

Your cloud key-management service decrypts a small recovery capsule. Your application uses the recovered secret to decrypt the record locally. Your private key stays in your cloud key-management service.

The appendix shows the record bundle and local decryption examples.

Before you start

  • Enable PSP decryption, connect storage, and select a recovery key. See PSP decryption and Set up asymmetric keys.
  • Give your application permission to read the stored object and decrypt using the original RSA-3072 recovery key for the record.
  • Keep the original registration, public key, and exact cloud key/version while records depend on them.

Only records written with PSP decryption enabled for your key can be decrypted with it. Existing records aren’t converted.

Decrypt a record

1. Read the record

Read the record from your cloud storage. If it has an EKM storage envelope, decrypt that layer with its original EKM configuration first.

For OCI EKM, your recovery application also needs KEY_DECRYPT on the original AES key. Preserve the envelope’s key version and scope-associated data when decrypting that layer.

Parse the resulting JSON bundle containing protected_record and customer_access, as shown in Bundle format. If customer_access is null, PSP decryption is unavailable for that record.

2. Select the original key

Use customer_access.customer_key_id to find the original cloud key and version in your saved registration metadata. You can also retrieve the registration through the Admin API with GET /v1/organization/external_keys/{customer_key_id} using an organization Admin API key. See Retrieve the key registration.

Check the public-key fingerprint and use the exact cloud key/version. Keep the private key in your cloud key-management service. Never share it with OpenAI.

3. Decrypt the recovery capsule

Send the decoded customer_access.recovery_secret to your cloud key-management service for RSA-OAEP-SHA256 decryption.

For OCI Vault, use the vault’s cryptographic endpoint and the Decrypt operation with these fields:

Field Value
keyId The original registration’s key_ocid
keyVersionId The original registration’s exact key_version_ocid
encryptionAlgorithm RSA_OAEP_SHA_256
ciphertext The recovery-secret bytes encoded as standard Base64

The bundle uses base64url encoding. Decode recovery_secret before encoding those bytes as standard Base64 for OCI. Decode the response’s Base64 plaintext to get the recovery capsule for step 4. It isn’t the recovered record yet.

Your recovery application’s OCI identity needs KEY_DECRYPT on the original RSA key. This is separate from OpenAI’s public-key read access. Keep the original version available after rotation, and omit associatedData for this RSA operation.

4. Decrypt and verify the content

Use the decryption examples to check the capsule’s binding to the record and decrypt the content locally.

Return content only after all checks and AES-GCM authentication succeed.

Check the result

A successful operation returns authenticated UTF-8 content. Request records contain request_text and metadata telling you whether truncation occurred. See Recovered content.

Troubleshooting

Result What to check
customer_access is null The record wasn’t written with PSP decryption enabled for a recovery key. Selecting a key doesn’t enable PSP decryption for that record.
KMS access denied or key unavailable Check your decrypt permission and the availability of the original cloud key and version.
Fingerprint or binding mismatch Check the intended record and original registration. Don’t modify authenticated fields or substitute another key.
AES-GCM authentication fails Check the inputs to the decryption examples. Don’t return partial plaintext.

Appendix: Format and decryption reference

This appendix covers bundle version 1, protected-record version v4. Use the examples below to implement local decryption without OpenAI libraries.

Bundle format

The object is UTF-8 JSON with this shape. Angle brackets are placeholders.

{
  "bundle_version": 1,
  "protected_record": {
    "version": "v4",
    "algorithm": "HPKE-v1-DHKEM_P256_HKDF_SHA256-EXPORT_ONLY-AES256_GCM",
    "scope": "global",
    "key_thumbprint": "<runtime public-key thumbprint>",
    "expires_at": "2026-11-20",
    "content_id": "<content ID>",
    "encrypted_dek": "<E: base64url P-256 public point>",
    "safety_review_runtime_public_key": "<R: base64url P-256 public point>",
    "nonce": "<base64url 12-byte nonce>",
    "encrypted_cot": ["<opaque encrypted CoT string>"],
    "ciphertext": "<base64url ciphertext followed by GCM tag>"
  },
  "customer_access": {
    "version": 1,
    "algorithm": "RSA-OAEP-256",
    "customer_key_id": "<original registration ID>",
    "customer_public_key_fingerprint": "<RSA public-key fingerprint>",
    "recovery_secret": "<base64url RSA ciphertext>"
  }
}

encrypted_cot contains encrypted chain-of-thought content. This content cannot be decrypted with your customer recovery key. The array may be empty.

Decryption examples

Use the example below after decrypting any separate EKM storage envelope and the recovery capsule with the original cloud key. It checks the key fingerprint, capsule binding, recovered scalar, and runtime thumbprint before authenticating and decrypting the payload.

Download and extract the TypeScript samples and locked dependencies. From the extracted typescript-examples directory, run pnpm install --ignore-workspace --frozen-lockfile to install canonicalize and the other dependencies. The complete recovery source includes the validation and key-derivation helpers used below. Pass the bundle JSON and public-key PEM as strings, the decrypted capsule as a Buffer, and the original key ID as a string. The private RSA key remains in your cloud key-management service. To run the complete file, use node --experimental-strip-types psp/recover-record.ts bundle.json capsule.bin original-key-id public.pem. Supply the decrypted capsule as a binary file. The command writes only the recovered text to standard output. It exits with code 1 for validation errors and code 2 for payload authentication errors.

Pass these inputs to the recovery function:

  • bundle_json: The inner record bundle as UTF-8 JSON bytes.
  • capsule: The bytes returned by your cloud key-management service.
  • original_key_id: The original key registration ID from step 2.
  • original_public_key_pem: That cloud key version’s RSA public key in PEM format, as bytes in Python or a string in Java.

The function returns the decrypted content as a UTF-8 string. A failed check stops recovery.

Decrypt a PSP record
// Supply the decrypted capsule and trusted original registration. Keep the RSA
// private key in the cloud. This function returns the exact recovered UTF-8 text.
function recoverRecord(
  bundleJSON: string,
  capsule: Buffer,
  originalKeyID: string,
  publicPEM: string
): string {
  const bundle = parseBundle(bundleJSON);
  const record = object(bundle.protected_record);
  const access = object(bundle.customer_access);
  if (
    bundle.bundle_version !== 1 ||
    record.version !== "v4" ||
    record.algorithm !==
      "HPKE-v1-DHKEM_P256_HKDF_SHA256-EXPORT_ONLY-AES256_GCM" ||
    access.version !== 1 ||
    access.algorithm !== "RSA-OAEP-256" ||
    access.customer_key_id !== originalKeyID
  )
    throw new Error("Wrong schema or original key");
  if (
    !/^\s*-----BEGIN (PUBLIC KEY|RSA PUBLIC KEY)-----[A-Za-z0-9+/=\r\n]+-----END \1-----\s*$/.test(
      publicPEM
    )
  )
    throw new Error("Expected one RSA public key");
  const publicKey = createPublicKey(publicPEM);
  if (
    publicKey.asymmetricKeyType !== "rsa" ||
    publicKey.asymmetricKeyDetails?.modulusLength !== 3072
  )
    throw new Error("Expected RSA-3072");
  if (decode64(access.recovery_secret).length !== 384)
    throw new Error("Wrong RSA ciphertext length");
  const der = publicKey.export({ type: "spki", format: "der" });
  if (!equal(decode64(access.customer_public_key_fingerprint), sha256(der)))
    throw new Error("Wrong key fingerprint");
  const runtime = decode64(record.safety_review_runtime_public_key);
  if (runtime.length !== 65 || runtime[0] !== 4)
    throw new Error("Invalid P-256 encoding");
  const thumbprint = sha256(
    canonical({
      crv: "P-256",
      kty: "EC",
      x: runtime.subarray(1, 33).toString("base64url"),
      y: runtime.subarray(33).toString("base64url"),
    })
  ).toString("base64url");
  if (record.key_thumbprint !== thumbprint)
    throw new Error("Wrong runtime key");
  const nonce = decode64(record.nonce);
  const ciphertext = decode64(record.ciphertext);
  if (nonce.length !== 12 || ciphertext.length < 16)
    throw new Error("Invalid AES-GCM parameters");
  const binding = sha256(
    canonical({
      purpose: "OpenAI-PSP-v4/customer-recovery-binding",
      bundle_version: 1,
      record,
      recovery_header: without(access, "recovery_secret"),
    })
  );
  if (
    capsule.length !== 72 ||
    !equal(
      capsule.subarray(0, 8),
      Buffer.from([0x50, 0x53, 0x50, 0x76, 0x34, 0, 0, 1])
    ) ||
    !equal(capsule.subarray(40), binding)
  )
    throw new Error("Invalid recovery capsule binding");
  const ephemeral = createECDH("prime256v1");
  ephemeral.setPrivateKey(capsule.subarray(8, 40));
  if (!equal(decode64(record.encrypted_dek), ephemeral.getPublicKey()))
    throw new Error("Wrong recovered scalar");
  const aad = canonical(without(record, "ciphertext"));
  const key = payloadKey(ephemeral, runtime, aad);
  const decipher = createDecipheriv("aes-256-gcm", key, nonce);
  decipher.setAAD(aad);
  decipher.setAuthTag(ciphertext.subarray(-16));
  let plaintext: Buffer;
  try {
    plaintext = Buffer.concat([
      decipher.update(ciphertext.subarray(0, -16)),
      decipher.final(),
    ]);
  } catch {
    throw new AuthenticationError("Payload authentication failed");
  }
  return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(
    plaintext
  );
}

Recovered content

For request records whose recovered JSON has format: "psp_request_v1", request_text contains the retained request text. The other fields are reasoning_summaries (string array), request_text_truncated (boolean), and reasoning_summary_parts_omitted (nonnegative integer). Check the truncation fields when interpreting the result. Other protected content types may use different plaintext formats.

Customer recovery can continue after the OpenAI runtime key expires, provided your original customer recovery key and snapshot remain available. Leave the authenticated expires_at value unchanged. The separately encrypted encrypted_cot blobs remain opaque to customer recovery.