Skip to main content
Secrets let your Notion Workers use API keys, tokens, client secrets, webhook signing secrets, and other credentials without committing those values to your source code. Notion encrypts worker secrets at rest and exposes them as environment variables at runtime. In your worker code, read them from process.env.
Never commit .env files or any type of secret to source control. Worker projects created from the template include .env and .env.* in .gitignore by default.

Add a secret

Use ntn workers env set to store one or more secrets for your worker:
To set multiple secrets at once, pass multiple KEY=value pairs:
If a key already exists, setting it again replaces the previous value.
Quote values that contain spaces, shell metacharacters, or other characters your shell might interpret.

Use a secret in worker code

Read secrets from process.env inside your worker capability:

Pull secrets for local development

When you run a worker locally, use a .env file to provide the same environment variables that the hosted worker receives. Pull remote secrets into .env:
Or write to a different file:
If the file already exists, pull preserves comments, blank lines, and local-only keys. It updates keys that also exist remotely, then appends new remote keys. For non-interactive scripts, add --yes to skip the confirmation prompt:
Treat any pulled .env file as sensitive. Confirm that the file is ignored by Git before you pull secrets into a project.

Push local secrets to your worker

If you’ve added secrets locally to .env, push them to the hosted worker:
Or push a different file:
push adds new local keys and updates changed local keys. It does not remove keys that exist only in the remote worker environment. For non-interactive scripts, add --yes:

Manage another worker

When you run these commands inside a worker project, the CLI reads the worker ID from workers.json. To manage a different worker, pass its worker ID. For set and unset, use --worker-id:
For list, pull, and push, pass the worker ID as the positional argument:

Use secrets for OAuth client credentials

For custom OAuth providers, store the OAuth client ID and client secret as worker secrets:
Then read them from process.env in the OAuth capability configuration:

Command summary

See the CLI command reference for all ntn workers env flags and options.

Next steps

OAuth

Authenticate with third-party APIs using OAuth.

Syncs

Sync external data into Notion databases.

Agent tools

Build custom tools for Notion AI.

Webhooks

Receive HTTP events from external services.