@batadata/cli
The command-line interface for BataDB, a serverless Postgres
platform with copy-on-write branches, scale-to-zero, point-in-time restore, query insights
and honest cost reporting.
Every command runs headlessly with one API key and --json output, so an AI agent can
provision and operate a database on its own. The one step that needs a person is adding a
card to a new Free team, once, before its first database starts. The full reference, generated
from the command registry, is at batadb.com/docs/cli.
Install
npm install -g @batadata/cli
This installs the bata command. Requires Node.js 20 or newer.
Authenticate
Log in with bata login, once per machine. It prints a code and opens the BataDB
console, where you type that code and approve it for one of your teams. The CLI then
saves a revocable API key (cli-<hostname>) to ~/.batarc (mode 0600). It works for
accounts that sign in with GitHub or Google, and it renews itself on use: it expires
only after 90 days unused. A password change keeps it; a password reset revokes it.
So every agent on the machine keeps working without a person until someone revokes
the key on purpose. On a machine without a browser, bata login --no-browser prints
the URL to open elsewhere. bata login --password signs in with email and password
and saves the same kind of key (the session itself is never written to disk).
bata logout (or bata keys revoke <id>, or "Revoke all CLI keys" in Settings)
revokes the saved key.
- Resume. If
bata login is interrupted while it waits (an agent's tool call timed
out), run it again: it resumes the same request and shows the same code (in --json
the first line has "resumed": true). --new starts over.
- Profiles.
--profile <name> or BATA_PROFILE=<name> selects a saved login. The
default profile is ~/.batarc; a named one lives in ~/.bata/profiles/<name>.json.
Test as another account with BATA_PROFILE=qa bata login instead of swapping
~/.batarc around.
- When a login dies. A refused saved login fails with
AUTH_REQUIRED (exit 4). The
JSON envelope has reason (for example revoked or expired), at, profile, and
next: "bata login --json". A refused BATA_API_KEY or --api-key stays
INVALID_KEY with the same reason and at, and next: null.
- See the credential.
bata whoami --json reports credential.source (profile,
env or flag), profile, kind (cli, integration, or session for an old password
login), key_id, name and expires_at.
Or set an API key. Every command works with just BATA_API_KEY set:
export BATA_API_KEY=bata_xxx
bata whoami # your team, role, and the key's scopes and project restriction
Keys are scoped by the server. Give an agent the narrowest key that does its job:
| Scope |
Allows |
admin |
Everything your team role allows (the default) |
read |
Read-only API: projects, branches, insights, schema, usage |
sql |
read, plus running SQL and reading connection strings |
telemetry:write |
Only posting Turbine telemetry for its project |
bata keys create --name ci --scope read --scope sql --project prj_123 --json
--project (repeatable) restricts a key to specific projects. A restricted key cannot
call team-level commands (teams, billing, keys, creating projects).
Quick start
bata create my-app # create a project and wait until it is ready
bata link my-app # later commands in this directory target it
bata db query "SELECT 1" --json # run SQL headlessly
bata db branch create pr-42 --expires-in 2h # an ephemeral copy-on-write branch
bata insights recommendations # what to fix, with evidence and the fix
bata usage # per-dimension cost for the period
Agent contract
-
--json prints the API payload verbatim on stdout, so it stays stable across CLI
releases. Human output is for people.
-
Errors print one envelope in --json mode, { "error", "code", "hint" }, and
exit non-zero:
| Exit |
Meaning |
Codes |
| 0 |
Success |
|
| 1 |
Generic error |
CLI_ERROR |
| 2 |
Gate tripped |
migrate check, schema check --fail-on |
| 3 |
Not implemented |
NOT_IMPLEMENTED |
| 4 |
Auth or permission |
NO_CREDENTIALS, AUTH_REQUIRED, INVALID_KEY, KEY_SCOPE_DENIED, KEY_PROJECT_DENIED, FORBIDDEN |
| 5 |
Not found or bad input |
NO_PROJECT, BRANCH_NOT_FOUND, NOT_FOUND, INVALID_FLAG, CONFIRM_REQUIRED, PLAN_LIMIT_REACHED |
| 6 |
Transient, retry |
API_UNAVAILABLE, TIMEOUT, COMPUTE_STARTING |
| 7 |
Billing: a person must act, do not retry |
PAYMENT_METHOD_REQUIRED, SPEND_CAP_REACHED |
KEY_SCOPE_DENIED names the missing scope in its hint, with the bata keys create
command that fixes it.
PLAN_LIMIT_REACHED means the request is over the team's plan (for example a 4 CU
compute on Free). The envelope adds limit and allowed, and the hint says how to
raise the limit.
-
Destructive commands need --yes when no terminal can answer. On a terminal they
prompt (default no). In a pipe, CI, an agent, or --json mode they refuse with
CONFIRM_REQUIRED (exit 5) unless you pass --yes.
-
Creating a project never moves your saved default. bata create and
bata projects create make the new project the default only when none is saved
yet, or with --set-default, and say which happened (default_project_changed in
--json). bata projects delete clears the default only when it deletes that project.
-
--help works on every command and never touches the network. It prints usage,
flags and the API routes the command calls.
-
Cold starts are normal. An idle branch's compute scales to zero. A command that
meets a waking compute exits 6; retry after a few seconds.
-
A new Free team needs a card before its first database. Until one is on file, every
command that creates or starts a database exits 7 with PAYMENT_METHOD_REQUIRED. The
hint says A human needs to add a card: <link>, and --json adds add_card_url. An
agent cannot add the card: hand the link to a person on the team (bata billing card add
makes a direct Stripe link). Nothing is charged while usage stays inside the free
allowance. Past it, a Free team's databases stop by default; bata billing stop-at-limit off
turns on pay as you go, which bills usage past the allowance to the card.
-
A spend cap stops databases, it is not a permission error. SPEND_CAP_REACHED also
exits 7. An owner or admin raises the cap (bata billing spend-cap --set <dollars>) or
turns off stop-at-limit.
-
Cost is honest. A dimension that is not metered reports null, never a priced $0.
Commands
| Group |
Commands |
| Projects |
create, status, projects list, info, create, update, storage, pitr, delete, link, unlink |
| Branches |
db branches, db branch create, info, delete, reset, rollback, set-primary, expire, protect, unprotect, checkout |
| SQL and data |
db query (--at time-travels), db url (pooled and direct), db tables, db rows (filters, sort, paging) and db rows insert, update, delete, db ping, db databases, db roles |
| Compute |
compute status, show, set, start, suspend, restart, resize, logs, create, delete, compute replicas list, add, remove |
| Operations |
ops list, show, cancel |
| Insights |
insights overview, top, performance, queries, query, timeseries, size, live, cold-start, trends, regressions, turbine, health, explain, insights recommendations and refresh, dismiss, reopen |
| Index advice |
index advice, report, status, apply, index trial start, list, show, cancel, doctor upload |
| Telemetry |
telemetry setup (mints a telemetry-only app key, which never expires, and prints the setup), telemetry status |
| Restore |
restore points, restore create (non-destructive, a new branch) |
| Schema and migrations |
schema dump, diff, check, migrate check (a CI gate), migrate test-connection, estimate, start (server-side pipeline), import |
| PowDB |
powdb status, query, exec, park, wake, upgrade, pull |
| Keys and identity |
whoami, keys create, list, rotate, expiring, revoke |
| Team |
team list, info, members, create, rename, invite, remove, role |
| Billing |
usage, billing plans, usage, history, subscribe, checkout, portal, card, card add, stop-at-limit, spend-cap, events, reservations |
| Account |
audit-log, notifications list, read, read-all, health, config |
| Something wrong? |
report (files it with your project's state attached; asks in a terminal, flags for agents), report list, show, comment |
Every command is documented, with its flags and API routes, at
batadb.com/docs/cli.
Examples
A full agent loop, headless:
export BATA_API_KEY=bata_xxx
PROJECT_ID=$(bata create my-app --json | jq -r .id)
bata link "$PROJECT_ID"
bata db branch create task-17 --expires-in 2h --json
bata db query "CREATE TABLE notes (id serial primary key, body text)" --branch task-17 --json
bata db rows notes --branch task-17 --filter "body ILIKE %todo%" --sort id:desc --json
bata insights recommendations --status open --json
bata index trial start --table notes --columns body --json
bata db branch delete task-17 --yes --json
Set up Turbine telemetry for an app:
bata telemetry setup --project prj_123
# prints BATA_API_KEY (a telemetry-only app key: never expires, shown once), BATA_PROJECT_ID, the install
# command and the batadbTelemetry(db) snippet
bata telemetry status --project prj_123
Point-in-time restore is non-destructive (a new branch); rollback overwrites a branch:
bata restore create --branch main --at 2026-07-04T12:00:00Z --name before-migration
bata db branch rollback main --to 2026-07-04T12:00:00Z --yes --wait
Move a database in (requires local pg_dump and psql at least as new as the source):
bata import --source "$SOURCE_DATABASE_URL" --name my-app --json
See Migrate from Neon for the full import guide.
Global options
| Flag |
Meaning |
--json |
Machine-readable output |
--yes, -y |
Confirm a destructive command |
--api-key <key> |
Credential (else BATA_API_KEY, else the saved login) |
--api-url <url> |
API base URL (else BATA_API_URL, else the saved or default URL) |
--profile <name> |
Saved login to use (else BATA_PROFILE, else ~/.batarc) |
--help, -h |
Help for any command or group |
--version, -v |
Print the version |
Changes in 0.12.0
bata db roles delete drops the role in Postgres too (its sessions end, what it
owns goes to the owner role), and only on a project's only branch.
bata db owner-password reset rotates the owner password; every branch's
connection string changes.
bata billing checkout calls nothing and says how to pay as you go instead (exit 3).
bata billing plans shows data transfer as not metered yet unless the API says it
is billed. See CHANGELOG.md.
Changes in 0.11.0
bata db query reports a SQL error as QUERY_ERROR with its sqlstate.
PLAN_LIMIT_REACHED keeps its hint, limit and allowed on every command (exit 5).
- Key commands keep the server's code: a missing key is
API_KEY_NOT_FOUND (exit 5).
bata create refuses flags it does not take, such as --size and --tier.
bata status --json reports compute_status: null when the API does not say.
See CHANGELOG.md.
Changes in 0.10.0
bata compute logs shows the compute's Postgres lines and startup errors, scrubbed,
with the last start failure first; --since sets how far back.
bata db branch create --wait starts the new branch and reports when it is ready.
In --json, wake replaces poll.
bata db branch rollback keeps the replaced state as a <name>_old_<time> branch.
db commands exit with the server's error codes, and a project name where the id
belongs is NOT_FOUND (5).
bata status, bata projects info, bata migrate check --branch and
bata schema dump fixes. See CHANGELOG.md.
Changes in 0.9.0
bata report files an issue report with BataDB, with the project's state attached;
bata report list, show and comment follow it up. An outage or urgent report
alerts the team at once.
bata report attaches this login's recent failed calls (--no-errors to skip).
Changes in 0.8.1