openapi: 3.2.0 info: title: AI for Database Conversations API version: 1.0.0 description: API for AI agents to interact with databases through natural language, dashboards, workflows, and more. servers: - url: https://app.aifordatabase.com/api/v1 security: - bearerAuth: [] tags: - name: Conversations description: Manage chat conversation history paths: /conversations: get: tags: - Conversations summary: List conversations operationId: listConversations description: List chat conversations for the organization, optionally filtered by connectionId. parameters: - $ref: '#/components/parameters/PageParam' - $ref: '#/components/parameters/PageSizeParam' - name: connectionId in: query schema: type: string description: Filter by connection responses: '200': description: Paginated list of conversations content: application/json: schema: allOf: - $ref: '#/components/schemas/SuccessEnvelope' - type: object properties: data: type: array items: $ref: '#/components/schemas/Conversation' post: tags: - Conversations summary: Create conversation operationId: createConversation description: Create a new empty conversation. requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/ConversationCreate' responses: '201': description: Conversation created content: application/json: schema: allOf: - $ref: '#/components/schemas/SuccessEnvelope' - type: object properties: data: $ref: '#/components/schemas/Conversation' /conversations/{id}: get: tags: - Conversations summary: Get conversation operationId: getConversation description: Get a conversation with all its messages. parameters: - $ref: '#/components/parameters/IdParam' responses: '200': description: Conversation with messages content: application/json: schema: allOf: - $ref: '#/components/schemas/SuccessEnvelope' - type: object properties: data: $ref: '#/components/schemas/Conversation' '404': $ref: '#/components/responses/NotFound' patch: tags: - Conversations summary: Update conversation operationId: updateConversation description: Update the conversation title. parameters: - $ref: '#/components/parameters/IdParam' requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/ConversationUpdate' responses: '200': description: Conversation updated content: application/json: schema: allOf: - $ref: '#/components/schemas/SuccessEnvelope' - type: object properties: data: $ref: '#/components/schemas/Conversation' '400': $ref: '#/components/responses/BadRequest' '404': $ref: '#/components/responses/NotFound' delete: tags: - Conversations summary: Delete conversation operationId: deleteConversation description: Delete a conversation and all its messages. parameters: - $ref: '#/components/parameters/IdParam' responses: '200': description: Conversation deleted content: application/json: schema: allOf: - $ref: '#/components/schemas/SuccessEnvelope' - type: object properties: data: $ref: '#/components/schemas/DeletedResponse' '404': $ref: '#/components/responses/NotFound' /conversations/{id}/messages: get: tags: - Conversations summary: Get messages operationId: listConversationMessages description: List messages in a conversation, ordered chronologically. parameters: - $ref: '#/components/parameters/IdParam' - $ref: '#/components/parameters/PageParam' - $ref: '#/components/parameters/PageSizeParam' responses: '200': description: Paginated messages content: application/json: schema: allOf: - $ref: '#/components/schemas/SuccessEnvelope' - type: object properties: data: type: array items: $ref: '#/components/schemas/Message' '404': $ref: '#/components/responses/NotFound' components: parameters: PageSizeParam: name: pageSize in: query schema: type: integer default: 20 maximum: 100 description: Items per page (max 100) PageParam: name: page in: query schema: type: integer default: 1 description: Page number (1-based) IdParam: name: id in: path required: true schema: type: string description: Resource ID schemas: DeletedResponse: type: object properties: deleted: type: boolean example: true Conversation: type: object properties: id: type: string orgId: type: string userId: type: string connectionId: type: string nullable: true title: type: string createdAt: type: string format: date-time updatedAt: type: string format: date-time ApiMeta: type: object properties: requestId: type: string format: uuid timestamp: type: string format: date-time pagination: $ref: '#/components/schemas/Pagination' required: - requestId - timestamp SuccessEnvelope: type: object properties: data: {} error: type: 'null' meta: $ref: '#/components/schemas/ApiMeta' required: - data - error - meta ConversationUpdate: type: object required: - title properties: title: type: string ApiError: type: object properties: code: type: string message: type: string details: {} required: - code - message Message: type: object properties: id: type: string conversationId: type: string role: type: string enum: - USER - ASSISTANT content: type: string sqlQuery: type: string nullable: true resultSummary: type: string nullable: true promptTokens: type: integer nullable: true completionTokens: type: integer nullable: true model: type: string nullable: true createdAt: type: string format: date-time Pagination: type: object properties: total: type: integer page: type: integer pageSize: type: integer totalPages: type: integer required: - total - page - pageSize - totalPages ConversationCreate: type: object properties: title: type: string connectionId: type: string ErrorEnvelope: type: object properties: data: type: 'null' error: $ref: '#/components/schemas/ApiError' meta: $ref: '#/components/schemas/ApiMeta' required: - data - error - meta responses: BadRequest: description: Validation error or bad request content: application/json: schema: $ref: '#/components/schemas/ErrorEnvelope' NotFound: description: Resource not found content: application/json: schema: $ref: '#/components/schemas/ErrorEnvelope' securitySchemes: bearerAuth: type: http scheme: bearer bearerFormat: API Key description: Platform API key starting with afd_