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.
Neon key types
| Type | Prefix | Secret? | Scope | Expiry |
|---|---|---|---|---|
| Personal API key The CLI shows keys starting napi_; the API reference examples use other formats, so the prefix may vary by creation method. | 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 Created by organization admins. | — | Yes | All projects in the organization, including ones created later | Until revoked |
| Project-scoped API key Created by organization admins. | — | 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
- Sign in to the Neon Console.
- For a personal key open Account settings → API keys; for organization or project-scoped keys open your organization's Settings → API keys.
- Create the key, or run
neon api-keys create --name <name>. - 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
- Create a replacement key with the same scope.
- Update every caller, such as CI secrets, Terraform, serverless functions, the CLI and MCP configurations.
- Revoke the old key once nothing depends on it.
Keys do not expire on a schedule, so rotation is manual. For a Postgres role password, use Roles → Reset password on the branch; the old password stops working on the next connection, and resets are branch-scoped.
How to revoke a Neon key
- Revoke in the Console, run
neon api-keys revoke <key-id>, or send DELETE to/api/v2/api_keys/{key_id}. - Revocation is immediate and permanent; the key cannot be reactivated and later requests return 401.
If your Neon key leaked
- Revoke the exposed key first, then create and deploy a replacement.
- Reset Postgres role passwords on branches the key could reach.
- Review recent branches, projects and queries for changes you did not make.
Environment variables and CLI
Neon's SDKs and docs read the key from NEON_API_KEY.
Neon CLI (neon): neon login signs in through the browser; or set NEON_API_KEY or pass --api-key. Order is --api-key, then NEON_API_KEY, then saved credentials
Things that catch people out
- 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/mcpsupports OAuth or a Bearer API key, and?readonly=truedisables writes. The/sseendpoint is deprecated. - Neon recommends the MCP server for development and testing, not production.
Common Neon authentication errors
password authentication failed for user '<user_name>'
The connection details are wrong, or the driver does not support SNI.
Using your Neon 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 Neon key, these intents fit:
| Intent | What BotPassword does |
|---|---|
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. |
Neon 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 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.