# Notion API tokens: find, store, rotate, and use them safely with AI agents

Source: https://botpassword.com/keys/notion
Last checked: 2026-11-08

Notion API tokens come in two kinds: an internal connection token, made by a workspace owner in the Developer portal and shown on the connection's **Configuration** tab, and a personal access token that acts as the user who created it. An internal connection token only reaches pages shared with that connection, so a "not found" error usually means the page was never shared.

## Key types

| Type | Prefix | Secret | Scope | Expiry |
|---|---|---|---|---|
| Internal connection token | `ntn_` | Yes | Only the pages and databases shared with the connection, within one workspace, limited by the capabilities you enable | — |
| Personal access token (PAT) | — | Yes | Everything the creating user can access in the workspace, limited by the capabilities chosen | 7, 30, 90 or 180 days, or 1 year (the default) |
| OAuth access token | — | Yes | The pages the user granted to a public or scoped OAuth connection | — |

## How to create a Notion key

1. Sign in to Notion as a workspace owner and open the [Developer portal connections page](https://app.notion.com/developers/connections).
2. Under **Internal connections**, click **Create a new connection**, enter a name and choose the workspace.
3. On the **Configuration** tab, choose the capabilities (read, update or insert content, read user information) and copy the API token.
4. Grant page access on the **Content access** tab with **Edit access**, or from a page's ••• menu under **Connections → + Add connection**.

## Limiting what the key can do

An internal connection can only see pages explicitly shared with it, and its capabilities on the **Configuration** tab limit what it can do there. A personal access token instead carries the creating user's permissions, so prefer an internal connection for team automations and give a PAT a short expiration. On Business and Enterprise plans, workspace owners control who may create PATs.

## How to rotate a Notion key

1. Open the internal connection in the Developer portal, or go to **Settings → Connections → Develop or manage connections** in Notion.
2. Select **Refresh** on the connection's token to issue a new one; the old token stops working.
3. Replace the token in every application and environment that used it.
4. For a personal access token, create a new PAT, update your scripts, then revoke the old PAT.

## How to revoke a Notion key

1. For a personal access token, revoke it on the **Personal access tokens** page of the Developer portal; workspace admins can also revoke any PAT under **Settings → Connections → All personal access tokens**. Revocation is immediate.
2. For an internal connection token, select **Refresh** on the connection to invalidate the current token.

## If the key leaked

1. Refresh the exposed internal connection token, or revoke the exposed personal access token, straight away.
2. Replace the old token in every application and environment, and remove it from configuration files and documentation.
3. Review recent changes to pages and databases, and check **Settings → Connections** for connections you do not recognise.
4. Remove page access the connection does not need.
5. Notion is a GitHub secret scanning partner for Notion API tokens, so tokens pushed to public repositories are reported to Notion.

## Environment variables

- `NOTION_API_KEY`
- `NOTION_API_TOKEN`

## Gotchas

- A newly created internal connection has no page access. A valid token still returns 404 for anything not shared with it.
- A personal access token acts as you and sees everything you can see; an internal connection token sees only shared pages.
- Do not give the token a `NEXT_PUBLIC_` or `VITE_` variable name, because build tools expose those to the browser.
- Guests and restricted members cannot create PATs or use `ntn login`.

## Using this key with AI agents (BotPassword)

- `run_with`: Runs a command with the key injected as an environment variable or a 0600 temporary file, never on the command line, and redacts the key from the output.
- `http_request`: Makes an authenticated API call after checking the destination against the hosts this key may be sent to. The response comes back with credential-shaped values redacted, and one that holds the key itself is refused.
- `rotate`: Partly built: creates a new key, stores it as pending, verifies it, promotes it, then revokes the old key after a grace period. Today it works for Cloudflare tokens and AWS IAM keys you have set up, and an agent can start it only under a grant with autopilot; other providers cannot be rotated through their API yet.
- `store_secret`: Saves a value the agent already holds as a new vault item.

## FAQ

### Where do I find my Notion API token?

In the Developer portal, open your internal connection and look at the **Configuration** tab. For a personal access token, create one on the **Personal access tokens** page.

### Why does the Notion API say it cannot find my database?

The page or database has not been shared with your connection. Add it on the connection's **Content access** tab or with **+ Add connection** on the page.

### How do I rotate a Notion integration token?

Select **Refresh** on the internal connection's token in the Developer portal, then update every application. The old token stops working.

### What is the difference between a Notion personal access token and an internal connection?

A personal access token acts as the user who created it. An internal connection is a separate bot user that only sees pages shared with it, which suits team-owned automations.

### Do Notion personal access tokens expire?

Yes. You choose 7, 30, 90 or 180 days, or 1 year, which is the default. Expired tokens return `unauthorized`.

### Can an AI agent use my Notion key without seeing it?

Yes, if the key never enters the agent's context. Instead of pasting the key into a chat or leaving it in a `.env` file the agent can read, keep it in a credential broker that injects it into the command or request on the agent's behalf. BotPassword does this with `run_with`, `http_request`, `store_secret`, so the agent gets the result and never the value.

## Sources

- https://developers.notion.com/docs/authorization
- https://developers.notion.com/guides/get-started/internal-connections
- https://developers.notion.com/guides/get-started/personal-access-tokens
- https://developers.notion.com/docs/best-practices-for-handling-api-keys
- https://developers.notion.com/cli/get-started/authentication
- https://developers.notion.com/reference/status-codes
- https://developers.notion.com/docs/mcp
- https://docs.github.com/en/code-security/secret-scanning/introduction/supported-secret-scanning-patterns
