Send an image file via the API from a URL with Xano

Hello, I’m using 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 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:

File Preparation:

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.

Request Body:

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 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.

import requests

image_url = ''
response = requests.get(image_url)

if response.status_code == 200:
    with open('image.jpg', 'wb') as f:
1 Like

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!

1 Like