# REST API

Reference for the KeelDB REST API, covering authentication, rate limits, errors and every endpoint with examples.

Everything you do with databases in the console is available over HTTPS as JSON.

## Base URL

```bash
https://keeldb.com/api/v1
```

## Authentication

Create an API key under **API keys** in the console (owner, admin or developer role) and send it as a bearer token:

```bash
export KEELDB_API_KEY=keel_xxx

curl https://keeldb.com/api/v1/databases \
  -H "Authorization: Bearer $KEELDB_API_KEY"
```

- A key belongs to an organization and acts with the role and permissions chosen when it was created, never more than its creator's role. When the organization requires two-factor authentication, a key created by a member without it can only read. A call the key is not allowed gets `403 forbidden`. See [API keys](/docs/security#api-keys).
- Missing, malformed or revoked keys get `401 unauthorized`.
- `GET /plans`, `GET /regions` and `GET /extensions` are public and need no key.

See [API keys](/docs/security#api-keys) for how keys are stored and how to handle them.

## Rate limits

Each API key gets 120 requests per minute, with bursts of up to 60 requests. Over the limit, requests fail with `429 rate_limited`; wait a moment and retry with backoff. The [MCP server](/docs/mcp) has its own budget with the same limits.

## Requests and responses

- Send request bodies as JSON with `Content-Type: application/json`. Field names are `snake_case`.
- Successful responses wrap the result in `data`: an object for single resources, an array for lists.
- Timestamps are ISO 8601 in UTC, for example `2026-10-07T09:12:44.512Z`.
- Responses are never cached (`Cache-Control: no-store`).
- Creating and changing databases is asynchronous: the API returns once the change is accepted, and the database's `status` shows progress.

## Errors

Errors use one shape:

```json
{
  "error": {
    "code": "invalid_input",
    "message": "Request body is invalid",
    "details": [{ "path": "name", "message": "Name must be at least 2 characters" }]
  }
}
```

`details` is present only when there is more to say, for example one entry per invalid field, its `path` named as in the request body. `message` is written for people and may change; branch on `code`.

| HTTP status | `code` | When |
| --- | --- | --- |
| 400 | `invalid_json` | The body isn't valid JSON. |
| 401 | `unauthorized` | Missing, malformed or revoked API key. |
| 402 | `payment_required` | Launch and Dedicated need a payment method, or the last invoice is unpaid. |
| 403 | `forbidden` | The organization is suspended, or the action isn't allowed. |
| 403 | `limit_reached` | A plan or account limit was reached. See [Limits](/docs/limits). |
| 404 | `not_found` | The database or job doesn't exist in your organization. |
| 409 | `conflict` | The database isn't in a state that allows this (for example not running, being deleted, protected from deletion, or it still has branches). |
| 422 | `invalid_input` | A field is missing or invalid. |
| 429 | `rate_limited` | Too many requests. |
| 500 | `internal` | Unexpected error. Retry. |
| 503 | `unavailable` | KeelDB's control plane is briefly unavailable (your databases keep running), or our shared servers have no room for a new Free branch right now. Retry after the seconds in the `Retry-After` header. |

## The database object

Databases and branches share one representation:

```json
{
  "id": "k7m2x9qa4pz1",
  "name": "shop",
  "status": "ready",
  "status_message": "Cluster in healthy state",
  "plan": "dedicated",
  "size": "perf-8",
  "topology": "single",
  "interim_placement": null,
  "waiting_line": null,
  "region": "us-east",
  "provider": "hetzner",
  "postgres_version": "18.6",
  "database": "shop",
  "user": "shop_owner",
  "hosts": {
    "direct": "k7m2x9qa4pz1.us-east.db.keeldb.com",
    "pooler": "k7m2x9qa4pz1-pooler.us-east.db.keeldb.com",
    "read_only": null,
    "port": 5432
  },
  "storage": { "allocated_gb": 80, "used_bytes": 52428800, "max_gb": 512 },
  "read_replicas": 0,
  "pooler_enabled": true,
  "ip_allowlist": [],
  "scale_to_zero": false,
  "scale_to_zero_minutes": null,
  "sleeps_after_idle_minutes": null,
  "on_limit": null,
  "min_cu": null,
  "max_cu": null,
  "current_cu": null,
  "warm_floor": null,
  "restore_window_days": 7,
  "private_networking": null,
  "archived_at": null,
  "suspended_reason": null,
  "read_only_reason": null,
  "read_only_until": null,
  "deletion_protection": false,
  "protected": false,
  "restored_from": null,
  "expires_at": null,
  "extensions": [],
  "parent_id": null,
  "branch_point": null,
  "relocation": "relocate",
  "slow_query_ms": 1000,
  "durability": null,
  "created_at": "2026-10-07T09:12:44.512Z"
}
```

| Field | Description |
| --- | --- |
| `id` | Database id: `k` followed by 11 lowercase letters and digits. Used in hostnames. |
| `name` | Display name. |
| `status` | `provisioning`, `ready`, `restarting` (it served before and is coming back: a restart, a failover, a resize switching over), `sleeping` (Free, Launch or Scale, scaled to zero), `suspended`, `error` or `deleting`. A Dedicated database that can't be placed yet stays `provisioning` with a `status_message` that says it is waiting for capacity. A Free database with no connections for 30 days goes `archiving`, then `archived` (moved to backup storage), and `restoring` when the next connection asks for it. See [Idle archive](/docs/limits#free-limits-in-practice). |
| `status_message` | Human-readable detail about the status, or `null`. |
| `plan` | `free`, `launch`, `scale` or `dedicated`. |
| `size`, `topology` | Dedicated only: the size (for example `perf-8`) and topology (`single`, `ha2` or `ha3`). `null` on Free, Launch and Scale. |
| `interim_placement` | Dedicated only, while the database runs on [reserved capacity](/docs/plans-and-billing#reserved-capacity) until its own servers are ready: `status` ("Running on reserved capacity on a shared server until your own servers are ready"), `reason` and `since`. `null` otherwise. |
| `waiting_line` | Free, Launch and Scale only, while the database waits for room on our shared servers: `status` ("In line for a database") and `since`, when it joined the line. It is created by itself as soon as there is room, Scale databases first, then Launch, then Free, oldest first, with the hostnames and credentials it already has; nothing is billed while it waits. `null` otherwise. |
| `region`, `provider` | Where the database runs: the region id, `us-east` today, and the provider of the servers it runs on: `hetzner` for a Dedicated database on its own servers in Ashburn, `aws` for a Free or Launch database on our shared server at AWS in Northern Virginia. |
| `postgres_version` | The running version once known, otherwise the requested major version. |
| `database`, `user` | PostgreSQL database name and owner role. |
| `hosts.direct` | Direct host for the primary. |
| `hosts.pooler` | PgBouncer host, or `null` when the pooler is off. |
| `hosts.read_only` | Read-only host, or `null` when the database has a single copy. |
| `hosts.port` | Always `5432`. |
| `storage` | `allocated_gb`: the storage the database is given now, in GB; `used_bytes`: the database's size (`pg_database_size`, without the write-ahead log), refreshed every 10 seconds on Free and Launch and every minute on Dedicated; `max_gb`: the maximum storage in GB (Free 1, Launch 100, Dedicated your maximum). 1 GB is 1,073,741,824 bytes. |
| `read_replicas` | Number of read replicas (0 to 3). |
| `pooler_enabled` | Whether the PgBouncer pooler runs. |
| `ip_allowlist` | Allowed addresses and CIDR ranges. Empty means all. |
| `scale_to_zero` | Whether the database scales to zero when idle (always on Free, by default on Launch, never on Dedicated). |
| `scale_to_zero_minutes` | Idle minutes before it scales to zero, or `null` for always on. |
| `sleeps_after_idle_minutes` | Idle minutes after which it scales to zero today, or `null` for always on. |
| `on_limit` | Launch and Scale: what happens at the organization's hard [spend limit](/docs/plans-and-billing#spending-controls), when one applies, `hold_min` (stay at the minimum) or `suspend`. `null` on Free and Dedicated. |
| `min_cu`, `max_cu` | Free, Launch and Scale: the autoscaling range in CU (Free always 0.25 to 2; Launch and Scale up to 16 as the elastic pool has room). `null` on Dedicated. |
| `current_cu` | Free, Launch and Scale: the primary's size right now, in CU (0 while it sleeps), or `null` before it was measured. |
| `warm_floor` | Launch and Scale: `true` when an idle database first shrinks to a small warm size, `false` when it sleeps at once. `null` on Free (always on) and Dedicated. |
| `restore_window_days` | The days of history it keeps for point-in-time restore: Free 1, Launch up to 7, Scale up to 30 (7 by default), Dedicated its topology's window. |
| `private_networking` | Reserved for Scale and Dedicated: `null` today. |
| `archived_at` | Free only: when the database was moved to backup storage after 30 days without connections, or `null`. |
| `suspended_reason` | Why a `suspended` database is suspended: `billing` (an unpaid invoice), `spend_limit` (Launch and Scale at a hard spend limit set to suspend), `free_allowance` (Free, a monthly allowance used up: CU-hours or egress), `fair_use` (Free, its Free allowance used the month's fair use), `owner` (you suspended it) or `abuse`. `null` when it is not suspended. |
| `read_only_reason`, `read_only_until` | Why the database is read-only right now: `wal_cap` (Free, 5 GB of archived WAL today, until 00:00 UTC), `storage_limit` or `storage_max`, and until when (`null` means until it is resolved). Both `null` when it accepts writes. |
| `deletion_protection` | When `true`, the database can't be deleted. See [Deletion protection](/docs/branching#deletion-protection). |
| `protected` | Launch and Dedicated: when `true`, the database is [protected](/docs/branching#protected-branches): deletion protection stays on, it can't expire, it never scales to zero and it holds at its minimum size at the spend limit. |
| `restored_from` | For a database or branch made from a [snapshot](/docs/backups-and-restore#snapshots): `snapshot_id`, `database_id` (the database it was taken of) and `taken_at` (the moment it holds). Otherwise `null`. |
| `expires_at` | Branches only: when the branch deletes itself, or `null`. See [Branch expiry](/docs/branching#branch-expiry). |
| `extensions` | Catalog extensions KeelDB installs in this database. See [Extensions](/docs/extensions#catalog-extensions). |
| `slow_query_ms` | Statements running at least this many milliseconds appear in the [logs](#get-postgresql-logs) as slow queries. 1000 unless you set it. |
| `relocation` | Single-copy databases: what happens if their data center is lost, `relocate` (restored from backups in another data center, the default) or `wait` (it stays down until its data center returns). See the [SLA](/legal/sla). |
| `durability` | Reserved for Free and Launch: `null` today. |
| `parent_id` | For branches, the database it was created from. Otherwise `null`. |
| `branch_point` | For point-in-time branches and restores, the time restored to. Otherwise `null`. |
| `created_at` | Creation time. |

## Plans

### List plans

`GET /plans` (public)

Returns the catalog: Free, Launch, Scale and Dedicated with every size and topology, its price and whether it can be ordered right now. The same data is behind the [pricing page](/pricing) and [Plans and billing](/docs/plans-and-billing).

```bash
curl https://keeldb.com/api/v1/plans
```

```json
{
  "data": [
    {
      "id": "free",
      "name": "Free",
      "region": "us-east",
      "compute_cu": { "min": 0.25, "max": 2 },
      "cu_hours_per_database_month": 100,
      "cu_hours_per_organization_month": 300,
      "scale_to_zero_minutes": 5,
      "sleeps_after_idle_minutes": 5,
      "storage_gb": 1,
      "databases_per_organization": 10,
      "branches_per_database": 5,
      "branches_per_organization": 20,
      "restore_window_days": 1,
      "egress_gb_per_project_month": 5,
      "egress_gb_per_organization_month": 50,
      "wal_written_gb_per_organization_day": 0.5,
      "archived_wal_gb_per_database_day": 5,
      "snapshots_per_database": 1,
      "max_connections": 100,
      "monthly_usd": 0
    },
    {
      "id": "launch",
      "name": "Launch",
      "region": "us-east",
      "compute_cu": { "min": 0.25, "max": 16, "default_max": 2, "untrusted_max": 4, "max_spread": 8, "note": "as the elastic pool has room" },
      "scale_to_zero_minutes_default": 5,
      "sleeps_after_idle_minutes_default": 5,
      "orderable": true,
      "max_storage_gb": 50,
      "restore_window_days": 7,
      "read_replicas_max": 3,
      "minimum_monthly_usd": 5,
      "minimum_egress": { "share_of_rest": 0.7, "gb_per_usd_left": 7, "max_gb": 35 },
      "spend_limit_default_usd": 100,
      "spend_limit_default_mode": "alerts",
      "rates_usd": { "cu_hour": 0.106, "storage_gb_month": 0.3, "history_gb_month": 0.05, "egress_gb": 0.1, "extra_branch_month": 1, "snapshot_gb_month": 0.08 },
      "rates_from": "2026-10-01T00:00:00.000Z",
      "included": { "egress_gb_per_month": 500, "egress_included_per": "project", "egress_organization_bound": { "gb_per_usd": 1, "above_usd": 5 }, "branches_per_database": 10, "branches_organization_allowance": { "base": 5, "per_usd": 1, "above_usd": 5, "counted_in": "branch_hours" }, "history_multiple_of_data": 2 },
      "rate_cards": [
        { "id": "r3", "from": "2026-10-01T00:00:00.000Z", "until": null, "launch": { "cu_hour": 0.106, "storage_gb_month": 0.3, "history_gb_month": 0.05, "egress_gb": 0.1, "extra_branch_month": 1, "egress_included": { "gb_per_month": 500, "per": "project", "organization_bound": { "gb_per_usd": 1, "above_usd": 5 } }, "branches_organization_allowance": { "base": 5, "per_usd": 1, "above_usd": 5, "counted_in": "branch_hours" }, "monthly_minimum": { "usd": 5, "egress_share_of_rest": 0.7, "dedicated_only_months": true } }, "dedicated": { "egress_gb": 0.1, "egress_included_gb_per_node_month": 100, "extra_storage_gb_month_per_node": 0.4, "node_monthly_usd": { "std-2": 51, "std-4": 78, "std-8": 211, "perf-8": 145, "perf-16": 266, "perf-32": 512, "perf-64": 1000, "perf-128": 1859, "perf-192": 2571 } } }
      ],
      "price_list": [
        { "id": "launch-compute", "item": "Compute", "unit": "CU-hour: the CU allocated, measured each hour (1 CU is 1 vCPU and 4 GB of RAM)", "price": "$0.106 per CU-hour", "included": "" }
      ]
    },
    {
      "id": "scale",
      "name": "Scale",
      "region": "us-east",
      "compute_cu": { "min": 0.25, "max": 16, "default_max": 4, "untrusted_max": 4, "max_spread": 8, "vcpu_per_cu": 1, "note": "as the elastic pool has room" },
      "scale_to_zero_minutes_default": 5,
      "scale_to_zero_minutes_min": 1,
      "sleeps_after_idle_minutes_default": 5,
      "orderable": true,
      "opens": "2026-10-01T00:00:00.000Z",
      "max_storage_gb": 100,
      "restore_window_days": { "default": 7, "max": 30 },
      "read_replicas_max": 3,
      "minimum_monthly_usd": 5,
      "minimum_egress": { "share_of_rest": 0.7, "gb_per_usd_left": 7, "max_gb": 35 },
      "minimum_shared_with": "launch",
      "rates_usd": { "cu_hour": 0.15, "storage_gb_month": 0.3, "history_gb_month": 0.05, "egress_gb": 0.1, "extra_branch_month": 1, "snapshot_gb_month": 0.08 },
      "rates_from": "2026-10-01T00:00:00.000Z",
      "included": { "egress_gb_per_month": 500, "egress_included_per": "project", "egress_organization_bound": { "gb_per_usd": 1, "above_usd": 5 }, "branches_per_database": 25, "branches_organization_allowance": { "base": 5, "per_usd": 1, "above_usd": 5, "counted_in": "branch_hours" }, "history_multiple_of_data": 2 },
      "private_networking": null,
      "telemetry_export": { "protocol": "otlp/http", "signals": ["metrics", "logs"] },
      "sla_monthly_uptime_pct": 99.9,
      "price_list": [
        { "id": "scale-compute", "item": "Compute", "unit": "CU-hour: the CU allocated, measured each hour (1 CU is 1 vCPU, guaranteed, and 4 GB of RAM)", "price": "$0.15 per CU-hour", "included": "" }
      ]
    },
    {
      "id": "dedicated",
      "name": "Dedicated",
      "region": "us-east",
      "price_zone": "us",
      "hours_cap_per_month": 730,
      "extra_storage_usd_per_gb_month_per_node": 0.4,
      "backup_storage_usd_per_gb_month": 0.03,
      "snapshot_usd_per_gb_month": 0.08,
      "egress_included_gb_per_node_month": 100,
      "egress_usd_per_gb": 0.1,
      "egress_from": "2026-10-01T00:00:00.000Z",
      "minimum_monthly_usd": 5,
      "prices_from": "2026-10-01T00:00:00.000Z",
      "read_replicas_max": 3,
      "private_networking": null,
      "sizes": [
        {
          "id": "perf-8",
          "name": "Performance 8",
          "vcpu": 2,
          "cpu": "dedicated",
          "memory_gb": 8,
          "included_storage_gb": 80,
          "max_storage_gb": 512,
          "max_connections": 400,
          "topologies": [
            { "topology": "single", "nodes": 1, "backup_retention_days": 7, "monthly_usd": 145, "hourly_usd": 0.19863, "status": "orderable", "placement": "own_servers" },
            { "topology": "ha2", "nodes": 2, "backup_retention_days": 14, "monthly_usd": 290, "hourly_usd": 0.39726, "status": "waiting_for_capacity", "placement": null },
            { "topology": "ha3", "nodes": 3, "backup_retention_days": 30, "monthly_usd": 435, "hourly_usd": 0.59589, "status": "waiting_for_capacity", "placement": null }
          ]
        }
      ]
    }
  ]
}
```

Every plan has a `price_list`: each unit it bills, how it is measured, its price and what the plan includes first, in the words of the price list on the [pricing page](/pricing) (one line of Launch's is shown here). Launch's `rates_usd` are the newest rate card's, in force from `rates_from`; `rate_cards` lists every card, oldest first, with the 00:00 UTC it starts and the one it ends (`null`: still in force), and an hour is billed at the card in force in that hour. Launch's included egress is counted `per` project (a database and all its branches) or per database; an `organization_bound` of `{ "gb_per_usd": 1, "above_usd": 5 }` means all of an organization's projects together include at most 1 GB for each $1 of its Launch and Scale compute, storage and restore history that month above $5 (the minimum), each project at most its 500 GB. Under the minimum, `minimum_egress` of `{ "share_of_rest": 0.7, "gb_per_usd_left": 7, "max_gb": 35 }` means Launch and Scale egress counts toward the part of the $5 minimum that their other usage leaves, up to 70% of that part: 7 GB for each $1 left, 35 GB in a month with no other usage, with egress past it billed on top (each card's `monthly_minimum` has the same share as `egress_share_of_rest`). `branches_organization_allowance` of `{ "base": 5, "per_usd": 1, "above_usd": 5, "counted_in": "branch_hours" }` means all of an organization's databases together include at most 5 child branches plus 1 for each $1 above the minimum, counted in branch-hours over the month (each database includes `branches_per_database` of them, and a database itself never counts); included branch-hours above it are billed at the month's end, or at the account's closure if that comes first, as extra branches. Dedicated's `minimum_monthly_usd` is the same minimum in a month with only Dedicated databases, their egress billed beside it.

Free's `egress_gb_per_project_month` is a hard stop for that project only, and `egress_gb_per_organization_month` one for all of the organization's Free databases together, deleted ones included.

Each plan names the `region` it describes, the region new databases go to by default, and Dedicated also its `price_zone` (`us` in US East). Free shows what one of our shared servers can give a database now; Launch and Scale what the elastic pool can give one now, a server it runs or a larger one it may buy for a paying customer: when that is less than the plan's maximum, `compute_cu.max` is the lower value and `compute_cu.note` says "more when shared capacity grows"; when the maximum needs a larger server than the pool runs today, the note says "as the elastic pool has room" (the pool adds that server for a paying customer whose minimum the others cannot start; a database grows within the free room of the server it runs on). `untrusted_max` is the most before the organization's first paid invoice, and `max_spread` the widest range. Launch's `max_storage_gb` is the largest database every shared server of the region takes. Scale's `orderable` is `true` once `opens` has passed and paid plans are open; its `minimum_shared_with` says the one $5 minimum counts Launch and Scale together, and `private_networking` is `null` until AWS PrivateLink opens.

The response lists all nine Dedicated sizes; one is shown here, as US East offers it now: `single` only until Dedicated servers open (a database on reserved capacity has one copy), then `ha2` across two AWS availability zones, while `ha3` waits for a third. A size's `monthly_usd` and `hourly_usd`, `extra_storage_usd_per_gb_month_per_node` and `egress_included_gb_per_node_month` (a whole month's; a database that exists for part of a month includes it in proportion to its hours) are the newest rate card's, in force from `prices_from`; each card in `rate_cards` (on Launch) gives its Dedicated prices per node, and an hour is billed at the card in force in that hour. `status` is `orderable` or `waiting_for_capacity` (see [Plans and billing](/docs/plans-and-billing#dedicated)). `placement` says where an orderable option would start: `interim` on [reserved capacity](/docs/plans-and-billing#reserved-capacity), `own_servers` otherwise; it is `null` for an option waiting for capacity, and for every option until Dedicated servers open. `hourly_usd` is the monthly price divided by 730, rounded to six decimals.

## Regions

### List regions

`GET /regions` (public)

```bash
curl https://keeldb.com/api/v1/regions
```

```json
{
  "data": [
    {
      "id": "us-east",
      "provider": "aws",
      "provider_name": "AWS",
      "location": "Ashburn, Virginia, USA",
      "name": "US East",
      "available": true,
      "private_link": { "available": false, "aws_region": "us-east-1" }
    }
  ]
}
```

`private_link` says whether AWS PrivateLink is offered there (`available`) and through which AWS region. Only regions with `available: true` accept new databases; today that is US East. Regions that do not accept new databases yet are listed with `available: false`. `provider` is the region's main provider; a region uses several, all listed on the [Sub-processors](/legal/subprocessors) page.

## Databases

### List databases

`GET /databases`

Returns every database and branch in the organization, oldest first. Deleted databases are not included; databases being deleted have `status: "deleting"`.

```bash
curl https://keeldb.com/api/v1/databases \
  -H "Authorization: Bearer $KEELDB_API_KEY"
```

```json
{ "data": [ { "id": "k7m2x9qa4pz1", "name": "shop", "status": "ready", "plan": "dedicated" } ] }
```

Each item is a full [database object](#the-database-object); fields are trimmed here.

### Create a database

`POST /databases`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | string | Yes | 2 to 48 characters: letters, numbers, spaces, dots, hyphens or underscores, starting with a letter or number. |
| `plan` | string | Yes | `free`, `launch` or `dedicated`. |
| `size` | string | Dedicated | A Dedicated size from [`GET /plans`](#list-plans), for example `perf-8`. Not allowed on Free and Launch. |
| `topology` | string | Dedicated | `single`, `ha2` or `ha3`. Not allowed on Free and Launch. |
| `region` | string | No | Region id. Default `us-east`, the region available today. |
| `postgres_version` | string | No | `"18"` (default), `"17"` or `"16"`. |
| `database` | string | No | PostgreSQL database name. Normalized to lowercase letters, digits and underscores (at most 40 characters). Defaults to one derived from `name`. The owner role is `<database>_owner`. |

```bash
curl -X POST https://keeldb.com/api/v1/databases \
  -H "Authorization: Bearer $KEELDB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "shop", "plan": "dedicated", "size": "perf-8", "topology": "single", "region": "us-east", "postgres_version": "18"}'
```

Response `201 Created`:

```json
{
  "data": {
    "id": "k7m2x9qa4pz1",
    "name": "shop",
    "status": "provisioning",
    "status_message": null,
    "plan": "dedicated",
    "size": "perf-8",
    "topology": "single",
    "region": "us-east",
    "provider": "hetzner",
    "postgres_version": "18",
    "database": "shop",
    "user": "shop_owner",
    "hosts": {
      "direct": "k7m2x9qa4pz1.us-east.db.keeldb.com",
      "pooler": "k7m2x9qa4pz1-pooler.us-east.db.keeldb.com",
      "read_only": null,
      "port": 5432
    },
    "storage": { "allocated_gb": 80, "used_bytes": 0, "max_gb": 512 },
    "read_replicas": 0,
    "pooler_enabled": true,
    "ip_allowlist": [],
    "scale_to_zero": false,
    "scale_to_zero_minutes": null,
    "sleeps_after_idle_minutes": null,
    "on_limit": null,
    "deletion_protection": false,
    "expires_at": null,
    "extensions": [],
    "parent_id": null,
    "branch_point": null,
    "created_at": "2026-10-07T09:12:44.512Z"
  }
}
```

The response holds the full [database object](#the-database-object); some of its fields are left out here.

Poll [`GET /databases/{id}`](#get-a-database) until `status` is `ready`. Free and Launch databases are usually ready in about a minute; Dedicated databases take longer, because their servers are created first. Common errors: `402 payment_required` (a paid plan without a payment method), `403 limit_reached` (plan or account limit), `422 invalid_input` (unknown or unavailable region, invalid name, a size or topology that is waiting for capacity, or a size without a topology).

### Get a database

`GET /databases/{id}`

```bash
curl https://keeldb.com/api/v1/databases/k7m2x9qa4pz1 \
  -H "Authorization: Bearer $KEELDB_API_KEY"
```

Returns `{"data": <database object>}` with two more fields: `tier_move`, its move between plans while one is under way (see [Move to another plan](#move-to-another-plan)), and `free_usage`, where a Free database stands against the Free limits this month (`null` on every other plan):

```json
{
  "limits": "before_garboard",
  "meters": [
    { "id": "cu_hours", "scope": "family", "unit": "cu_hours", "used": 42.5, "limit": 100, "percent": 42.5, "level": "ok", "ticks": [80], "stops_at": 100, "resets_at": "2026-12-01T00:00:00.000Z", "forecast_at": null, "organization_used": null, "half_cap": false },
    { "id": "egress_project", "scope": "family", "unit": "gb", "used": 1.2, "limit": 5, "percent": 24, "level": "ok", "ticks": [80], "stops_at": 5, "resets_at": "2026-12-01T00:00:00.000Z", "forecast_at": null, "organization_used": null, "half_cap": false }
  ],
  "fair_use": null,
  "allowance": null,
  "low_cu_hours": false,
  "inactivity": "idle_archive",
  "idle_archive_days": 30
}
```

| Field | Description |
| --- | --- |
| `limits` | The set of Free limits in force: `before_garboard`. |
| `meters` | One entry per limit that applies, the database's first: `id`, `scope` (`family` for the database with its Free branches, `database`, or `organization` for all of the organization's Free databases together), `unit` (`cu_hours` or `gb`, 1 GB being 1,073,741,824 bytes), `used` and `limit` in that unit, `percent`, `level` (`ok`, `warn` at the tick, `stopped`), `ticks` (percents the console marks), `stops_at` (where it stops, in the unit), `resets_at` (the 1st at 00:00 UTC for a monthly limit, the next 00:00 UTC for a daily one), `forecast_at` (when the month-to-date pace reaches the stop, only when that comes before the reset), `organization_used` (`null`) and `half_cap` (`false`). |
| `fair_use`, `allowance` | `null`. |
| `low_cu_hours` | `true` when the database or its organization has fewer than 10 CU-hours left this month: it runs at up to 0.5 CU so the last hours last longer. |
| `inactivity`, `idle_archive_days` | `idle_archive`: after `idle_archive_days` without connections it moves to backup storage (see `status`). |

The database's meters are `cu_hours`, `egress_project` and `archived_wal`; the organization's are `cu_hours_org`, `egress_org` and `wal_written_org`.

### Update a database

`PATCH /databases/{id}`

Send only the fields you want to change.

| Field | Type | Description |
| --- | --- | --- |
| `name` | string | New display name. Hostnames and the PostgreSQL database name don't change. |
| `plan` | string | Move to another plan; the data must fit the new plan. A Launch database moves back to `free` with all its branches when they fit Free, refused with `403 limit_reached` and every line that does not fit otherwise ([Moving back to Free](/docs/plans-and-billing#moving-back-to-free)); Scale and Dedicated move to `launch` first. A Free database moves with its whole family: sent for the database or any of its Free branches, the root and every Free branch move to the paid plan together and are each billed on it. A Free family with branches moves to `launch` first, then one database to `dedicated`. See [Change plan, size or topology](/docs/scaling#change-plan-size-or-topology). |
| `size`, `topology` | string | Dedicated only: a new size or topology, or the target of a move to Dedicated. |
| `scale_to_zero_minutes` | integer or `null` | Launch and Scale: idle minutes (1 or more) before it scales to zero, or `null` for always on. See [Scale to zero](/docs/scaling#scale-to-zero). |
| `on_limit` | string | Launch and Scale: at a hard spend limit, when one applies, `hold_min` (stay at the minimum, the default) or `suspend`. |
| `min_cu`, `max_cu` | number | Launch and Scale: the autoscaling range, each one of 0.25, 0.5, 1, 1.5, 2, 3, 4, 6, 8, 10, 12, 14 or 16, with `max_cu` at most 8 CU above `min_cu`, and at most 4 CU until the organization's first paid invoice. A new range restarts PostgreSQL once and must fit the spend limit. `max_cu` is at most what the elastic pool can give one database and `min_cu` at most what a server it runs or may buy starts (see [Autoscaling](/docs/scaling#the-range)); a larger value is refused with the most you can choose now. |
| `warm_floor` | boolean | Launch and Scale: keep the small warm size while idle (fast wakes, billed at its CU equivalent) or sleep at once (cold wakes). |
| `restore_window_days` | integer or `null` | Launch (1 to 7) and Scale (1 to 30): the days of history it keeps for point-in-time restore, or `null` for the plan's default. History above twice its billed storage is billed. |
| `pooler_enabled` | boolean | Turn the PgBouncer pooler on or off. |
| `read_replicas` | integer | 0 to 3. Launch, Scale and Dedicated only. |
| `ip_allowlist` | string array | Replaces the whole list. Up to 50 IPv4 or IPv6 addresses or CIDR ranges. `[]` allows all. |
| `deletion_protection` | boolean | Turn deletion protection on or off. Turn it off in its own request before deleting. Refused (`409`) while the database is protected. |
| `protected` | boolean | Launch, Scale and Dedicated: protect the database or branch. Turning it on also turns deletion protection on, removes a branch's expiry, sets `scale_to_zero_minutes` to `null` (always on, billed at least its minimum size every hour) and `on_limit` to `hold_min`; while protected, changes to those are refused. Turning it off leaves them as they are. See [Protected branches](/docs/branching#protected-branches). |
| `expires_at` | string or `null` | Branches only: when the branch deletes itself, at most 30 days ahead, or `null`. |
| `relocation` | string | Single-copy databases only: `relocate` or `wait`, what happens if their data center is lost. |
| `slow_query_ms` | integer or `null` | The slow query threshold for the [logs](#get-postgresql-logs), 100 to 60,000 ms, or `null` for the default 1,000 ms. Applied without a restart. |

```bash
curl -X PATCH https://keeldb.com/api/v1/databases/k7m2x9qa4pz1 \
  -H "Authorization: Bearer $KEELDB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"read_replicas": 1, "ip_allowlist": ["203.0.113.0/24"], "deletion_protection": true}'
```

Returns `200` with the updated database object. Plan, size, replica and pooler changes are applied in the background; watch `status`. A database that is being deleted returns `409 conflict`.

A change of `plan` between Free or Launch and Dedicated works like [Move to another plan](#move-to-another-plan): the answer carries a `tier_move` object when a move started (status `202`), or a `notice` when the change applied in place.

### Move to another plan

`POST /databases/{id}/move`

Moves a database between Free or Launch and Dedicated, or from Dedicated back to Launch, with the same id, hostnames and connection string. Send `plan`, and for Dedicated also `size` and `topology`.

Today Dedicated databases run on KeelDB's shared servers with their vCPU and memory reserved, so the change applies in place (one restart of PostgreSQL) and the answer is `200` with a `notice` that says so. Once Dedicated databases run on their own servers, the request starts a move instead: the data is copied to the target while the database keeps serving (about 1.5 hours per TB), then it switches over in seconds and the previous copy is kept for 24 hours. The answer is then `202` with the move:

| Field | Description |
| --- | --- |
| `id` | The move's id. |
| `state` | `requested`, `creating_target`, `copying`, `catching_up`, `cutover`, `rollback_window`, `done`, `cancelled` or `failed`; `state_text` says it in words. |
| `to`, `to_plan`, `to_size`, `to_topology` | Where it moves. |
| `estimated_copy_seconds`, `estimated_copy_text` | The estimate shown before you started it. |
| `lag_bytes` | While catching up: how far the target is behind. |
| `cutover_at`, `rollback_until` | When it switched over, and until when the previous copy is kept. |
| `cancellable` | Whether `DELETE` can still cancel it (before the switch-over). |
| `error` | Why a failed move did not complete. The database stays where it was. |

A database with branches, with snapshots or a backup schedule on, one that is not running, data that does not fit the target, or a second move while one is under way returns `409 conflict` or `422 invalid_input` with the reason. Dedicated moves to `launch` first; a Launch database moves back to `free` as with `PATCH`.

```bash
curl -X POST https://keeldb.com/api/v1/databases/k7m2x9qa4pz1/move \
  -H "Authorization: Bearer $KEELDB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"plan": "dedicated", "size": "std-2", "topology": "single"}'
```

`GET /databases/{id}/move` returns the latest move (or `null`), and `DELETE /databases/{id}/move` cancels a move before its switch-over. Cancelling a move to Dedicated after its servers exist bills their started hours, as for a Dedicated database deleted before it was ready. `GET /databases/{id}` shows a move under way as `tier_move`.

### Delete a database

`DELETE /databases/{id}`

Deletes the database: a Free, Launch or Scale database is stopped cleanly and its last write-ahead log kept in its backups (see [When you delete a database](/docs/backups-and-restore#when-you-delete-a-database)), then its servers, volumes and hostnames are destroyed. Its backups are kept for 7 days, then deleted. This can't be undone from the API. A database with branches returns `409 conflict` until its branches are deleted, and a database with deletion protection returns `409 conflict` until protection is turned off.

```bash
curl -X DELETE https://keeldb.com/api/v1/databases/k7m2x9qa4pz1 \
  -H "Authorization: Bearer $KEELDB_API_KEY"
```

Response `202 Accepted`:

```json
{ "data": { "id": "k7m2x9qa4pz1", "status": "deleting", "kept_until": null, "notice": null } }
```

Billing stops at the hour of the request. A Dedicated database deleted after its servers were created is billed for their started hours.

### Get connection details

`GET /databases/{id}/connection`

Returns the hosts, credentials and ready-to-use URIs, including the password. Each call is recorded in the audit log.

```bash
curl https://keeldb.com/api/v1/databases/k7m2x9qa4pz1/connection \
  -H "Authorization: Bearer $KEELDB_API_KEY"
```

```json
{
  "data": {
    "host": "k7m2x9qa4pz1.us-east.db.keeldb.com",
    "pooler_host": "k7m2x9qa4pz1-pooler.us-east.db.keeldb.com",
    "read_only_host": null,
    "port": 5432,
    "database": "shop",
    "user": "shop_owner",
    "password": "<password>",
    "uri": "postgresql://shop_owner:<password>@k7m2x9qa4pz1.us-east.db.keeldb.com:5432/shop?sslmode=require&connect_timeout=10",
    "pooler_uri": "postgresql://shop_owner:<password>@k7m2x9qa4pz1-pooler.us-east.db.keeldb.com:5432/shop?sslmode=require&connect_timeout=10",
    "read_only_uri": null
  }
}
```

`pooler_uri` uses the direct host when the pooler is off. `read_only_host` and `read_only_uri` are `null` for single-copy databases.

## Free usage

### Get Free usage

`GET /free-usage`

```bash
curl https://keeldb.com/api/v1/free-usage \
  -H "Authorization: Bearer $KEELDB_API_KEY"
```

Returns where the organization's Free databases stand this month: `limits`, `meters` (the organization's limits and, once they show, its Free allowance's), `fair_use` and `allowance`, as in a database's [`free_usage`](#get-a-database), and `databases`, each Free database with its own branches as one entry (`id`, `name`, `meters`, `low_cu_hours`), nearest to a limit first. An organization without Free databases gets an empty `databases` list.

## Branches

### List branches

`GET /databases/{id}/branches`

Returns the database's direct branches (not branches of branches) as database objects.

```bash
curl https://keeldb.com/api/v1/databases/k7m2x9qa4pz1/branches \
  -H "Authorization: Bearer $KEELDB_API_KEY"
```

### Create a branch

`POST /databases/{id}/branches`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | string | Yes | Same rules as a database name. |
| `plan` | string | No | Where the branch runs. By default: Free and Launch parents keep their plan; a Dedicated parent's branch runs on Launch when its data fits 100 GB, otherwise on one Dedicated `single` node of the smallest size that holds it. See [Branching](/docs/branching#where-a-branch-runs-and-what-it-costs). |
| `at` | string | No | ISO 8601 time with a `Z` or offset, for a point-in-time branch. Omit for a branch of the current state (instant on Free and Launch). |
| `expires_at` | string | No | ISO 8601 time, at most 30 days ahead, when the branch deletes itself. |

```bash
curl -X POST https://keeldb.com/api/v1/databases/k7m2x9qa4pz1/branches \
  -H "Authorization: Bearer $KEELDB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "before-bad-deploy", "at": "2026-10-07T08:29:00Z", "expires_at": "2026-10-14T08:29:00Z"}'
```

Response `201 Created`, with a new database object:

```json
{
  "data": {
    "id": "kq4w8e2r6t0y",
    "name": "before-bad-deploy",
    "status": "provisioning",
    "plan": "launch",
    "parent_id": "k7m2x9qa4pz1",
    "branch_point": "2026-10-07T08:29:00.000Z",
    "expires_at": "2026-10-14T08:29:00.000Z"
  }
}
```

Fields are trimmed here. Errors include `409 conflict` (parent not running), `403 limit_reached` (on Free: 5 branches per database, or a branch that would take the database and its branches past their shared 1 GB; a point-in-time branch counts all its data), `422 invalid_input` (a `free` plan for a branch of a paid database, a time outside the restore window, an expiry more than 30 days ahead, or not enough storage on the chosen plan) and `503 unavailable` (a Free branch while our shared servers have no room for it; nothing was created, try again in a few minutes). See [Branching](/docs/branching).

## Backups

### List backups

`GET /databases/{id}/backups`

Returns up to 100 backups, newest first.

```bash
curl https://keeldb.com/api/v1/databases/k7m2x9qa4pz1/backups \
  -H "Authorization: Bearer $KEELDB_API_KEY"
```

```json
{
  "data": [
    {
      "id": "k7m2x9qa4pz1-od-20261007093012-x7k2",
      "status": "completed",
      "method": "on-demand",
      "size_bytes": null,
      "started_at": "2026-10-07T09:30:12.000Z",
      "completed_at": "2026-10-07T09:31:40.000Z",
      "restore_test": null,
      "restore_tested_at": null
    }
  ]
}
```

| Field | Values |
| --- | --- |
| `status` | `running`, `completed` or `failed` |
| `method` | `scheduled` (daily), `on-demand`, or `base` |
| `size_bytes` | Size in bytes, or `null` when not reported |
| `restore_test` | `passed`, `failed`, or `null` if not tested yet |

## Snapshots

A snapshot keeps a database's data until you delete it, past the restore window. See [Snapshots](/docs/backups-and-restore#snapshots) for limits and prices.

### The snapshot object

```json
{
  "id": "snap_8h2k4m1q9x7c3v5b",
  "database_id": "k7m2x9qa4pz1",
  "name": "before-migration-42",
  "origin": "manual",
  "status": "ready",
  "taken_at": "2026-10-16T12:00:05.000Z",
  "size_bytes": 52428800,
  "error": null,
  "created_at": "2026-10-16T11:59:02.118Z"
}
```

| Field | Description |
| --- | --- |
| `origin` | `manual`, or the [schedule](#backup-schedule) that took it: `daily`, `weekly` or `monthly`. |
| `status` | `creating` (its backup runs), `ready` (restorable) or `failed` (see `error`; nothing is kept or billed). |
| `taken_at` | The moment a restore brings back: when its backup finished. `null` while `creating`. |
| `size_bytes` | The size of its backup in the backup storage, which is what is billed per GB-month on Launch and Dedicated. |

### List snapshots

`GET /databases/{id}/snapshots`

Newest first: snapshots being taken, ready ones, and failed ones from the last 7 days.

### Take a snapshot

`POST /databases/{id}/snapshots` with `{"name": "before-migration-42"}`

`name` is 1 to 63 letters, numbers, spaces, dots, colons, dashes or underscores, unique among the database's snapshots. Returns `202` with the snapshot in `creating`; poll [Get a snapshot](#get-a-snapshot) until it is `ready`. Errors: `409 conflict` (the name is taken, the database is not running, is being deleted, runs on Dedicated servers of its own, or is moving to another plan and has not switched over yet), `403 limit_reached` (Free keeps 1 manual snapshot per database, Launch and Dedicated 100; on Launch, the snapshot's storage for the rest of the month would pass the organization's hard spend limit, when one applies).

### Get a snapshot

`GET /databases/{id}/snapshots/{snapshot_id}`

### Restore a snapshot

`POST /databases/{id}/snapshots/{snapshot_id}/restore`

| Field | Type | Description |
| --- | --- | --- |
| `target` | string | `branch`: a new branch of the database. `database`: a new database on the same plan, region and PostgreSQL version. |
| `name` | string | The new database's display name. |

```bash
curl -X POST https://keeldb.com/api/v1/databases/k7m2x9qa4pz1/snapshots/snap_8h2k4m1q9x7c3v5b/restore \
  -H "Authorization: Bearer $KEELDB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"target": "database", "name": "shop-before-migration"}'
```

Returns `201` with the new database object (`restored_from` names the snapshot). It is `provisioning` until the restore is done. The same limits and billing apply as for a new [branch](/docs/branching) or [database](#create-a-database).

### Delete a snapshot

`DELETE /databases/{id}/snapshots/{snapshot_id}`

Returns `202`. The snapshot is no longer listed or billed from now on; copies that finished restoring from it stay. While a copy restored from it has not started yet (its `status` is still `provisioning`, or `error` after a failed restore), the deletion is refused with `409 conflict`: delete the snapshot once the copy runs, or delete the copy first.

## Backup schedule

### Get the schedule

`GET /databases/{id}/backup-schedule`

```json
{
  "data": {
    "daily": { "enabled": true, "keep": 7, "next_run_at": "2026-10-17T03:00:00.000Z" },
    "weekly": { "enabled": false, "keep": 4, "next_run_at": null },
    "monthly": { "enabled": true, "keep": 12, "next_run_at": "2026-11-01T03:00:00.000Z" },
    "hour_utc": 3,
    "weekday": 0,
    "month_day": 1
  }
}
```

### Set the schedule

`PUT /databases/{id}/backup-schedule`

Launch and Dedicated. Send only what changes; every other field keeps its value.

| Field | Type | Description |
| --- | --- | --- |
| `daily`, `weekly`, `monthly` | object | `enabled` (boolean) and `keep`, how many of that schedule's snapshots are kept: daily 1 to 35, weekly 1 to 26, monthly 1 to 24. The oldest beyond the count is deleted. |
| `hour_utc` | integer | 0 to 23: when every enabled schedule runs. |
| `weekday` | integer | 0 (Sunday) to 6: the weekly schedule's day. |
| `month_day` | integer | 1 to 28: the monthly schedule's day. |

Returns the schedule. `422 invalid_input` names what is out of range; a schedule on Free is refused. Turning a schedule on while the database is moving to another plan and has not switched over yet returns `409 conflict`.

## Operations and jobs

### Start an operation

`POST /databases/{id}/operations`

| Field | Type | Description |
| --- | --- | --- |
| `kind` | string | `restart`, `failover`, `backup` or `rotate_password` |

| Kind | Effect |
| --- | --- |
| `restart` | Restarts PostgreSQL. Open sessions get 15 seconds to finish, then new connections are refused until it is back, usually within a minute (the database's `status` is `restarting` meanwhile). With a standby or read replica, KeelDB switches over to it first, so writes pause only briefly. The job is `done` once the database serves again. While one of its instances is not running (a standby or read replica still starting, or down), a restart is refused (the job fails at once and nothing is restarted): try again once every instance runs. |
| `failover` | Promotes a standby or read replica to primary. Needs one that is running. The job is `done` once the database serves again. |
| `backup` | Takes a full base backup. The database stays online. The job is `done` once the backup has completed. |
| `rotate_password` | Sets a new password. The job is `done` once the new password works, usually within seconds; until then the current password keeps working and is the one the connection details return. From then on the old one stops working. |

```bash
curl -X POST https://keeldb.com/api/v1/databases/k7m2x9qa4pz1/operations \
  -H "Authorization: Bearer $KEELDB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"kind": "backup"}'
```

Response `202 Accepted`:

```json
{ "data": { "job_id": "job_3k9x0m2q7c1v8b4n", "status": "queued" } }
```

- The database must be `ready`, except for `rotate_password`, which works in any state. Otherwise you get `409 conflict`.
- If the same kind of operation is already queued or running for this database, you get that job's id back instead of a new job.

### Get a job

`GET /jobs/{job_id}`

```bash
curl https://keeldb.com/api/v1/jobs/job_3k9x0m2q7c1v8b4n \
  -H "Authorization: Bearer $KEELDB_API_KEY"
```

```json
{
  "data": {
    "id": "job_3k9x0m2q7c1v8b4n",
    "kind": "backup",
    "status": "done",
    "error": null,
    "result": { "backupId": "k7m2x9qa4pz1-od-20261007093012-x7k2", "status": "completed", "sizeBytes": null },
    "created_at": "2026-10-07T09:30:11.204Z",
    "finished_at": "2026-10-07T09:30:12.031Z"
  }
}
```

| `status` | Meaning |
| --- | --- |
| `queued` | Waiting to run, or waiting to be retried. |
| `running` | In progress. |
| `done` | Finished. `result` holds details where there are any. |
| `failed` | Gave up. `error` says why. |

A job that hits an error is retried up to 3 attempts in total, so `error` can be set while the status is back to `queued`. `error` is a plain explanation; internal error details stay with KeelDB. Treat only `done` and `failed` as final. A job is `done` when what it asked for has happened: the restart or failover has finished, the backup has completed, the new password works. A backup still running after 12 hours ends its job as `done` with `"status": "running"` in `result`; follow it in [List backups](#list-backups).

### Polling pattern

```bash
job=$(curl -fsS -X POST https://keeldb.com/api/v1/databases/k7m2x9qa4pz1/operations \
  -H "Authorization: Bearer $KEELDB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"kind": "restart"}' | jq -r '.data.job_id')

while true; do
  status=$(curl -fsS "https://keeldb.com/api/v1/jobs/$job" \
    -H "Authorization: Bearer $KEELDB_API_KEY" | jq -r '.data.status')
  case "$status" in
    done) echo "Restarted"; break ;;
    failed) echo "Restart failed"; exit 1 ;;
  esac
  sleep 3
done
```

Poll every few seconds; the rate limit leaves plenty of room. The same pattern works for database creation, using `GET /databases/{id}` and `status: "ready"`.

## SQL

### Run a query

`POST /databases/{id}/query`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `sql` | string | Yes | One or more statements, up to 200 KB. |
| `read_only` | boolean | No | Default `false`. When `true`, one statement runs, in a read-only transaction that is never committed, on a read-only instance if the database has one. A script of several statements answers `422 invalid_input`. |

```bash
curl -X POST https://keeldb.com/api/v1/databases/k7m2x9qa4pz1/query \
  -H "Authorization: Bearer $KEELDB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"sql": "select id, title from todos order by id", "read_only": true}'
```

```json
{
  "data": {
    "results": [
      {
        "command": "SELECT",
        "rowCount": 2,
        "fields": [{ "name": "id", "type": 20 }, { "name": "title", "type": 25 }],
        "rows": [["1", "Read the KeelDB docs"], ["2", "Ship the app"]],
        "truncated": false
      }
    ],
    "durationMs": 4
  }
}
```

- The query runs as the database's owner role with a 30 second statement timeout.
- `results` has one entry per statement. Each returns at most 500 rows (`truncated` tells you if there were more), and long values are cut at 2,000 characters.
- A request with a single statement stops it after 501 rows, as a cursor would, and its `rowCount` is then `null`. A `SELECT` that calls a function which changes data runs it for those rows only, so process large sets in batches (`LIMIT`) or from your own client. `INSERT`, `UPDATE`, `DELETE` and `MERGE` with `RETURNING` still change every row they match.
- A request reads at most 8 MiB from the database, on every plan. A larger result is not returned: KeelDB closes the connection and `error.message` says the result was cut. On Free, these reads go through the proxy and count in the project's egress.
- `fields[].type` is the PostgreSQL type OID. `bigint` values come back as strings.
- Multiple statements run in one implicit transaction unless you use `BEGIN`/`COMMIT`.
- SQL errors are not HTTP errors. The response is `200` with an empty `results` and an `error` object:

```json
{
  "data": {
    "results": [],
    "durationMs": 2,
    "error": { "message": "relation \"todo\" does not exist", "code": "42P01", "position": "19" }
  }
}
```

`error` can also include `hint` and `detail`. A sleeping Free or Launch database returns `409 conflict` and starts waking up; retry shortly. Every run is recorded in the audit log.

## Extensions

See [Extensions](/docs/extensions) for what each one does.

### List the catalog

`GET /extensions?postgres_version=18` (public)

Every extension KeelDB offers, with `install` set to `self` (run `CREATE EXTENSION` yourself) or `managed` (enable it through KeelDB first), its version per PostgreSQL major, `requires`, `needs_restart`, `available` and `paid_only` (Launch and Dedicated only: `dblink` and `postgres_fdw`, which send data to other servers directly). `postgres_version` is optional and narrows the list to one major.

### Extensions of a database

`GET /databases/{id}/extensions`

Returns `postgres_version`, `enabled` (the managed extensions KeelDB installs), `installed` (what the database has right now, or `null` while it sleeps or starts) and the catalog for its PostgreSQL major, each entry with `status` `installed`, `enabled` or `available`.

### Enable a managed extension

`POST /databases/{id}/extensions`

```bash
curl -X POST https://keeldb.com/api/v1/databases/k7m2x9qa4pz1/extensions \
  -H "Authorization: Bearer $KEELDB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "postgis"}'
```

Response `202 Accepted` with `{"data": {"enabled": ["postgis"], "database": <database object>}}`; managed extensions it requires are enabled with it. KeelDB installs them within a minute or two. Enabling one that is already on returns `200` with an empty `enabled`.

### Disable a managed extension

`DELETE /databases/{id}/extensions/{name}`

KeelDB drops the extension. Refused with `409 conflict` while objects in the database use it, while another enabled extension needs it, or while the database is not running.

## Metrics

### Get metrics

`GET /databases/{id}/metrics?range=24h`

| Query parameter | Values |
| --- | --- |
| `range` | `1h`, `24h` (default), `3d`, `7d`, `14d` or `30d`, on every plan |

```bash
curl "https://keeldb.com/api/v1/databases/k7m2x9qa4pz1/metrics?range=1h" \
  -H "Authorization: Bearer $KEELDB_API_KEY"
```

```json
{
  "data": [
    { "t": "2026-10-07T09:00:04.000Z", "storageBytes": 52428800, "connections": 4, "tps": null },
    { "t": "2026-10-07T09:05:04.000Z", "storageBytes": 52445184, "connections": 6, "tps": 12.47 }
  ]
}
```

One point every 5 minutes while the database runs:

| Field | Description |
| --- | --- |
| `t` | When the sample was taken. |
| `storageBytes` | Size of the database in bytes (`pg_database_size`: tables, indexes and their free space, without the write-ahead log). |
| `connections` | Sessions on the primary at the sample. A client of the connection pooler is not one: the pooler's server connections are, which its clients share and which stay open for 60 seconds after their last use (10 minutes on a database that never sleeps). Read replicas and KeelDB's own monitoring sessions are not counted. |
| `tps` | Committed transactions per second on the primary over the 5 minutes since the previous point. `null` for the first point of the range, when the two points are more than 5.5 minutes apart (the database slept or was stopped in between), and when PostgreSQL restarted, woke up, failed over to a standby or had its statistics reset in between: the counters then start from another value. |

### Get CPU, memory and cache metrics

`GET /databases/{id}/metrics/compute?range=24h`

The primary's CPU and memory, used against what it is allocated, its cache hit ratio, sessions and commits per second, measured every minute while the database runs. Read replicas are not included. `range` is `1h`, `24h` (default), `3d`, `7d`, `14d` or `30d` on every plan (another value returns `422 invalid_input`); points are 1 minute, 5 minutes, 15 minutes, 30 minutes and 1 hour apart (`bucketSeconds`; 1 hour for both `14d` and `30d`). A point longer than a minute averages the minutes the database ran in it.

```bash
curl "https://keeldb.com/api/v1/databases/k7m2x9qa4pz1/metrics/compute?range=24h" \
  -H "Authorization: Bearer $KEELDB_API_KEY"
```

```json
{
  "data": {
    "range": "24h",
    "bucketSeconds": 300,
    "points": [
      { "t": "2026-10-07T09:00:00.000Z", "cpuUsedMillicores": 140, "cpuPeakMillicores": 310, "cpuAllocatedMillicores": 500, "memoryUsedBytes": 402653184, "memoryPeakBytes": 419430400, "memoryAllocatedBytes": 2147483648, "cacheHitRatio": 0.998, "connections": 4, "tps": 12.5 }
    ]
  }
}
```

| Field | Description |
| --- | --- |
| `t` | Start of the point (UTC), its first minute. Each minute is read a few seconds after it ends: its commits and block reads are the increase between two reads, and its CPU and memory the averages of the metrics API windows that ended between them. |
| `cpuUsedMillicores`, `cpuPeakMillicores` | CPU the primary used, in millicores (1,000 is one vCPU): the average over the minutes the point measured, and its highest one-minute average. Each minute averages the Kubernetes metrics API's 15-second windows of that minute. On a 1-minute point both are the same. |
| `cpuAllocatedMillicores` | CPU allocated to the primary: on Free and Launch its current size (50 at the warm size), on Dedicated the size's vCPU. The point's highest. Free and Launch can use idle cores above it. |
| `memoryUsedBytes`, `memoryPeakBytes` | The primary's working set (memory in use, including file cache it used recently), in bytes: the average over the point and its highest minute. |
| `memoryAllocatedBytes` | Memory allocated to the primary, in bytes: on Free and Launch its memory limit, on Dedicated the size's RAM (the primary has its server to itself, with no memory limit inside it). The point's highest. |
| `cacheHitRatio` | Share of block reads found in shared buffers, from 0 to 1, or `null` when the point has no reads. |
| `connections` | Sessions on the primary when each minute was read; the point's highest. A client of the connection pooler is not one: the pooler's server connections are, which its clients share and which stay open for 60 seconds after their last use (10 minutes on a database that never sleeps). Read replicas and KeelDB's own monitoring sessions are not counted. |
| `tps` | Committed transactions per second on the primary over the point's minutes (read-only transactions count, rollbacks do not; read replicas are not counted). Minutes without a count are left out of the average rather than counted as zero: minutes asleep, and the first minute after a restart or a failover, whose counters start from another value. The first minute after a wake-up has its count. |

A sleeping or suspended database has no points for that time: sampling never wakes it, and a longer point averages only the minutes the database ran. Sizes are in bytes; the console shows them in binary units (1 GB is 1,073,741,824 bytes).

## Metrics and logs export

Scale only: push a database's minute metrics and its PostgreSQL logs to your own OpenTelemetry collector (Grafana, Datadog, Honeycomb or any OTLP endpoint), every minute, as OTLP over HTTPS to its `/v1/metrics` and `/v1/logs`. The endpoint must be `https` on a public host; headers, such as an API key, are kept encrypted and never shown back. After a failed push the next one waits longer each time, up to an hour, and `last_error` says why.

### Get the export

`GET /databases/{id}/telemetry-export`

```json
{
  "data": {
    "endpoint": "https://otlp.example.com:4318",
    "signals": ["metrics", "logs"],
    "enabled": true,
    "header_names": ["x-api-key"],
    "last_ok_at": "2026-12-10T12:01:05.000Z",
    "last_error": null,
    "failures": 0,
    "retry_at": null
  }
}
```

`data` is `null` when no export is set.

### Set the export

`PUT /databases/{id}/telemetry-export` with `endpoint`, optional `signals` (`["metrics", "logs"]` by default), `headers` (an object; it replaces the headers set, `{}` removes them, leaving it out keeps them) and `enabled`.

```bash
curl -X PUT https://keeldb.com/api/v1/databases/k7m2x9qa4pz1/telemetry-export \
  -H "Authorization: Bearer $KEELDB_API_KEY" -H "Content-Type: application/json" \
  -d '{"endpoint": "https://otlp.example.com:4318", "headers": {"x-api-key": "..."}}'
```

### Remove the export

`DELETE /databases/{id}/telemetry-export` returns `{ "data": { "deleted": true } }`.

## Logs

### Get PostgreSQL logs

`GET /databases/{id}/logs`

The database's PostgreSQL logs, newest first: errors and warnings, statements slower than the database's `slow_query_ms`, and sessions being authorized and ending. Records are kept for the plan's window: 1 day on Free, 3 days on Launch, 14 days on Dedicated, up to a number of records a minute and in all per plan. See [PostgreSQL logs](/docs/observability#postgresql-logs) for what is kept, what is left out and the limits.

| Query parameter | Values |
| --- | --- |
| `kind` | `error`, `slow_query` or `connection`, several separated by commas. All by default. |
| `since`, `until` | ISO 8601 times with `Z` or an offset. `since` earlier than the plan's window starts at the window. |
| `min_duration_ms` | Slow queries that ran at least this long. |
| `search` | Text in the message or the statement, case-insensitive, up to 200 characters. |
| `limit` | Records per page, 1 to 500. Default 100. |
| `cursor` | The `next_cursor` of the previous page, for older records. |

```bash
curl "https://keeldb.com/api/v1/databases/k7m2x9qa4pz1/logs?kind=error,slow_query&limit=2" \
  -H "Authorization: Bearer $KEELDB_API_KEY"
```

```json
{
  "data": {
    "records": [
      {
        "id": 8121,
        "at": "2026-10-16T09:12:44.512Z",
        "kind": "error",
        "severity": "ERROR",
        "sql_state": "42P01",
        "message": "relation \"todo\" does not exist",
        "detail": null,
        "hint": null,
        "statement": "select * from todo",
        "duration_ms": null,
        "user": "shop_owner",
        "database": "shop",
        "application": "api",
        "instance": "k7m2x9qa4pz1-1"
      },
      {
        "id": 8119,
        "at": "2026-10-16T09:10:02.004Z",
        "kind": "slow_query",
        "severity": "LOG",
        "sql_state": null,
        "message": "Statement ran for 1532.118 ms",
        "detail": null,
        "hint": null,
        "statement": "select pg_sleep(1.5)",
        "duration_ms": 1532.118,
        "user": "shop_owner",
        "database": "shop",
        "application": "api",
        "instance": "k7m2x9qa4pz1-1"
      }
    ],
    "next_cursor": "MjAyNi0xMC0xNlQwOToxMDowMi4wMDRafDgxMTk",
    "window_start": "2026-10-13T09:15:00.000Z",
    "retention_days": 3,
    "slow_query_ms": 1000
  }
}
```

| Field | Description |
| --- | --- |
| `kind` | `error`, `slow_query` or `connection`. |
| `severity` | PostgreSQL's severity: `WARNING`, `ERROR`, `FATAL` or `PANIC` for errors, `LOG` for the others. |
| `sql_state` | The SQLSTATE error code, or `null`. |
| `message` | PostgreSQL's message for errors; for slow queries and connections a short text KeelDB writes from the record. A minute that logged more than the plan keeps gets one `WARNING` record from KeelDB (instance `keeldb`, no user) that says how many of its records were not kept. |
| `statement` | The statement that failed or ran slowly, with passwords replaced by `[redacted]`, or `null`. |
| `duration_ms` | Slow queries: how long the statement ran. |
| `user`, `database`, `application` | The session's role, database and `application_name`. SQL run through [`query`](#run-a-query), MCP or the CLI shows as `keeldb-sql`, and a client that sets no `application_name` as `keeldb-proxy`. |
| `instance` | The instance that wrote the record: `<id>-<n>`, or `<id>-d<k>-<n>` on Dedicated (`k` counts the database's deployments, so a move between plans shows a new one). |
| `next_cursor` | Pass it as `cursor` for the next, older page; `null` on the last page. |
| `window_start` | The oldest time the plan's window shows. |

An unknown `kind`, a time without a zone, a `limit` outside 1 to 500 or a cursor this API did not return is `422 invalid_input`.
