advanced8 min read

API Endpoints

API Endpoints

This is the complete reference for all AI for Database API endpoints.

Queries

Run a query

POST /v1/queries

Request body:

json
{
  "question": "How many users signed up this week?",
  "connection_id": "conn_abc123",
  "format": "table"
}

Response:

json
{
  "data": {
    "query_id": "q_xyz789",
    "sql": "SELECT COUNT(*) FROM users WHERE created_at >= '2024-01-08'",
    "results": {
      "columns": ["count"],
      "rows": [[142]],
      "row_count": 1
    },
    "execution_time_ms": 45
  }
}

List saved queries

GET /v1/queries?limit=20&cursor=...

Get a specific query

GET /v1/queries/:query_id

Delete a query

DELETE /v1/queries/:query_id

Dashboards

List dashboards

GET /v1/dashboards

Get a dashboard

GET /v1/dashboards/:dashboard_id

Returns the dashboard configuration including all widgets and their current data.

Create a dashboard

POST /v1/dashboards
json
{
  "name": "Sales Overview",
  "description": "Daily sales metrics",
  "widgets": [
    {
      "type": "metric",
      "query_id": "q_abc",
      "position": { "x": 0, "y": 0, "w": 6, "h": 4 }
    }
  ]
}

Update a dashboard

PATCH /v1/dashboards/:dashboard_id

Delete a dashboard

DELETE /v1/dashboards/:dashboard_id

Workflows

List workflows

GET /v1/workflows

Get a workflow

GET /v1/workflows/:workflow_id

Create a workflow

POST /v1/workflows

Trigger a workflow manually

POST /v1/workflows/:workflow_id/run

Get workflow run history

GET /v1/workflows/:workflow_id/runs

Connections

List connections

GET /v1/connections

Create a connection

POST /v1/connections
json
{
  "type": "postgresql",
  "name": "Production DB",
  "host": "db.example.com",
  "port": 5432,
  "database": "production",
  "username": "aifordb_reader",
  "password": "encrypted-password",
  "ssl_mode": "require"
}

Test a connection

POST /v1/connections/:connection_id/test

Delete a connection

DELETE /v1/connections/:connection_id

Team

List team members

GET /v1/team/members

Invite a member

POST /v1/team/members
json
{
  "email": "new.member@company.com",
  "role": "editor"
}

Update a member's role

PATCH /v1/team/members/:member_id

Remove a member

DELETE /v1/team/members/:member_id

Error Codes

CodeHTTP StatusDescription
authentication_error401Missing or invalid API key
authorization_error403Key does not have the required scope
not_found404Resource does not exist
validation_error422Invalid request parameters
rate_limit_exceeded429Too many requests
query_error500The generated SQL failed to execute
connection_error502Could not reach the database