{
  "openapi": "3.0.1",
  "info": {
    "title": "Knowledge Engine API",
    "description": "Public API endpoints for managing knowledge engines",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://api.getdecisional.ai"
    }
  ],
  "paths": {
    "/api/v1/knowledge-engines": {
      "post": {
        "summary": "Create a new knowledge engine",
        "description": "Creates a new public knowledge engine",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateKnowledgeEngine"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Knowledge engine created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/KnowledgeEngineResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "get": {
        "summary": "List all public knowledge engines",
        "description": "Returns a list of all public knowledge engines",
        "responses": {
          "200": {
            "description": "List of knowledge engines",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/KnowledgeEngineResponse"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/knowledge-engines/{id}": {
      "get": {
        "summary": "Get a knowledge engine",
        "description": "Returns a single knowledge engine by ID",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Knowledge engine ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Knowledge engine found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/KnowledgeEngineResponse"
                }
              }
            }
          },
          "404": {
            "description": "Knowledge engine not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "put": {
        "summary": "Update a knowledge engine",
        "description": "Updates an existing knowledge engine",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Knowledge engine ID"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateKnowledgeEngine"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Knowledge engine updated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/KnowledgeEngineResponse"
                }
              }
            }
          },
          "404": {
            "description": "Knowledge engine not found"
          }
        }
      },
      "delete": {
        "summary": "Delete a knowledge engine",
        "description": "Deletes an existing knowledge engine",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Knowledge engine ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Knowledge engine deleted successfully"
          },
          "404": {
            "description": "Knowledge engine not found"
          }
        }
      }
    },
    "/api/v1/knowledge-engines/{id}/data-sources": {
      "get": {
        "summary": "List knowledge engine data sources",
        "description": "Returns a list of all data sources associated with a knowledge engine",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Knowledge engine ID"
          }
        ],
        "responses": {
          "200": {
            "description": "List of data sources",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/DataSourceResponse"
                  }
                },
                "example": {
                  "$ref": "#/components/examples/DataSourceListResponse"
                }
              }
            }
          },
          "404": {
            "description": "Knowledge engine not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/data-sources": {
      "post": {
        "summary": "Create a new data source",
        "description": "Creates a new data source and associates it with a knowledge engine",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": ["file", "data"],
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary",
                    "description": "The file to upload"
                  },
                  "data": {
                    "type": "string",
                    "description": "JSON string containing data source metadata. \n\n **Example**: \n```\n{\n  \"name\": \"Annual Report 2023\",\n  \"type\": \"file\",\n  \"knowledge_engine_id\": \"kng_abc123xyz789\"\n}\n```",
                    "example": "{\"name\":\"Annual Report 2023\",\"type\":\"file\",\"notes\":{\"category\":\"financial\"},\"knowledge_engine_id\":\"kng_abc123xyz789\"}"
                  }
                }
              },
              "example": {
                "file": "<binary file content>",
                "data": "{\"name\":\"Annual Report 2023\",\"type\":\"file\",\"notes\":{\"category\":\"financial\"},\"knowledge_engine_id\":\"kng_abc123xyz789\"}"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Data source created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DataSourceResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Duplicate file",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DuplicateFileError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/data-sources/{id}": {
      "get": {
        "summary": "Get a data source",
        "description": "Returns a single data source by ID",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Data source ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Data source found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DataSourceResponse"
                }
              }
            }
          },
          "404": {
            "description": "Data source not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Delete a data source",
        "description": "Deletes an existing data source",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Data source deleted successfully"
          },
          "404": {
            "description": "Data source not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/data-sources/{id}/presigned-url": {
      "get": {
        "summary": "Get a presigned URL for a data source",
        "description": "Returns a presigned URL for a data source",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Presigned URL found",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "presigned_url": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/data-sources/batch": {
      "post": {
        "summary": "Create multiple data sources",
        "description": "Creates multiple data sources in a single request",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": ["files[]", "data"],
                "properties": {
                  "files[]": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "binary"
                    },
                    "description": "Array of files to upload"
                  },
                  "data": {
                    "type": "string",
                    "description": "JSON string containing an array of data sources metadata. \n\n **Example**: \n```\n[{\"name\":\"Doc 1\",\"type\":\"file\",\"knowledge_engine_id\":\"kng_abc123xyz789\"},{\"name\":\"Doc 2\",\"type\":\"file\",\"knowledge_engine_id\":\"kng_abc123xyz789\"}]\n```",
                    "example": "[{\"name\":\"Doc 1\",\"type\":\"file\",\"knowledge_engine_id\":\"kng_abc123xyz789\"},{\"name\":\"Doc 2\",\"type\":\"file\",\"knowledge_engine_id\":\"kng_abc123xyz789\"}]"
                  }
                }
              },
              "example": {
                "files[]": ["<file1 binary>", "<file2 binary>"],
                "data": "[{\"name\":\"Doc 1\",\"type\":\"file\",\"knowledge_engine_id\":\"kng_abc123xyz789\"},{\"name\":\"Doc 2\",\"type\":\"file\",\"knowledge_engine_id\":\"kng_abc123xyz789\"}]"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Data sources accepted for processing",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DataSourceBatchResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Delete multiple data sources",
        "description": "Deletes multiple data sources in a single request",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["ids"],
                "properties": {
                  "ids": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Array of data source IDs to delete",
                    "example": ["dsc_abc123xyz789", "dsc_abc123xyz790", "dsc_abc123xyz791"]
                  }
                }
              },
              "example": {
                "ids": ["dsc_abc123xyz789", "dsc_abc123xyz790", "dsc_abc123xyz791"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Batch delete results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string",
                        "description": "Data source ID"
                      },
                      "success": {
                        "type": "boolean",
                        "description": "Whether the deletion was successful"
                      },
                      "error": {
                        "type": "string",
                        "description": "Error message if deletion failed"
                      }
                    },
                    "required": ["id", "success"]
                  }
                },
                "example": [
                  {
                    "id": "dsc_abc123xyz789",
                    "success": true
                  },
                  {
                    "id": "dsc_abc123xyz790",
                    "success": false,
                    "error": "data source not found"
                  },
                  {
                    "id": "dsc_abc123xyz791",
                    "success": true
                  }
                ]
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "missing_ids": {
                    "summary": "Missing IDs",
                    "value": {
                      "error": "At least one ID is required"
                    }
                  },
                  "invalid_format": {
                    "summary": "Invalid Request Format",
                    "value": {
                      "error": "Invalid request format"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/workflows": {
      "post": {
        "summary": "Create a new workflow",
        "description": "Creates a new workflow associated with a knowledge engine",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateWorkflow"
              },
              "example": {
                "$ref": "#/components/examples/CreateWorkflowRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Workflow created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WorkflowResponse"
                },
                "example": {
                  "$ref": "#/components/examples/WorkflowResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request - Various validation and state errors",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "invalid_knowledge_engine_id": {
                    "summary": "Invalid Knowledge Engine ID",
                    "value": {
                      "error": "Invalid knowledge engine ID"
                    }
                  },
                  "knowledge_engine_not_ready": {
                    "summary": "Knowledge Engine Not Ready",
                    "value": {
                      "error": "knowledge engine is not ready, current status: processing"
                    }
                  },
                  "no_active_data_sources": {
                    "summary": "No Active Data Sources",
                    "value": {
                      "error": "knowledge engine has no active data sources"
                    }
                  },
                  "invalid_model": {
                    "summary": "Invalid Model",
                    "value": {
                      "error": "Model unsupported-model not supported"
                    }
                  },
                  "model_not_enabled": {
                    "summary": "Model Not Enabled",
                    "value": {
                      "error": "Model Claude 3.5 Sonnet is not enabled"
                    }
                  },
                  "missing_required_field": {
                    "summary": "Missing Required Field",
                    "value": {
                      "error": "Key: 'WorkflowRequest.Name' Error:Field validation for 'Name' failed on the 'required' tag"
                    }
                  },
                  "invalid_json": {
                    "summary": "Invalid JSON",
                    "value": {
                      "error": "invalid character '}' looking for beginning of object key string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "Unauthorized"
                }
              }
            }
          },
          "500": {
            "description": "Internal Server Error - Processing failures",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "rag_service_failure": {
                    "summary": "RAG Service Failure",
                    "value": {
                      "error": "Failed to process query: connection timeout"
                    }
                  },
                  "database_error": {
                    "summary": "Database Transaction Error",
                    "value": {
                      "error": "Failed to create workflow: database connection lost"
                    }
                  },
                  "document_retrieval_error": {
                    "summary": "Document Retrieval Error",
                    "value": {
                      "error": "Failed to retrieve documents: vector database unavailable"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/knowledge-engines/{id}/retrieve": {
      "post": {
        "summary": "Retrieve Chunks",
        "description": "Returns raw retrieved chunks from a knowledge engine without streaming or workflow creation",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Knowledge engine ID"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["query"],
                "properties": {
                  "query": {
                    "type": "string",
                    "description": "The natural language query used to retrieve relevant chunks"
                  },
                  "data_source_id": {
                    "type": "string",
                    "description": "Optional data source ID to constrain retrieval to a single source"
                  },
                  "top_k": {
                    "type": "integer",
                    "description": "Maximum number of chunks to return. Defaults to 5; values above 20 are clamped to 20.",
                    "default": 5,
                    "minimum": 1,
                    "maximum": 20
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Retrieved chunks for the knowledge engine",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/KnowledgeEngineRetrieveResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request - invalid IDs or malformed payload",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "invalid_knowledge_engine_id": {
                    "summary": "Invalid Knowledge Engine ID",
                    "value": {
                      "error": "Invalid knowledge engine ID"
                    }
                  },
                  "invalid_data_source_id": {
                    "summary": "Invalid Data Source ID",
                    "value": {
                      "error": "Invalid data source ID"
                    }
                  },
                  "mismatched_data_source_id": {
                    "summary": "Data Source Ownership Mismatch",
                    "value": {
                      "error": "Data source does not belong to this knowledge engine"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "Unauthorized"
                }
              }
            }
          },
          "404": {
            "description": "Knowledge engine or data source not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal Server Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "Internal server error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/knowledge-engines/{id}/query": {
      "post": {
        "summary": "Query Knowledge Engine",
        "description": "Streams a response to a natural language query using Server-Sent Events",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Knowledge engine ID"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["query", "name"],
                "properties": {
                  "query": {
                    "type": "string",
                    "description": "The natural language query"
                  },
                  "name": {
                    "type": "string",
                    "description": "Name of the workflow"
                  },
                  "advanced_reasoning": {
                    "type": "boolean",
                    "description": "Enable advanced reasoning"
                  },
                  "model": {
                    "type": "string",
                    "description": "LLM to use for the query",
                    "enum": ["auto", "claude-4.5-sonnet", "llama-v3-70b", "llama-4-scout", "llama-4-maverick", "gemini-2.5", "gpt-5.4", "claude-4.6-haiku", "gpt-4.1"],
                    "example": "llama-v3-70b"
                  },
                  "context_id": {
                    "type": "string",
                    "description": "Context ID for maintaining conversation history in chat mode"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Streaming response using Server-Sent Events",
            "content": {
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request - Various validation and state errors",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "invalid_knowledge_engine_id": {
                    "summary": "Invalid Knowledge Engine ID",
                    "value": {
                      "error": "Invalid knowledge engine ID"
                    }
                  },
                  "knowledge_engine_not_ready": {
                    "summary": "Knowledge Engine Not Ready",
                    "value": {
                      "error": "knowledge engine is not ready, current status: processing"
                    }
                  },
                  "no_active_data_sources": {
                    "summary": "No Active Data Sources",
                    "value": {
                      "error": "knowledge engine has no active data sources"
                    }
                  },
                  "invalid_model": {
                    "summary": "Invalid Model",
                    "value": {
                      "error": "Model unsupported-model not supported"
                    }
                  },
                  "model_not_enabled": {
                    "summary": "Model Not Enabled",
                    "value": {
                      "error": "Model Claude 3.5 Sonnet is not enabled"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "Unauthorized"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "CreateKnowledgeEngine": {
        "type": "object",
        "required": ["name"],
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 50,
            "description": "Name of the knowledge engine",
            "example": "Fintech Companies"
          },
          "description": {
            "type": "string",
            "description": "Short description of what the knowledge engine is comprised of",
            "example": "Knowledge engine for processing and analyzing fintech companies"
          },
          "notes": {
            "type": "object",
            "description": "Custom attributes and fields",
            "example": {
              "tags": "fintech, startups, venture capital"
            }
          }
        }
      },
      "KnowledgeEngineResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Alphanumeric 14 character string identifier",
            "example": "kng_abc123xyz789"
          },
          "name": {
            "type": "string",
            "description": "Name of the knowledge engine",
            "example": "Fintech Companies"
          },
          "description": {
            "type": "string",
            "description": "Description of the knowledge engine",
            "example": "Knowledge engine for processing and analyzing fintech companies"
          },
          "notes": {
            "type": "object",
            "description": "Custom attributes and fields",
            "example": {
              "category": "fintech"
            }
          },
          "status": {
            "type": "string",
            "enum": ["processing", "ready"],
            "description": "Current status of the knowledge engine",
            "example": "ready"
          },
          "created_at": {
            "type": "integer",
            "format": "int64",
            "description": "Unix timestamp when this entity was created",
            "example": 1679644800
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "description": "Error message",
            "example": "Invalid knowledge engine name: exceeds maximum length of 50 characters"
          }
        }
      },
      "DuplicateFileError": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "description": "Error message",
            "example": "Duplicate file"
          }
        }
      },
      "CreateDataSource": {
        "type": "object",
        "required": ["knowledge_engine_id"],
        "properties": {
          "name": {
            "type": "string",
            "description": "Name of the data source",
            "example": "Annual Report 2023"
          },
          "type": {
            "type": "string",
            "enum": ["file", "ticket"],
            "description": "Type of the data source",
            "example": "file"
          },
          "notes": {
            "type": "object",
            "description": "Custom attributes and fields",
            "example": {
              "category": "financial",
              "department": "accounting"
            }
          },
          "knowledge_engine_id": {
            "type": "string",
            "description": "ID of the knowledge engine this data source belongs to",
            "example": "kng_abc123xyz789"
          },
          "file": {
            "type": "string",
            "format": "binary",
            "description": "The file to upload"
          }
        }
      },
      "DataSourceResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique identifier for the data source",
            "example": "ds_abc123xyz789"
          },
          "name": {
            "type": "string",
            "description": "Name of the data source",
            "example": "Annual Report 2023"
          },
          "type": {
            "type": "string",
            "description": "Type of the data source",
            "enum": ["file", "ticket"],
            "example": "file"
          },
          "status": {
            "type": "string",
            "enum": ["processing", "processed"],
            "description": "Current status of the data source",
            "example": "processed"
          },
          "notes": {
            "type": "object",
            "description": "Custom attributes and fields",
            "example": {
              "category": "financial"
            }
          },
          "knowledge_engine_id": {
            "type": "string",
            "description": "ID of the knowledge engine this data source belongs to",
            "example": "kng_abc123xyz789"
          },
          "created_at": {
            "type": "integer",
            "format": "int64",
            "description": "Unix timestamp when this entity was created",
            "example": 1679644800
          }
        }
      },
      "KnowledgeEngineRetrieveChunk": {
        "type": "object",
        "properties": {
          "content": {
            "type": "string",
            "description": "The raw chunk text"
          },
          "filename": {
            "type": "string",
            "description": "The source filename when available"
          },
          "chunk_id": {
            "type": "string",
            "description": "Identifier for the retrieved chunk"
          },
          "data_source_id": {
            "type": "string",
            "description": "Public data source ID associated with the chunk"
          },
          "page_number": {
            "type": "integer",
            "description": "Source page number for the chunk. Returns -1 for non-page-backed chunks (for example, spreadsheet rows).",
            "example": -1
          }
        }
      },
      "KnowledgeEngineRetrieveResponse": {
        "type": "object",
        "properties": {
          "query": {
            "type": "string",
            "description": "The original query string"
          },
          "knowledge_engine_id": {
            "type": "string",
            "description": "Public ID of the queried knowledge engine",
            "example": "kng_abc123xyz789"
          },
          "data_source_id": {
            "type": "string",
            "description": "Public ID of the queried data source when request was scoped to one source",
            "example": "ds_abc123xyz789"
          },
          "chunks": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/KnowledgeEngineRetrieveChunk"
            }
          },
          "total_chunks": {
            "type": "integer",
            "description": "Number of chunks returned"
          }
        }
      },
      "CreateDataSourceBatch": {
        "type": "object",
        "required": ["files", "data"],
        "properties": {
          "files": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "binary",
              "description": "A file to upload"
            },
            "description": "List of files to upload"
          },
          "data": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string",
                  "description": "Name of the data source"
                },
                "type": {
                  "type": "string",
                  "enum": ["file", "ticket"],
                  "description": "Type of the data source"
                },
                "notes": {
                  "type": "object",
                  "description": "Custom attributes and fields"
                },
                "knowledge_engine_id": {
                  "type": "string",
                  "description": "ID of the knowledge engine this data source belongs to"
                }
              }
            },
            "description": "List of data sources to create"
          }
        }
      },
      "DataSourceBatchResponse": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "name": {
              "type": "string",
              "description": "Name of the data source"
            },
            "success": {
              "type": "boolean",
              "description": "Data source creation status"
            },
            "error": {
              "type": "string",
              "description": "Error message if the data source was not created successfully"
            },
            "data_source": {
              "$ref": "#/components/schemas/DataSourceResponse"
            }
          }
        }
      },
      "CreateWorkflow": {
        "type": "object",
        "required": ["name", "query", "knowledge_engine_id", "type"],
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 50,
            "description": "Name of the workflow",
            "example": "Fintech Companies"
          },
          "query": {
            "type": "string",
            "description": "The query to ask the knowledge engine",
            "example": "What is the latest revenue of Square?"
          },
          "knowledge_engine_id": {
            "type": "string",
            "description": "ID of the knowledge engine this workflow belongs to",
            "example": "kng_abc123xyz789"
          },
          "type": {
            "type": "string",
            "enum": ["query"],
            "description": "Type of the workflow",
            "example": "query"
          },
          "description": {
            "type": "string",
            "description": "Short description of what the workflow is comprised of",
            "example": "Workflow for processing and analyzing fintech companies"
          },
          "context_id": {
            "type": "string",
            "description": "Context ID used in case of thread mode for chat based workflows",
            "example": "ctx_abc123xyz78910"
          },
          "advanced_reasoning": {
            "type": "boolean",
            "description": "Flag to enable advanced reasoning for the workflow",
            "example": true
          },
          "model": {
            "type": "string",
            "description": "LLM to use for the query",
            "enum": ["auto", "claude-4.5-sonnet", "llama-v3-70b", "llama-4-scout", "llama-4-maverick", "gemini-2.5", "gpt-5.4", "claude-4.6-haiku", "gpt-4.1"],
            "example": "llama-v3-70b"
          }
        }
      },
      "WorkflowResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Alphanumeric 14 character string identifier",
            "example": "wfl_abc123xyz78910"
          },
          "name": {
            "type": "string",
            "description": "Name of the workflow",
            "example": "Fintech Companies"
          },
          "query": {
            "type": "string",
            "description": "The query to ask the knowledge engine",
            "example": "What is the latest revenue of Square?"
          },
          "response": {
            "type": "string",
            "description": "The response from the knowledge engine",
            "example": "Square's latest revenue is $1.2 billion"
          },
          "context_id": {
            "type": "string",
            "description": "Context ID used in case of thread mode for chat based workflows",
            "example": "ctx_abc123xyz78910"
          },
          "advanced_reasoning": {
            "type": "boolean",
            "description": "Flag to enable advanced reasoning for the workflow",
            "example": true
          },
          "model": {
            "type": "string",
            "description": "LLM to use for the query",
            "enum": ["auto", "claude-4.5-sonnet", "llama-v3-70b", "llama-4-scout", "llama-4-maverick", "gemini-2.5", "gpt-5.4", "claude-4.6-haiku", "gpt-4.1"],
            "example": "llama-v3-70b"
          },
          "citations": {
            "type": "array",
            "description": "List of citations referenced in the response, or null if no citations are available",
            "items": {
              "type": "object",
              "properties": {
                "citation_key": {
                  "type": "string",
                  "description": "Key used to reference this citation in the response",
                  "example": "<source_id=1>"
                },
                "data_source_id": {
                  "type": "string",
                  "description": "ID of the data source containing this citation",
                  "example": "dsc_n5kdefxua5fnrd"
                },
                "file_name": {
                  "type": "string",
                  "description": "Name of the source file",
                  "example": "report.pdf"
                },
                "page_number": {
                  "type": "integer",
                  "description": "Page number where the citation appears",
                  "example": 4
                }
              }
            }
          },
          "status": {
            "type": "string",
            "enum": ["PROCESSING", "PROCESSED"],
            "description": "Current status of the workflow",
            "example": "PROCESSED"
          },
          "created_at": {
            "type": "integer",
            "format": "int64",
            "description": "Unix timestamp when this entity was created",
            "example": 1679644800
          }
        }
      }
    },
    "examples": {
      "CreateKnowledgeEngineRequest": {
        "value": {
          "name": "My Knowledge Engine",
          "description": "A sample knowledge engine",
          "notes": {
            "custom_field": "value",
            "priority": "high"
          }
        }
      },
      "KnowledgeEngineResponse": {
        "value": {
          "id": "kng_v62llr4fhbc2nl",
          "name": "My Knowledge Engine",
          "description": "A sample knowledge engine",
          "notes": {
            "custom_field": "value",
            "priority": "high"
          },
          "created_at": 1679644800
        }
      },
      "CreateDataSourceRequest": {
        "value": {
          "file": "<binary file content>",
          "data": "{\"name\":\"Annual Report 2023\",\"type\":\"file\",\"notes\":{\"category\":\"financial\",\"department\":\"accounting\"},\"knowledge_engine_id\":\"kng_abc123xyz789\"}"
        }
      },
      "DataSourceResponse": {
        "value": {
          "id": "ds_abc123xyz789",
          "name": "Annual Report 2023",
          "type": "file",
          "status": "processing",
          "notes": {
            "category": "financial",
            "department": "accounting"
          },
          "knowledge_engine_id": "kng_abc123xyz789",
          "created_at": 1679644800
        }
      },
      "CreateDataSourceBatchRequest": {
        "value": {
          "files": [
            "<binary file content>",
            "<binary file content>"
          ],
          "data": [
            {
              "name": "Annual Report 2023",
              "type": "file",
              "notes": {
                "category": "financial"
              },
              "knowledge_engine_id": "kng_abc123xyz789"
            },
            {
              "name": "Q4 Metrics",
              "type": "file",
              "notes": {
                "category": "metrics"
              },
              "knowledge_engine_id": "kng_abc123xyz789"
            }
          ]
        }
      },
      "DataSourceBatchResponse": {
        "value": [
          {
            "id": "", 
            "success": false,
            "name": "Annual Report 2023",
            "error": "duplicate file"
          },
          {
            "id": "dsc_drwzwmsvdffshe", 
            "success": true,
            "name": "Q4 Metrics"
          }
        ]
      },
      "DataSourceListResponse": {
        "value": [
          {
            "id": "ds_abc123xyz789",
            "name": "Annual Report 2023",
            "type": "file",
            "status": "processed",
            "notes": {
              "category": "financial"
            },
            "knowledge_engine_id": "kng_abc123xyz789",
            "created_at": 1679644800
          },
          {
            "id": "ds_def456uvw321",
            "name": "Q4 Metrics",
            "type": "file",
            "status": "processing",
            "notes": {
              "category": "metrics"
            },
            "knowledge_engine_id": "kng_abc123xyz789",
            "created_at": 1679644900
          }
        ]
      },
      "CreateWorkflowRequest": {
        "value": {
          "name": "Revenue Analysis",
          "query": "What is the latest revenue of Square?",
          "description": "Workflow to analyze financial metrics of fintech companies",
          "context_id": "ctx_abc123xyz789",
          "advanced_reasoning": true,
          "model": "llama-v3-70b"
        }
      },
      "WorkflowResponse": {
        "value": {
          "id": "wfl_abc123xyz789",
          "name": "Revenue Analysis",
          "query": "What is the latest revenue of Square?",
          "response": "Square's latest revenue is $1.2 billion <source_id=1>",
          "context_id": "ctx_abc123xyz789",
          "advanced_reasoning": true,
          "model": "llama-v3-70b",
          "citations": [
            {
              "citation_key": "<source_id=1>",
              "data_source_id": "dsc_n5kdefxua5fnrd",
              "file_name": "report.pdf",
              "page_number": 4
            }
          ],
          "status": "PROCESSED",
          "created_at": 1679644800
        }
      }
    }
  }
}
