Productivity and CRM

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

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.

Notion key types

TypePrefixSecret?ScopeExpiry
Internal connection token
Sent as Authorization: Bearer together with a Notion-Version header. The connection acts as a separate bot user.
ntn_YesOnly the pages and databases shared with the connection, within one workspace, limited by the capabilities you enable—
Personal access token (PAT)
Acts as the user who created it and does not need pages shared with a connection.
—YesEverything the creating user can access in the workspace, limited by the capabilities chosen7, 30, 90 or 180 days, or 1 year (the default)
OAuth access token
Refreshing returns a new access token and a new refresh token (nrt_ in Notion's example).
—YesThe 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.
  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.

Open Notion's key settings

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.

Notion's security guide treats Refresh as the way to disable an exposed internal connection token. For personal access tokens, Notion recommends creating a new PAT and updating scripts before the old one expires.

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 your Notion 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 and CLI

Notion's SDKs and docs read the key from NOTION_API_KEY or NOTION_API_TOKEN.

Notion CLI (ntn): ntn login opens a browser to authorize a workspace and stores the token in the OS keychain; NOTION_API_TOKEN overrides it for scripts and CI

Things that catch people out

  • 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.

Common Notion authentication errors

API token is invalid.

The bearer token is not valid, was refreshed or revoked, or the PAT has expired (HTTP 401, code unauthorized).

API token does not have access to this resource.

The token lacks permission for the request (HTTP 403, code restricted_resource).

Could not find database with ID: ...

The resource does not exist for this token, or it was not shared with the connection (HTTP 404, code object_not_found).

Using your Notion key with AI agents

A coding agent that can read your .env file or your shell history can read the key, and anything in its context can end up in logs, transcripts or a prompt-injected request. The safer pattern is to keep the key in a credential broker that performs the authenticated step for the agent and hands back only the result.

BotPassword works this way. For a Notion key, these intents fit:

IntentWhat BotPassword does
run_withRuns 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_requestMakes 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.
rotatePartly 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_secretSaves a value the agent already holds as a new vault item.

Notion also publishes its own MCP server. Whatever server the agent uses, keep the credential it authenticates with out of the agent's context.

Set it up in your agent: Aider · Amp · Claude Code · Claude Desktop · Cline · OpenAI Codex CLI · all agents

Frequently asked questions

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.

Stop pasting Notion keys into agents

BotPassword is in early access. Request an invite and we'll email you when your spot opens.