AI for Database API reference for agents

A REST and OpenAPI data layer for discovering database structure, returning raw query results, and creating guarded database workflows.

API base
https://app.aifordatabase.com/api/v1
Authentication
Authorization: Bearer afd_...
Canonical contract
https://app.aifordatabase.com/api/v1/openapi.json
Last verified

If this page disagrees with the OpenAPI document, the OpenAPI document is authoritative.

Recommended agent lifecycle

  1. 01. Discover: List sanitized connections, health state, and cached schemas.
  2. 02. Validate: Run read-only SQL and inspect raw columns, rows, count, and timing.
  3. 03. Draft: Create a paused workflow and reference a write-only outbound credential.
  4. 04. Preview: Execute draft queries without contacting external systems.
  5. 05. Test: Explicitly confirm one live action and inspect its sanitized attempts.
  6. 06. Publish: Activate an immutable version, then inspect scheduled run history.

Authentication and scopes

Generate an API key in the application settings. Keys use one afd_ prefix; there are no live or test key variants. Use the narrowest scopes necessary.

ScopePurpose
queryDirect SQL, saved-query runs, and query approval
chatNatural-language questions and generated SQL
connectionsSanitized connections, schemas, health, and annotations
dashboardsDashboards, widgets, and widget data
workflowsWorkflow drafts, previews, tests, publishing, and runs
workflow_credentialsEncrypted outbound credentials; admin role also required
usageUsage records and budget status
webhooksSigned event endpoints, tests, and deliveries
adminAPI-key management and administrative operations

Workflow credential operations require both the workflow_credentials scope and an organization admin role.

Endpoint catalog

Connections and queries

Relevant scope: connections / query

MethodPathBehaviorExternal side effect
GET / POST/api/v1/connectionsList sanitized connections or create oneNone beyond stated resource mutation
GET / PATCH / DELETE/api/v1/connections/{id}Read, update, or remove a connectionNone beyond stated resource mutation
POST/api/v1/connections/{id}/testTest connectivity and introspect on first successNone beyond stated resource mutation
GET / POST/api/v1/connections/{id}/schemaRead cached schema or introspect nowNone beyond stated resource mutation
POST/api/v1/connections/{id}/queryExecute SQL and return raw columns and rowsNone beyond stated resource mutation
GET / POST/api/v1/connections/{id}/annotationsList or add schema contextNone beyond stated resource mutation
PATCH / DELETE/api/v1/connections/{id}/annotations/{annotationId}Update or remove an annotationNone beyond stated resource mutation
POST/api/v1/connections/{id}/annotations/autoGenerate schema annotationsNone beyond stated resource mutation

Chat and conversations

Relevant scope: chat

MethodPathBehaviorExternal side effect
POST/api/v1/chatAsk in natural language and receive generated SQL and resultsNone beyond stated resource mutation
GET / POST/api/v1/conversationsList or create conversationsNone beyond stated resource mutation
GET / PATCH / DELETE/api/v1/conversations/{id}Manage one conversationNone beyond stated resource mutation
GET/api/v1/conversations/{id}/messagesRead conversation messagesNone beyond stated resource mutation

Dashboards

Relevant scope: dashboards

MethodPathBehaviorExternal side effect
GET / POST/api/v1/dashboardsList or create dashboardsNone beyond stated resource mutation
GET / PATCH / DELETE/api/v1/dashboards/{id}Manage one dashboardNone beyond stated resource mutation
GET / POST/api/v1/dashboards/{id}/widgetsList or add widgetsNone beyond stated resource mutation
PATCH / DELETE/api/v1/dashboards/{id}/widgets/{widgetId}Update or remove a widgetNone beyond stated resource mutation
GET/api/v1/dashboards/{id}/widgets/{widgetId}/dataRead current widget dataNone beyond stated resource mutation

Workflows

Relevant scope: workflows / workflow_credentials

MethodPathBehaviorExternal side effect
GET / POST/api/v1/workflowsList workflows or create a paused draftPOST creates state but does not schedule it
GET / PATCH / DELETE/api/v1/workflows/{id}Read, revise, publish, pause, or deletePATCH with isActive=true publishes
POST/api/v1/workflows/{id}/previewRun draft queries only; no delivery or persisted runNone beyond stated resource mutation
POST/api/v1/workflows/{id}/actions/{order}/testSend one explicitly confirmed live action testReal external delivery
POST/api/v1/workflows/{id}/runRun the current draft including actionsReal external delivery
GET/api/v1/workflows/{id}/runsInspect paginated execution historyNone beyond stated resource mutation
GET / POST/api/v1/workflow-credentialsList safe metadata or create an encrypted credentialNone beyond stated resource mutation
GET / PATCH / DELETE/api/v1/workflow-credentials/{id}Read metadata, rotate, or safely delete a credentialNone beyond stated resource mutation

Saved queries, metrics, and approval

Relevant scope: query

MethodPathBehaviorExternal side effect
GET / POST/api/v1/saved-queriesList or create saved queriesNone beyond stated resource mutation
GET / PATCH / DELETE/api/v1/saved-queries/{id}Manage a saved queryNone beyond stated resource mutation
POST/api/v1/saved-queries/{id}/runRun a saved query with parametersNone beyond stated resource mutation
GET / POST/api/v1/metricsList or define metricsNone beyond stated resource mutation
GET / PATCH / DELETE/api/v1/metrics/{id}Manage a metric definitionNone beyond stated resource mutation
GET/api/v1/metrics/{id}/valueEvaluate a metric nowNone beyond stated resource mutation
GET / POST/api/v1/approval-rulesList or create approval rulesNone beyond stated resource mutation
GET / PATCH / DELETE/api/v1/approval-rules/{id}Manage an approval ruleNone beyond stated resource mutation
POST/api/v1/queries/submitSubmit a query for approvalNone beyond stated resource mutation
GET/api/v1/queries/pendingList pending queriesNone beyond stated resource mutation
GET/api/v1/queries/{id}/statusRead approval statusNone beyond stated resource mutation
POST/api/v1/queries/{id}/approveApprove a pending queryNone beyond stated resource mutation
POST/api/v1/queries/{id}/rejectReject a pending queryNone beyond stated resource mutation

Webhooks, usage, and keys

Relevant scope: webhooks / usage / admin

MethodPathBehaviorExternal side effect
GET / POST/api/v1/webhooksList or create signed event endpointsNone beyond stated resource mutation
GET / PATCH / DELETE/api/v1/webhooks/{id}Manage one event endpointNone beyond stated resource mutation
GET/api/v1/webhooks/{id}/deliveriesInspect delivery historyNone beyond stated resource mutation
POST/api/v1/webhooks/{id}/testSend a test eventReal external delivery
GET/api/v1/usageRead usage recordsNone beyond stated resource mutation
GET/api/v1/usage/budgetRead budget statusNone beyond stated resource mutation
GET / POST/api/v1/keysList or create API keysNone beyond stated resource mutation
DELETE/api/v1/keys/{id}Revoke an API keyNone beyond stated resource mutation

Response envelope and pagination

{
  "data": {},
  "error": null,
  "meta": {
    "requestId": "uuid",
    "timestamp": "ISO-8601",
    "pagination": {
      "total": 0,
      "page": 1,
      "pageSize": 20,
      "totalPages": 0
    }
  }
}

Pagination is page-based with page and pageSize. On errors, data is null and error contains a stable code, message, and optional details.

Safety and delivery boundaries

  • Connection reads never return database passwords or stored platform secrets.
  • Workflow credentials are encrypted, write-only, and restricted to allowed destination hosts.
  • New workflows are paused drafts; creation alone never schedules delivery.
  • Preview executes queries only and never creates a delivery or workflow run.
  • Action tests require confirmDelivery=true because they contact the destination.
  • Manual workflow runs have real side effects; published schedules use an immutable version.

Webhook actions accept explicit successStatusCodes. Use this when a destination distinguishes full acceptance from partial acceptance, such as HTTP 202 versus 207.

Minimal raw-query example

curl -X POST   https://app.aifordatabase.com/api/v1/connections/CONNECTION_ID/query   -H "Authorization: Bearer afd_your_key"   -H "Content-Type: application/json"   -d '{"sql":"SELECT id, email FROM users LIMIT 5"}'

Errors and retries

  • 400: malformed body or validation failure.
  • 401: missing, invalid, or expired API key.
  • 403: missing scope or required admin role.
  • 422: connection, preview, or action-test execution failed.
  • 428: draft revision or explicit delivery confirmation required.
  • 429: rate limited; retry with backoff.
  • 5xx: transient service error; retry idempotent reads with backoff.

Do not automatically retry live action tests, manual workflow runs, or other delivery operations unless your integration can prove the first attempt did not reach the destination.