---
source_url: https://www.pubnub.com/docs/serverless-sdk/modules-and-libraries/vault
title: vault
updated_at: 2026-09-30T07:20:08.000Z
---

# vault

## Documentation index

To discover more PubNub resources:

1. Fetch [PubNub's llms.txt](https://www.pubnub.com/llms-full.txt) for a list of available pages in Markdown format.
2. Identify relevant URLs from that index.
3. Fetch the target pages.

Do not assume a path exists, always check the index first.

The `vault` built-in module is available only inside a PubNub Function. It reads secrets stored on the Function's keyset.

```javascript
const vault = require('vault');
```

Secrets are encrypted at rest and decrypted only during Function execution. Assign secrets from a Function's Package Revision editor (**Assign secrets**) or from the [Keyset](https://www.pubnub.com/docs/architecture/authentication/set-up-your-account.md) page of the Admin Portal.

## get

`get(secretKey)`

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| secretKey | String | Yes |  | Name of the secret to retrieve. |

Returns: Promise resolving to the decrypted secret value. Rejects if the secret is missing.

```javascript
export default (request, response) => {
    const xhr = require('xhr');
    const vault = require('vault');

    return vault.get('myApiKey').then((apiKey) => {
        const http_options = {
            method: 'GET',
            headers: { API_KEY: apiKey }
        };
        return xhr.fetch('https://httpbin.org/get', http_options).then((resp) => {
            return response.send('OK');
        });
    });
};
```

## Related reference

* [Modules and libraries](https://www.pubnub.com/docs/serverless-sdk/modules-and-libraries/overview.md). Every built-in module available inside a Function.
* [xhr](https://www.pubnub.com/docs/serverless-sdk/modules-and-libraries/xhr.md). Making an authenticated outbound request with a retrieved secret.
* [API limits](https://www.pubnub.com/docs/serverless-sdk/api-limits.md). Per-execution vault read cap.

Last updated at: 2026-09-30T07:20:08.000Z
