API Reference
Complete reference for the Basira REST API.
All endpoints are under https://api.usebasira.com/api/v1. Authenticate with an API key (X-API-Key header) or JWT token (Authorization: Bearer header). See Authentication for details.
All timestamps are RFC 3339 format. Error responses use {"error": "message"}.
Databases
List Databases
GET /api/v1/databasesReturns all databases in your organization.
Register Database
POST /api/v1/databases| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Display name |
engine | string | Yes | postgres or clickhouse |
engine_version | string | No | Database version string |
host | string | Yes | Hostname or IP |
port | int | No | Default: 5432 (postgres), 8123 (clickhouse) |
tags | object | No | Key-value metadata |
Unverified accounts are limited to 1 database.
Get Database
GET /api/v1/databases/{id}Update Database
PATCH /api/v1/databases/{id}| Field | Type | Description |
|---|---|---|
name | string | Display name |
host | string | Hostname or IP |
port | int | Port (1–65535) |
tags | object | Key-value metadata |
poll_interval_seconds | int | Collection interval (minimum 1) |
collect_explain_plans | bool | Enable/disable EXPLAIN plan collection |
collect_replication | bool | Enable/disable replication monitoring |
disabled_collectors | string[] | Collectors to disable server-side |
Delete Database
DELETE /api/v1/databases/{id}Returns 204 No Content. Cascades to related alerts and recommendations.
Database Health
GET /api/v1/databases/{id}/healthResponse: { "id": "...", "status": "connected|disconnected", "last_seen_at": "..." }
Queries
List Query Statistics
GET /api/v1/databases/{id}/queries| Param | Default | Description |
|---|---|---|
since | 24h ago | Start time (RFC 3339) |
until | now | End time (RFC 3339) |
limit | 25 | Max results (max 100) |
sort_by | total_time | total_time, calls, mean_time, or rows |
Response fields: query_hash, query_text, total_calls, total_time_ms, mean_time_ms, total_rows, shared_blks_hit, shared_blks_read, cache_hit_ratio.
Get Query Detail
GET /api/v1/databases/{id}/queries/{hash}| Param | Default | Description |
|---|---|---|
since | 24h ago | Start time |
until | now | End time |
Returns query metadata plus timeseries array with per-interval breakdowns of calls, time, rows, and block I/O.
Get EXPLAIN Plans
GET /api/v1/databases/{id}/queries/{hash}/explain| Param | Default | Description |
|---|---|---|
since | 24h ago | Start time |
until | now | End time |
limit | 10 | Max plans (max 50) |
Response fields per plan: ts, plan_json, plan_hash, total_cost, actual_time_ms, seq_scans, index_scans, rows_estimated, rows_actual.
Active Queries & Locks
List Active Queries
GET /api/v1/databases/{id}/active| Param | Default | Description |
|---|---|---|
limit | 50 | Max results (max 200) |
Response fields: pid, query_text, state, wait_event_type, wait_event, duration_ms, blocking_pids, ts. ClickHouse adds memory_usage, read_bytes, written_bytes, read_rows.
Active Queries WebSocket
GET /api/v1/databases/{id}/active/ws?token={jwt}&interval=5Streams active query snapshots at the specified interval (seconds). Authenticate via token query param or session cookie.
List Locks
GET /api/v1/databases/{id}/locks| Param | Default | Description |
|---|---|---|
limit | 100 | Max results (max 500) |
Response fields: pid, lock_type, mode, relation_name, granted, blocked_by_pid, duration_ms, query_text, ts.
Wait Events
GET /api/v1/databases/{id}/waits| Param | Default | Description |
|---|---|---|
since | 24h ago | Start time |
until | now | End time |
bucket | 60 | Aggregation bucket in seconds |
Response fields: ts, wait_event_type, wait_event, count, total_duration_ms.
Tables & Indexes
List Tables
GET /api/v1/databases/{id}/tables| Param | Default | Description |
|---|---|---|
sort_by | size | size, dead_tuples, seq_scans, live_tuples, or index_size |
limit | 50 | Max results (max 500) |
Response fields: schema_name, table_name, seq_scan, idx_scan, n_tup_ins, n_tup_upd, n_tup_del, n_live_tup, n_dead_tup, last_vacuum, last_autovacuum, last_analyze, table_size_bytes, index_size_bytes.
Get Table Detail
GET /api/v1/databases/{id}/tables/{schema}/{name}Returns table metadata plus timeseries array.
List Indexes
GET /api/v1/databases/{id}/indexes| Param | Default | Description |
|---|---|---|
sort_by | size | size, scans, or tuples_read |
limit | 50 | Max results (max 500) |
Response fields: schema_name, table_name, index_name, idx_scan, idx_tup_read, idx_tup_fetch, size_bytes, index_def, is_unique, is_primary, is_valid.
Unused Indexes
GET /api/v1/databases/{id}/indexes/unusedSame response as List Indexes, filtered to indexes with 0 scans, not primary, not unique, and over 1 MB.
Get Index Detail
GET /api/v1/databases/{id}/indexes/{schema}/{name}Returns index metadata plus timeseries array.
Dashboard & Health
Overview
GET /api/v1/databases/{id}/overviewReturns a summary of database health. Response includes engine, status, last_seen_at, health_score (0–100), active_queries, longest_query_ms, and top_queries.
PostgreSQL adds: blocked_queries, cache_hit_ratio, dead_tuple_ratio, last_autovacuum.
ClickHouse adds: active_merges, merge_progress_pct, active_mutations, stuck_mutations, query_p99_ms.
Health Diagnosis
GET /api/v1/databases/{id}/doctorReturns status (healthy, degraded, unhealthy), score (0–100), top_issues array with severity, category, title, detail, recommendation, how_to_investigate, how_to_fix, and a metrics_summary.
Replication (PostgreSQL)
Current Status
GET /api/v1/databases/{id}/replicationResponse: is_replica, replication_lag_bytes, replication_lag_seconds, upstream_host, slots array.
Lag History
GET /api/v1/databases/{id}/replication/history| Param | Default | Description |
|---|---|---|
since | 24h ago | Start time |
until | now | End time |
bucket | 60 | Aggregation bucket in seconds |
Slot History
GET /api/v1/databases/{id}/replication/slots/historySame params as lag history. Response includes slot_name and lag_bytes per interval.
PostgreSQL Internals
Background Writer
GET /api/v1/databases/{id}/bgwriter| Param | Default | Description |
|---|---|---|
since | 24h ago | Start time |
until | now | End time |
Returns timeseries with checkpoint and buffer write statistics.
WAL Statistics
GET /api/v1/databases/{id}/wal-statsReturns current WAL generation stats (PostgreSQL 14+).
WAL Timeseries
GET /api/v1/databases/{id}/wal-stats/timeseriesReturns WAL stats over time with since, until params.
I/O Statistics
GET /api/v1/databases/{id}/io-statsReturns current I/O stats by backend/object/context (PostgreSQL 16+).
I/O Timeseries
GET /api/v1/databases/{id}/io-stats/timeseriesReturns I/O stats over time with since, until params.
ClickHouse Internals
Parts
GET /api/v1/databases/{id}/partsReturns part statistics for MergeTree tables.
Merges
GET /api/v1/databases/{id}/mergesReturns currently active merge operations.
Mutations
GET /api/v1/databases/{id}/mutationsReturns mutation status for ALTER TABLE operations.
Server Metrics
GET /api/v1/databases/{id}/server-metricsReturns server-level metrics: memory, disk, connections, uptime.
API Keys
List Keys
GET /api/v1/api-keys| Param | Default | Description |
|---|---|---|
include_revoked | false | Include revoked keys |
Create Key
POST /api/v1/api-keys| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Display name |
Response includes the full key — this is the only time it's shown.
Revoke Key
DELETE /api/v1/api-keys/{id}Returns 204 No Content.
Account
Current User
GET /api/v1/auth/meReturns user info (when using JWT) or organization info (when using API key). Includes organization with id, name, slug, plan, verified.
Signup
POST /api/v1/auth/signup| Field | Type | Required | Description |
|---|---|---|---|
email | string | Yes | Valid email address |
password | string | Yes | Minimum 8 characters |
name | string | Yes | User's name |
org_name | string | Yes | Organization name |
Login
POST /api/v1/auth/login| Field | Type | Required | Description |
|---|---|---|---|
email | string | Yes | Email address |
password | string | Yes | Password |
Response: { "access_token": "...", "refresh_token": "...", "expires_in": 900 }
Refresh Token
POST /api/v1/auth/refresh| Field | Type | Required | Description |
|---|---|---|---|
refresh_token | string | Yes | Refresh token from login |
Logout
POST /api/v1/auth/logoutClears session cookies. Returns 204.
Verify Email
GET /api/v1/auth/verify-email?token={token}Forgot Password
POST /api/v1/auth/forgot-password| Field | Type | Required | Description |
|---|---|---|---|
email | string | Yes | Account email |
Always returns success (does not leak whether the email exists).
Reset Password
POST /api/v1/auth/reset-password| Field | Type | Required | Description |
|---|---|---|---|
token | string | Yes | Reset token from email (1 hour TTL) |
password | string | Yes | New password (minimum 8 characters) |
Health Check
GET /healthzNo authentication required. Returns 200 if the API is running.