Hello, I’m using Xano.com for my web app’s backend and need to upload an image to OpenAI to use with the assistant. I’m trying to create the file using the OpenAI API at https://platform.openai.com/docs/api-reference/files/create. I’m not sure what to put for the ‘file’ part, and I don’t think I can just add the image URL as the file. How can I send that file via the API?
Based on the information from the OpenAI API documentation for file uploads, here’s a more detailed explanation of how to upload an image file for use with OpenAI’s assistant:
The API requires the actual File object to be uploaded, not just the file name or URL. This means you need to have the image file itself ready in the format that the OpenAI API can accept.
file: This is the File object you want to upload. If you have an image URL from Xano, you need to first download this image to your local system or server, then prepare it for upload.
purpose: This is a string that indicates the intended use of the file. For use with Assistants, you should set this to “assistants”.
Uploading the File:
Make a POST request to https://api.openai.com/v1/files with the file and purpose as part of the request body.
The request should be made with multipart/form-data content type since you are uploading a file.
Ensure that the API key for OpenAI is included in the header for authentication.
Handling File Size Limits:
The maximum size for individual files is 512 MB, and the total size of all files uploaded by one organization can be up to 100 GB.
Using the Uploaded File:
After successful upload, the API will return a File object. This object can then be used across various OpenAI endpoints as required.
In your case, since you’re dealing with an image from Xano, the critical step is downloading the image from Xano and preparing it as a File object for the POST request to the OpenAI API. You cannot directly use the image URL for this upload; the image must first be retrieved and then uploaded as a file.
image_url = 'https://example.com/your-image.jpg'
response = requests.get(image_url)
if response.status_code == 200:
with open('image.jpg', 'wb') as f:
Thanks for your help @PaulBellow.
I finally was able to figure out the solution for Xano. For those interested, the key is to use the Create File Resource function within Xano’s function stack. Then, simply send the output variable from this file resource as the ‘File’ element in the Open AI API call and it worked!