# Neon

> Connect Neon so failed compute starts, met quotas and full branches open incidents, and Ace can resize, start, suspend or restart a compute, or reset a preview branch, after approval.

Source: https://tryace.dev/docs/integrations/neon

Ace watches Neon projects for computes that don't start, met quotas and full branches, and reads branches, computes and operations during investigations. It never runs SQL and never reads connection strings, role names or passwords.

| | |
| --- | --- |
| Category | Database |
| Ace reads | Project quotas and usage, branches, computes, operations, consumption history |
| Ace can change | Compute autoscaling and scale to zero, compute start, suspend and restart, preview branch restore. A person always approves. |
| Opens incidents | Yes, for workloads that route Neon |
| Setup | An organization API key |

## What it reads
Ace reads the projects you list, or the first 25 the key can see, while it investigates a workload that lists Neon in its **Observability** settings or routes its alerts.

- Each project's quotas against its usage this billing period, and which quotas are met.
- The branch tree, with each branch's state, size, size quota and last restore.
- Each compute's state, pending transition, autoscaling limits and scale-to-zero timeout.
- Operations in the incident window, such as compute starts, configuration applies and branch changes, with their status and error.
- Each branch's compute, storage and data transfer in the window, from Neon's consumption history. Ace skips it on the Free plan.

For the Blueprint, Ace reads the organization, its projects, the branch tree and each compute and read replica. The default branch is the production service, and other branches sit under their parent as preview. Ace also counts databases and roles on up to 60 branches.

An app that connects to a compute's direct or pooled host links to that branch. A service with environment variables named `NEON_…`, or one that connects to a host ending in `aws.neon.tech` or `azure.neon.tech`, gets a dependency on Neon. Ace reads variable names, never values.

Neon has no read-only keys, so Ace blocks every other request before it leaves Ace. That includes SQL, role creation, passwords, connection strings, deletes, project settings, API keys and writes other than the actions below.

### Cost findings

Every day, Ace checks up to the last 7 days of consumption history for three kinds of waste. It reports each one from $5 a month, with its calculation, under [**Cost opportunities**](https://app.tryace.dev/settings/integrations#cost-opportunities).

- **Compute never scales to zero**: a compute on a preview branch with scale to zero off that ran at its minimum size for 24 hours or more. Ace can turn scale to zero on after approval.
- **Compute never used more than its minimum**: an autoscaling compute that stayed at or below its minimum in every active hour. Ace can lower the minimum after approval.
- **Idle branches still bill storage**: child branches older than 7 days, not protected, with no compute in the window. Ace doesn't delete branches. Delete them in Neon, or set an expiration date on them.

Cost findings need consumption history, so the Free plan gets none.

## What it can change
Every Neon action needs a person's approval, whatever your policy says. Ace proposes them only after an admin turns on **Actions**. See [Actions and approvals](https://tryace.dev/docs/concepts/actions-and-approvals).

| Action | What it does | Undo |
| --- | --- | --- |
| Compute autoscaling | Sets a compute's minimum and maximum size, and its scale-to-zero delay. Changing the size restarts the compute and drops its connections for a moment. | Yes. Restores the settings it replaced. |
| Compute start | Starts an idle compute, for example one that doesn't wake on connections. | No. Scale to zero suspends it again. |
| Compute suspend | Suspends a running compute. Every connection drops, and the next connection starts it again. | Yes. Starts the compute. |
| Compute restart | Restarts a running compute. Its connections drop for a moment. | No |
| Branch restore | Resets a preview branch to its parent's current data and schema. Ace keeps the branch's current state as a backup branch first. Connections to the branch drop for a moment. | Yes. Restores from the backup. |

Sizes are 0.25, 0.5 or a whole number of CU up to 16, with at most 8 CU between minimum and maximum. Scale to zero waits from 60 seconds to a week, uses Neon's default of 300 seconds, or never suspends.

Safeguards:

- Ace refuses a maximum more than double the current one, so grow a compute in steps. Change computes larger than 16 CU in Neon.
- Ace writes nothing if the compute's settings or the branch's parent changed since approval.
- Ace refuses a compute in a transition or with connections disabled, and any change while another Neon operation runs on the project.
- Branch restore refuses the default branch, protected branches and root branches. Restore those in Neon.
- It also refuses a branch that other branches were made from. Neon would move them onto the backup, and Undo wouldn't move them back.
- The backup is named `<branch>-before-ace-<time>` and stays in Neon until you delete it. A restore never runs twice.
- A branch that uses Neon Object Storage may get its parent's buckets too, and Undo doesn't bring them back.
- Neon refuses changes to a project over a consumption quota. Raise the quota in Neon first.

Every Neon key can write, so Settings shows each action as **Allowed by the credential**.

## What opens an incident

Problems open incidents only on workloads that route this connection. Neon has no webhook, so Ace checks routed projects every 2 minutes.

| Condition | Severity |
| --- | --- |
| A project quota met: active time, compute time, data written or data transfer. Neon suspends every compute until the billing period ends or the quota is raised. | Critical |
| The default branch at the size quota set on the project. Writes fail. | Critical |
| A compute that failed to be created or started, or a failed Neon availability check, on the default branch | High |
| The default branch's compute stuck in a transition, such as idle to active, for about 10 minutes | High |

A met quota, a full branch and a failed operation open an incident at once. Quota, branch and compute incidents resolve when the condition clears. Neon refreshes usage about every 15 minutes, so a quota incident clears at that pace.

A failed operation is an event, and Neon reports no recovery for it. After a fix, Ace checks for a later operation of the same kind that finished.

On preview branches and read replicas, these conditions only add context. So does every other failed operation.

Branches created or deleted, computes created, configuration applied and branch restores join the change ledger, even before a workload routes Neon. Neon doesn't record who made a change.

## Before you start

- The **admin** role in Ace.
- The Admin role in your Neon organization. Only admins create organization API keys.

## Credentials and permissions

| Credential | Where to create it | Reaches | Why Ace needs it |
| --- | --- | --- | --- |
| Organization API key (`napi_…`) | Your organization's **Settings** > **API keys** in the [Neon Console](https://console.neon.tech) | Every project in the organization. Neon has no read-only keys. | Reads, and the actions a person approves. |

Ace refuses personal and project-scoped API keys. It stores the key encrypted and sends only the requests in [What it reads](#what-ace-reads) and the actions above.

## Set up

### 1. Create an organization API key

1. In the [Neon Console](https://console.neon.tech), switch to your organization.
2. Open **Settings** > **API keys**. Neon describes the key types in its [API key docs](https://neon.com/docs/manage/api-keys).
3. Choose **Create new** and name the key Ace. Keep it an organization key. Ace refuses personal and project-scoped keys.
4. Create the key and copy it. Neon shows it only once.

### 2. Connect Neon

1. Open [**Settings** > **Integrations** > **Neon**](https://app.tryace.dev/settings/integrations/neon).
2. Fill in the form:

   | Field | What to enter |
   | --- | --- |
   | **Organization API key** | The `napi_…` key. |
   | **Project IDs** | Optional. Up to 25, comma-separated, such as `cold-poetry-09157238`. Each is under the project's **Settings** > **General**. Leave it empty to read the first 25 projects the key can see. |

3. Select **Connect Neon**. Ace checks the key before it saves, and reads the organization from it.

With **Project IDs** empty, Ace saves the first 25 projects the key can see when you connect. A project created later isn't read until you save the settings again with **Project IDs** empty.

### 3. Route alerts to a workload

In the workload's settings, open **Alerts** (`https://app.tryace.dev/workloads/<workload-id>/settings/alerts`), tick Neon under **Sources** and turn on **Investigate alerts**.

### 4. Optional: allow actions

In the [**Actions** section](https://app.tryace.dev/settings/integrations/neon#actions), turn the switch **On**.

## Set up with an agent

Copy this prompt into a coding agent, or open it in one with the logos below it. The agent does the Neon side in your terminal and asks you for each decision and each step in a browser. See [how agent setup works](https://tryace.dev/docs/integrations#set-up-with-an-agent).

Give your coding agent this prompt:

```text
Help me connect Neon to Ace. Read https://tryace.dev/docs/integrations/neon/agent.md and follow it step by step. Ask me whenever you need a decision or something only I can do.
```

## Confirm it's working

The connection card shows **Organization API key** and **Synced** with a time. **Sync now** reruns the checks **Organization key**, **Organization read** and **Projects read**. A failed check shows under the card:

- "This is a personal API key." Create an organization API key instead.
- "This is not a Neon organization API key." Create an organization API key in your organization's settings.
- "Projects not visible to this key: …" Check the project IDs, or use a key from the organization that owns them.

On connect, "This key sees no projects in its organization" means the organization has no projects the key can read. If polls keep failing, the page shows **Needs attention** and the card says why.

## Disconnect

1. In Ace, open [**Settings** > **Integrations** > **Neon**](https://app.tryace.dev/settings/integrations/neon), select **Disconnect**, then **Disconnect Neon**. To stop only actions, turn **Actions** off instead.
2. In the Neon Console, delete the key under your organization's **Settings** > **API keys**.
3. Delete any `-before-ace-` backup branches you no longer need.

## Next steps

- [Supabase](https://tryace.dev/docs/integrations/supabase)
- [PlanetScale](https://tryace.dev/docs/integrations/planetscale)
- [Actions and approvals](https://tryace.dev/docs/concepts/actions-and-approvals)
- [All integrations](https://tryace.dev/docs/integrations)
