To chat with a directory, use the /directories/[directory id]/chat endpoint. Pass your chat message as the parameter 'message' in either the URL or request body.
Importantly, before you can chat with a file, each file's processed_state must be 'processed' otherwise it won't be ready for chat. This usually takes a few seconds after uploading, so be sure to wait if your workflow involves uploading and immediately chatting with it. You should use the /files/[file id]/info endpoint to check the processed_state, retrying until it is processed.
Each chat message consumes one bonus credit. You can purchase bonus credits at the credits page. You are not charged for errors.
Example response:
{
"success": true,
"response": "The company had $318 million dollars of revenue in 2022."
}
Ruby code to chat with a directory via API:
require 'net/http'
require 'net/https'
require 'uri'
require 'json'
uri = URI.parse("https://api1.docalysis.com/api/v1/directories/[directory id]/chat")
request = Net::HTTP::Get.new(uri)
request["Authorization"] = "Bearer your_api_key_here"
request["Content-Type"] = "application/json"
request.body = JSON.dump({
'message' => "What do these documents say?"
})
req_options = {
use_ssl: true,
}
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
http.request(request)
end
puts response.body