---
source_url: https://www.pubnub.com/docs/serverless/functions/functions-apis/vault-module
title: Vault Module
updated_at: 2026-05-20T11:08:56.265Z
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Vault Module

The `vault` module gives you secure access to secrets. It returns the decrypted value during Function execution. Secrets are encrypted at rest and decrypted only during execution.

Add or manage secrets in the Functions UI:

* Open the Package Revision that contains your Function and select **Assign secrets**.

:::tip Manage secrets in Admin Portal
You can also manage secrets on the [Keyset](https://www.pubnub.com/docs/portal/keysets#manage-secrets) page of the [Admin Portal](https://admin.pubnub.com).
:::

Use the following `require()` statement:

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

The module exposes one method: `get(secretKey)`. It returns a Promise. If the secret is missing, the Promise rejects.

This example retrieves an API key and uses it in an authenticated XHR request.

This is an `On Request` Function.

```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) => {
            console.log(resp);
            return response.send("OK");
        });
    });
};
```

:::note Functions support
Functions provides a rich set of tools. For help with cases not covered here, please contact [PubNub Support](https://www.pubnub.com/docs/mailto:support@pubnub.com).
:::