Skip to content

Managed database

Managed Postgres on infrai's own self-operated database fleet: provision projects, copy-on-write branches and point-in-time snapshots behind one key.

1. Overview

Base path: https://api.infrai.cc/v1/db
Auth header: Authorization: Bearer $INFRAI_API_KEY
bash
# Call any /v1/db capability over raw HTTP — no SDK to install.
# curl:
curl https://api.infrai.cc/v1/db/... \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json"

2. Methods (12)

2.1db.project.create

POST /v1/db/project/create

Provision a managed Postgres project on infrai's self-operated database fleet.

Parameters

NameTypeRequiredDescription
namestring
Required
Database project name.
≥ 1 chars
vendor"tencent_pg" | nullOptionalOptional explicit vendor pin.
regionstringOptionalRegion to provision in.
default: "us-east-1"
plan"hobby" | "pro" | "scale"OptionalProvisioning plan / size.
default: "hobby"
mode"default_vendor" | "verified_account"OptionalProvisioning mode — managed.
default: "default_vendor"
postgres_versionstringOptionalPostgres major version.
default: "15"
idempotency_keystringOptionalClient-supplied key to make the call idempotent.

Returns

Project { id, name, region, connection_uri, created_at }
NameTypeDescription
project_idstringUnique identifier for the parent db project
db_idstringUnique identifier for this database instance
pattern: ^dbi_[A-Za-z0-9]{20,}$
namestringHuman-readable name for this resource
vendorstringVendor that handled or will handle this request
regionstring | nullGeographic region where this resource is located or processed
plan"hobby" | "pro" | "scale"Pricing plan for the database instance
state"provisioning" | "active" | "paused" | "deleting" | "deleted" | "failed"Current lifecycle state of this resource
postgres_versionstring | nulle.g. "15.4".
created_atstringISO 8601 timestamp when this resource was created
format: date-time
primary_branchstring | nullName of the primary branch
default: "main"
mode"default_vendor" | "verified_account"Delivery mode or operation mode
vendor_db_idstringVendor-side identifier for the physical database
metadataobjectRequest accounting metadata captured at creation time
metadata.request_idstring-
metadata.timestampstring-
format: date-time
metadata.latency_msinteger-
≥ 0
metadata.entry_formstring-
metadata.cost_usdnumber-
metadata.vendorstring-
metadata.vendor_regionstring-
metadata.markup_pctnumber-
metadata.trace_idstring-
metadata.modestring-

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/db/project/create \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "example"}'

2.2db.project.get

GET /v1/db/project/get/{project_id}

Fetch a managed database project by id, including its connection URI.

Parameters

NameTypeRequiredDescription
idstring
Required
The project id.

Returns

Project
NameTypeDescription
project_idstringUnique identifier for the parent db project
db_idstringUnique identifier for this database instance
pattern: ^dbi_[A-Za-z0-9]{20,}$
namestringHuman-readable name for this resource
vendorstringVendor that handled or will handle this request
regionstring | nullGeographic region where this resource is located or processed
plan"hobby" | "pro" | "scale"Pricing plan for the database instance
state"provisioning" | "active" | "paused" | "deleting" | "deleted" | "failed"Current lifecycle state of this resource
postgres_versionstring | nulle.g. "15.4".
created_atstringISO 8601 timestamp when this resource was created
format: date-time
primary_branchstring | nullName of the primary branch
default: "main"
mode"default_vendor" | "verified_account"Delivery mode or operation mode
vendor_db_idstringVendor-side identifier for the physical database
metadataobjectRequest accounting metadata captured at creation time
metadata.request_idstring-
metadata.timestampstring-
format: date-time
metadata.latency_msinteger-
≥ 0
metadata.entry_formstring-
metadata.cost_usdnumber-
metadata.vendorstring-
metadata.vendor_regionstring-
metadata.markup_pctnumber-
metadata.trace_idstring-
metadata.modestring-

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/db/project/get/PROJECT_ID \
  -H "Authorization: Bearer $INFRAI_API_KEY"

2.3db.project.list

GET /v1/db/project/list

List the managed database projects for the account.

Parameters

NameTypeRequiredDescription
cursorstringOptionalOpaque pagination cursor.
limitnumberOptionalMaximum number of items to return.

Returns

{ items: Project[], next_cursor?: string }
NameTypeDescription
itemsobject[]List of database project records
next_cursorstring | nullCursor for next page; null if last page
totalintegerTotal number of db projects for this account
≥ 0

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/db/project/list \
  -H "Authorization: Bearer $INFRAI_API_KEY"

2.4db.project.delete

DELETE /v1/db/project/delete/{project_id}

Delete a managed database project and all its branches/snapshots.

Parameters

NameTypeRequiredDescription
idstring
Required
The project id.

Returns

{ ok: boolean }
NameTypeDescription
project_idstringUnique identifier for the parent db project
db_idstringUnique identifier for this database instance
pattern: ^dbi_[A-Za-z0-9]{20,}$
namestringHuman-readable name for this resource
vendorstringVendor that handled or will handle this request
regionstring | nullGeographic region where this resource is located or processed
plan"hobby" | "pro" | "scale"Pricing plan for the database instance
state"provisioning" | "active" | "paused" | "deleting" | "deleted" | "failed"Current lifecycle state of this resource
postgres_versionstring | nulle.g. "15.4".
created_atstringISO 8601 timestamp when this resource was created
format: date-time
primary_branchstring | nullName of the primary branch
default: "main"
mode"default_vendor" | "verified_account"Delivery mode or operation mode
vendor_db_idstringVendor-side identifier for the physical database
metadataobjectRequest accounting metadata captured at creation time
metadata.request_idstring-
metadata.timestampstring-
format: date-time
metadata.latency_msinteger-
≥ 0
metadata.entry_formstring-
metadata.cost_usdnumber-
metadata.vendorstring-
metadata.vendor_regionstring-
metadata.markup_pctnumber-
metadata.trace_idstring-
metadata.modestring-

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X DELETE https://api.infrai.cc/v1/db/project/delete/PROJECT_ID \
  -H "Authorization: Bearer $INFRAI_API_KEY"

2.5db.branch.create

POST /v1/db/branch/create

Create a copy-on-write branch of a project for previews or testing.

Parameters

NameTypeRequiredDescription
project_idstring
Required
The project id.
branch_namestring
Required
Name for the new branch.
≥ 1 chars
from_branchstringOptionalSource branch to clone from.
default: "main"
idempotency_keystringOptionalClient-supplied key to make the call idempotent.

Returns

Branch { id, branch_name, project_id, connection_uri }
NameTypeDescription
db_idstringUnique identifier for this database instance
pattern: ^dbi_[A-Za-z0-9]{20,}$
branch_namestringName of the database branch
parentstring | nullParent branch name
default: "main"
created_atstringISO 8601 timestamp when this resource was created
format: date-time
state"creating" | "active" | "promoting" | "failed" | "deleted"Current lifecycle state of this resource

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/db/branch/create \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"project_id": "sample", "branch_name": "example"}'

2.6db.branch.get

GET /v1/db/branch/get/{project_id}

Fetch a database branch by id, including its connection URI.

Parameters

NameTypeRequiredDescription
idstring
Required
The branch id.

Returns

Branch
NameTypeDescription
db_idstringUnique identifier for this database instance
pattern: ^dbi_[A-Za-z0-9]{20,}$
branch_namestringName of the database branch
parentstring | nullParent branch name
default: "main"
created_atstringISO 8601 timestamp when this resource was created
format: date-time
state"creating" | "active" | "promoting" | "failed" | "deleted"Current lifecycle state of this resource

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/db/branch/get/PROJECT_ID \
  -H "Authorization: Bearer $INFRAI_API_KEY"

2.7db.branch.list

GET /v1/db/branch/list

List the branches of a managed database project.

Parameters

NameTypeRequiredDescription
project_idstringOptionalThe project id.
cursorstringOptionalOpaque pagination cursor.
limitnumberOptionalMaximum number of items to return.

Returns

{ items: Branch[], next_cursor?: string }
NameTypeDescription
itemsobject[]List of database branch records
next_cursorstring | nullCursor for next page; null if last page

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/db/branch/list \
  -H "Authorization: Bearer $INFRAI_API_KEY"

2.8db.branch.delete

DELETE /v1/db/branch/delete/{project_id}

Delete a database branch.

Parameters

NameTypeRequiredDescription
idstring
Required
The branch id.

Returns

{ ok: boolean }
NameTypeDescription
db_idstringUnique identifier for this database instance
pattern: ^dbi_[A-Za-z0-9]{20,}$
branch_namestringName of the database branch
parentstring | nullParent branch name
default: "main"
created_atstringISO 8601 timestamp when this resource was created
format: date-time
state"creating" | "active" | "promoting" | "failed" | "deleted"Current lifecycle state of this resource

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X DELETE https://api.infrai.cc/v1/db/branch/delete/PROJECT_ID \
  -H "Authorization: Bearer $INFRAI_API_KEY"

2.9db.snapshot.create

POST /v1/db/snapshot/create

Take a point-in-time snapshot of a managed database project.

Parameters

NameTypeRequiredDescription
project_idstring
Required
The project id.
labelstringOptionalHuman-readable snapshot label.
idempotency_keystringOptionalClient-supplied key to make the call idempotent.

Returns

Snapshot { id, project_id, label?, created_at }
NameTypeDescription
snapshot_idstringUnique identifier for this snapshot
project_idstringIdentifier of the db project this snapshot belongs to
db_idstringUnique identifier for this database instance
labelstring | nullRisk label (e.g. low, medium, high)
size_bytesinteger | nullSize of the resource in bytes
≥ 0
created_atstringISO 8601 timestamp when this resource was created
format: date-time
state"creating" | "ready" | "restoring" | "failed" | "expired"Current lifecycle state of this resource
vendorstringVendor that handled the underlying database (present on db.snapshot.get)
_tierstringStorage retention tier stamped by the asset store (present on db.snapshot.get)
expires_atstringISO 8601 expiry timestamp for the stored dump (present on db.snapshot.get)
format: date-time
_account_idstringOwning account identifier stamped by the asset store (present on db.snapshot.get)

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/db/snapshot/create \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"project_id": "sample"}'

2.10db.snapshot.get

GET /v1/db/snapshot/get/{snapshot_id}

Fetch a database snapshot by id.

Parameters

NameTypeRequiredDescription
idstring
Required
The snapshot id.

Returns

Snapshot
NameTypeDescription
snapshot_idstringUnique identifier for this snapshot
project_idstringIdentifier of the db project this snapshot belongs to
db_idstringUnique identifier for this database instance
labelstring | nullRisk label (e.g. low, medium, high)
size_bytesinteger | nullSize of the resource in bytes
≥ 0
created_atstringISO 8601 timestamp when this resource was created
format: date-time
state"creating" | "ready" | "restoring" | "failed" | "expired"Current lifecycle state of this resource
vendorstringVendor that handled the underlying database (present on db.snapshot.get)
_tierstringStorage retention tier stamped by the asset store (present on db.snapshot.get)
expires_atstringISO 8601 expiry timestamp for the stored dump (present on db.snapshot.get)
format: date-time
_account_idstringOwning account identifier stamped by the asset store (present on db.snapshot.get)

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/db/snapshot/get/SNAPSHOT_ID \
  -H "Authorization: Bearer $INFRAI_API_KEY"

2.11db.snapshot.list

GET /v1/db/snapshot/list

List the snapshots of a managed database project.

Parameters

NameTypeRequiredDescription
project_idstringOptionalThe project id.
cursorstringOptionalOpaque pagination cursor.
limitnumberOptionalMaximum number of items to return.

Returns

{ items: Snapshot[], next_cursor?: string }
NameTypeDescription
itemsobject[]List of snapshot records
next_cursorstring | nullCursor for next page; null if last page

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/db/snapshot/list \
  -H "Authorization: Bearer $INFRAI_API_KEY"

2.12db.snapshot.restore

POST /v1/db/snapshot/restore/{snapshot_id}

Restore a snapshot into a new managed database project.

Parameters

NameTypeRequiredDescription
snapshot_idstring
Required
The snapshot id.
new_namestringOptionalName for the restored project (defaults to the source name with a -restored suffix).
idempotency_keystringOptionalClient-supplied key to make the call idempotent.

Returns

Project { id, name, connection_uri }
NameTypeDescription
project_idstringUnique identifier for the newly-registered db project
db_idstringUnique identifier for this database instance
pattern: ^dbi_[A-Za-z0-9]{20,}$
namestringHuman-readable name for this resource (defaults to source name + _restored)
vendorstringVendor that handled or will handle this request
regionstring | nullGeographic region where this resource is located or processed
plan"hobby" | "pro" | "scale"Pricing plan for the database instance
postgres_versionstring | nulle.g. "15.4".
state"provisioning" | "active" | "paused" | "deleting" | "deleted" | "failed"Current lifecycle state of this resource
primary_branchstring | nullName of the primary branch
default: "main"
created_atstringISO 8601 timestamp when this resource was created
format: date-time
mode"default_vendor" | "verified_account"Delivery mode or operation mode
vendor_db_idstringVendor-side identifier for the restored physical database
metadataobjectRequest accounting metadata; absent on a restore (only set at original project create time)
metadata.request_idstring-
metadata.timestampstring-
format: date-time
metadata.latency_msinteger-
≥ 0
metadata.entry_formstring-
metadata.cost_usdnumber-
metadata.vendorstring-
metadata.vendor_regionstring-
metadata.markup_pctnumber-
metadata.trace_idstring-
metadata.modestring-

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/db/snapshot/restore/SNAPSHOT_ID \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"snapshot_id": "sample"}'
Advanced: pin a vendor

By default infrai routes each call to the best available provider — you do not pick a vendor. As an escape hatch, this capability accepts an optional vendor parameter to pin one specific provider. Every live vendor for this capability is available in real time from the discovery endpoint for the capability id — see the discovery API.

GET /v1/discovery/{capability}

db.project.create

3. All capabilities

Every routed capability in this module — the complete public REST contract. The methods above are the guided walkthrough; this index is the full reference.

db.branch.createPOST /v1/db/branch/create

db branch create — managed database (Neon/Supabase/PlanetScale).

Parameters (4)
NameTypeRequiredDescription
project_idstringRequiredParent project id.
branch_namestringRequiredName of the database branch
≥ 1 chars
from_branchstringOptionalSource branch to clone from.
default: "main"
idempotency_keystring | nullOptionalClient-provided idempotency key; prevents duplicate execution on retry
db.branch.deleteDELETE /v1/db/branch/delete/{project_id}

db branch delete — managed database (Neon/Supabase/PlanetScale).

Parameters (1)
NameTypeRequiredDescription
project_idstringRequiredPath parameter.
db.branch.getGET /v1/db/branch/get/{project_id}

db branch get — managed database (Neon/Supabase/PlanetScale).

Parameters (1)
NameTypeRequiredDescription
project_idstringRequiredPath parameter.
db.branch.listGET /v1/db/branch/list

db branch list — managed database (Neon/Supabase/PlanetScale).

No request parameters.

db.project.createPOST /v1/db/project/create

db project create — managed database (Neon/Supabase/PlanetScale).

Parameters (7)
NameTypeRequiredDescription
namestringRequiredHuman-readable name for this resource
≥ 1 chars
vendor"tencent_pg" | nullOptionalExplicit vendor pin (db is self-operated: tencent_pg only).
regionstringOptionalGeographic region where this resource is located or processed
default: "us-east-1"
plan"hobby" | "pro" | "scale"OptionalPricing plan for the database instance
default: "hobby"
mode"default_vendor" | "verified_account"OptionalDelivery mode or operation mode
default: "default_vendor"
postgres_versionstringOptionalPostgreSQL version for the database
default: "15"
idempotency_keystring | nullOptionalClient-provided idempotency key; prevents duplicate execution on retry
db.project.deleteDELETE /v1/db/project/delete/{project_id}

db project delete — managed database (Neon/Supabase/PlanetScale).

Parameters (1)
NameTypeRequiredDescription
project_idstringRequiredPath parameter.
db.project.getGET /v1/db/project/get/{project_id}

db project get — managed database (Neon/Supabase/PlanetScale).

Parameters (1)
NameTypeRequiredDescription
project_idstringRequiredPath parameter.
db.project.listGET /v1/db/project/list

db project list — managed database (Neon/Supabase/PlanetScale).

No request parameters.

db.snapshot.createPOST /v1/db/snapshot/create

db snapshot create — managed database (Neon/Supabase/PlanetScale).

Parameters (3)
NameTypeRequiredDescription
project_idstringRequiredProject identifier
labelstring | nullOptionalHuman-readable snapshot label.
idempotency_keystring | nullOptionalClient-provided idempotency key; prevents duplicate execution on retry
db.snapshot.getGET /v1/db/snapshot/get/{snapshot_id}

db snapshot get — managed database (Neon/Supabase/PlanetScale).

Parameters (1)
NameTypeRequiredDescription
snapshot_idstringRequiredPath parameter.
db.snapshot.listGET /v1/db/snapshot/list

db snapshot list — managed database (Neon/Supabase/PlanetScale).

No request parameters.

db.snapshot.restorePOST /v1/db/snapshot/restore/{snapshot_id}

db snapshot restore — managed database (Neon/Supabase/PlanetScale).

Parameters (3)
NameTypeRequiredDescription
snapshot_idstringRequiredPath param; the snapshot to restore.
new_namestring | nullOptionalName for the restored project (defaults to source-restored).
idempotency_keystring | nullOptionalClient-provided idempotency key; prevents duplicate execution on retry

4. End-to-end example

A production-style walkthrough of this module: configure once, then run the flow. It exercises most of the module's APIs.

A copy-paste-runnable single-file Python program (stdlib only, no SDK): set your INFRAI_API_KEY, run it, and walk this module's core flow with REAL billed calls — later steps reuse real fields returned by earlier ones. The 12-line helper is the entire integration.

python
#!/usr/bin/env python3
"""Infrai · db — runnable real-app example (single file, zero deps).

Copy this file, set your key, run it: every step is a REAL call to
api.infrai.cc, billed at the real (tiny) per-call price, printing the
live JSON response. Get a key at https://infrai.cc/login (Google/
GitHub sign-in grants $2 free credit); add funds at
https://infrai.cc/billing. No SDK — the 12-line helper below is the
entire integration."""
import json
import os
from urllib import error, request

KEY = os.environ.get("INFRAI_API_KEY") or "ifr_..."  # <- your key
BASE = "https://api.infrai.cc"


# Same raw HTTPS POST/GET as every per-method example on this page —
# wrapped once for reuse. There is nothing else to it: no SDK.
def infrai(method, path, body=None):
    req = request.Request(
        BASE + path, method=method,
        data=json.dumps(body).encode() if body is not None else None,
        headers={"Authorization": f"Bearer {KEY}",
                 "Content-Type": "application/json"})
    try:
        with request.urlopen(req, timeout=60) as r:
            return json.loads(r.read())
    except error.HTTPError as e:
        return json.loads(e.read())


def show(label, resp):
    print(f"\n== {label} ==")
    print(json.dumps(resp, indent=2, ensure_ascii=False))
    return resp


# 1) db.project.create — POST /v1/db/project/create · db project create — managed database (Neon/Supabase/PlanetScale).
r1 = show("db.project.create", infrai("POST", "/v1/db/project/create", {"name":"example"}))

# 2) db.branch.create — POST /v1/db/branch/create · db branch create — managed database (Neon/Supabase/PlanetScale).
r2 = show("db.branch.create", infrai("POST", "/v1/db/branch/create", {"project_id":"sample","branch_name":"example"}))

# 3) db.project.list — GET /v1/db/project/list · db project list — managed database (Neon/Supabase/PlanetScale).
r3 = show("db.project.list", infrai("GET", "/v1/db/project/list"))