File Upload
The Hatz API provides the functionality to uploading files, which then you can use the files across both chat and app.
When you successfully upload a file, a file UUID is returned. You can use this UUID as an input in the app builder (if the variable / input is of file upload type) or pass it in an array within the chat completions API.
ExampleCopied!
curl 'https://ai.hatz.ai/v1/files/upload' \
-H 'x-api-key: $HATZ_API_KEY' \
--form 'file=@"/Users/test/Downloads/Invoice-88E8A41B-0011-1.pdf"' \
--form 'only_calculate_tokens="false"'
-
file
is an input of where the file is located on the system. The API just accepts the file straight up, and has a size limit of30mb
currently. -
only_calculate_tokens
is a boolean parameter you can use to see how many tokens the file counts as. LLMs have a max token context window, so if the file exceeds the token limit, then the API will use retrieval and file chunking techniques to reduce the token count when it analyzes the file for you.
Example Response
{
"tokens": 487,
"file_uuid": "8fb5bc1d-5a8d-4015-86a6-b0ca394e7793",
"message": "File uploaded successfully"
}
Chat Completions File ExampleCopied!
Once the file is successfully uploaded, you can then just pass the file_uuid
into the body of a chat completions request
curl 'https://ai.hatz.ai/v1/chat/completions' \
-H 'X-API-Key: $HATZ_API_KEY' \
-H 'Content-Type: application/json' \
-D '{
"messages": [{"role": "user", "content": "tell me about this file"}],
"model": "gpt-4o",
"stream": false,
"file_uuids": ["a90cb2a4-a4d5-4403-9b6a-6def06b0d4af"]
}'
App Builder / Workflow File ExampleCopied!
Similarly, once the file is uploaded, you can then just pass the file_uuid
into the body of an app builder completions request. You would pass the file_uuid
as an input to any input type that is of file_input
For Example:
curl 'https://ai.hatz.ai/v1/app/5ae6e9dd-0296-4409-8fe4-1fc646bb22f7/query' \
-H 'X-API-Key: $HATZ_API_KEY' \
-H 'Content-Type: application/json' \
-D '{
"inputs": {
"jpg_file": "a90cb2a4-a4d5-4403-9b6a-6def06b0d4af",
"pdf_file": "8fb5bc1d-5a8d-4015-86a6-b0ca394e7793"
},
"stream": false
}'
Here my app has two inputs, one the variable name is called jpg_file
and the other is called pdf_file
, simply just passing the file’s UUID as the input value will allow the system to read the file