To chat with a file, use the /files/[file id]/chat endpoint. Pass your chat message as the parameter 'message' in either the URL or request body.
Your file's processed_state must be 'processed' in order to chat with it. This usually takes a few seconds after uploading, so be sure to wait if your workflow involves uploading and immediately chatting with it. You can either use the /files/[file id]/info endpoint to check the processed_state, or just use this /files/[file id]/chat endpoint but check its response to ensure it succeeded. (You will get an error response if you try to chat with a file that is not yet 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 file via API:
require 'net/http'
require 'net/https'
require 'uri'
require 'json'
uri = URI.parse("https://api1.docalysis.com/api/v1/files/[file 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 was this company's revenue in 2022?"
})
req_options = {
use_ssl: true,
}
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
http.request(request)
end
puts response.body