# Neon API keys: find, store, rotate, and use them safely with AI agents

Source: https://botpassword.com/keys/neon
Last checked: 2026-10-25

Neon API keys come in three types: personal, organization and project-scoped. They never expire until revoked, the secret is shown only once, and revocation is immediate and permanent. Create them under Account settings → API keys (personal) or your organization's Settings → API keys.

## Key types

| Type | Prefix | Secret | Scope | Expiry |
|---|---|---|---|---|
| Personal API key | `napi_` | Yes | Organization projects where the user is a member | Until revoked; org project access ends if the user leaves the organization |
| Organization API key | — | Yes | All projects in the organization, including ones created later | Until revoked |
| Project-scoped API key | — | Yes | One project, with Editor access; cannot delete the project, manage its access, create projects or create API keys | Until revoked or the project leaves the organization |

## How to create a Neon key

1. Sign in to the Neon Console.
2. For a personal key open **Account settings → API keys**; for organization or project-scoped keys open your organization's **Settings → API keys**.
3. Create the key, or run `neon api-keys create --name <name>`.
4. Copy it. Neon shows the secret only at creation.

## Limiting what the key can do

Use a project-scoped key to limit access to one project (Editor access) in CI or automation. Organization keys cover every project in the org. Personal keys inherit what the user can reach. Database access itself uses Postgres role passwords, which are separate from API keys.

## How to rotate a Neon key

1. Create a replacement key with the same scope.
2. Update every caller, such as CI secrets, Terraform, serverless functions, the CLI and MCP configurations.
3. Revoke the old key once nothing depends on it.

## How to revoke a Neon key

1. Revoke in the Console, run `neon api-keys revoke <key-id>`, or send DELETE to `/api/v2/api_keys/{key_id}`.
2. Revocation is immediate and permanent; the key cannot be reactivated and later requests return 401.

## If the key leaked

1. Revoke the exposed key first, then create and deploy a replacement.
2. Reset Postgres role passwords on branches the key could reach.
3. Review recent branches, projects and queries for changes you did not make.

## Environment variables

- `NEON_API_KEY`

## Gotchas

- Neon API keys manage projects and branches; Postgres connection passwords are separate credentials.
- Personal keys stop working for organization projects if the user leaves the organization.
- The MCP server at `https://mcp.neon.tech/mcp` supports OAuth or a Bearer API key, and `?readonly=true` disables writes. The `/sse` endpoint is deprecated.
- Neon recommends the MCP server for development and testing, not production.

## 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.
- `cli_login`: Lets git, Docker, the AWS CLI and kubectl log in through bpw's credential helper, so the token is fetched when the tool needs it and not written into its config. The helper hands the value to the tool, so the grant is always disclosing. Other tools use run_with; OAuth device logins are planned.
- `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 Neon API key?

Account settings → API keys in the Neon Console. The secret is visible only when you create the key.

### What is a project-scoped Neon API key?

A key limited to one project with Editor access. It cannot delete the project or create keys.

### How do I use a Neon API key with the CLI?

Set `NEON_API_KEY` or pass `--api-key`. Either one skips `neon login`.

### Can an AI agent use my Neon 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://neon.com/docs/manage/api-keys
- https://neon.com/docs/reference/neon-cli
- https://neon.com/docs/ai/neon-mcp-server
- https://neon.com/docs/connect/connection-errors
- https://neon.com/docs/manage/roles
