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/queriesRequest 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_idDelete a query
DELETE /v1/queries/:query_idDashboards
List dashboards
GET /v1/dashboardsGet a dashboard
GET /v1/dashboards/:dashboard_idReturns the dashboard configuration including all widgets and their current data.
Create a dashboard
POST /v1/dashboardsjson
{
"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_idDelete a dashboard
DELETE /v1/dashboards/:dashboard_idWorkflows
List workflows
GET /v1/workflowsGet a workflow
GET /v1/workflows/:workflow_idCreate a workflow
POST /v1/workflowsTrigger a workflow manually
POST /v1/workflows/:workflow_id/runGet workflow run history
GET /v1/workflows/:workflow_id/runsConnections
List connections
GET /v1/connectionsCreate a connection
POST /v1/connectionsjson
{
"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/testDelete a connection
DELETE /v1/connections/:connection_idTeam
List team members
GET /v1/team/membersInvite a member
POST /v1/team/membersjson
{
"email": "new.member@company.com",
"role": "editor"
}Update a member's role
PATCH /v1/team/members/:member_idRemove a member
DELETE /v1/team/members/:member_idError Codes
| Code | HTTP Status | Description |
|---|---|---|
authentication_error | 401 | Missing or invalid API key |
authorization_error | 403 | Key does not have the required scope |
not_found | 404 | Resource does not exist |
validation_error | 422 | Invalid request parameters |
rate_limit_exceeded | 429 | Too many requests |
query_error | 500 | The generated SQL failed to execute |
connection_error | 502 | Could not reach the database |