Timeout Error When Uploading Large Files to Azure OpenAI Assistant Service

Su Myat Hlaing 160 Reputation points
2024-09-04T00:30:51.65+00:00

Hi,
I'm encountering a timeout error when trying to upload large files 260 MB (up to 512MB) to the Azure OpenAI service using the assistantsClient.uploadFile method. I understand that can upload 512MB 20 files. The error occurs after the upload begins, and the operation fails with the following message:


try {

          const fileUploadPromises = files.map(async (file) => {
            // Read the content from the uploaded file in binary mode
            const fileContent = await fs.promises.readFile(file.path);
            // Define the filename for the upload
            const filename = Buffer.from(file.originalname, 'latin1').toString('utf8');
            console.log("before file upload to assistant..");
            // Upload the binary file content using Assistants SDK
            const uploadAssistantFile = await assistantsClient.uploadFile(fileContent, "assistants", { filename });
            console.log("after upload file to assistant..");

            return { fileId: uploadAssistantFile.id, filename: filename };
        });

          // Wait for all file uploads to complete
          const fileIdsWithNames = await Promise.all(fileUploadPromises);

          // Extract fileIds and filenames separately
          const fileIds = fileIdsWithNames.map(file => file.fileId);
          const filenames = fileIdsWithNames.reduce((acc, file) => {
              acc[file.fileId] = file.filename;
              return acc;
          }, {});

         
          // Create an assistant using Assistants SDK
          const assistantResponse = await assistantsClient.createAssistant({
              model: model,
              name: name,
              instructions: instructions,
              tools: [{ type: "code_interpreter" }],
              fileIds: fileIds,
          });

          console.log("Assistant created:", assistantResponse);

--------------------------------------------------------
Error creating assistant: RestError: The operation was timeout. 
 {
  "name": "RestError",
  "code": "Timeout",
  "statusCode": 408,
  "request": {
    "url": "https://..openai.azure.com/openai/files?api-version=2024-02-15-preview",
    "headers": {
      "accept": "application/json",
      "content-type": "multipart/form-data; boundary=----AzSDKFormBoundaryef1d4792-52b5-4075-a08c-f241f7507291",
      "accept-encoding": "gzip,deflate",
      "user-agent": "azsdk-js-openai-assistants-rest/1.0.0-beta.5 core-rest-pipeline/1.14.0 Node/v16.20.2 OS/(x64-Windows_NT-10.0.22631)",
      "x-ms-client-request-id": "2c69947f-f245-42e2-a120-d89479e7864f",
      "api-key": "REDACTED",
      "content-length": "276437299"
    },
    "method": "POST",
    "timeout": 0,
    "disableKeepAlive": false,
    "withCredentials": false,
    "requestId": "2c69947f-f245-42e2-a120-d89479e7864f",
    "allowInsecureConnection": false,
    "enableBrowserStreams": true
  },
  "message": "The operation was timeout."
}

I'm looking for guidance on:

  1. Whether there is a specific timeout limit imposed by the Azure OpenAI service for file uploads.
  2. Best practices for handling large file uploads to avoid timeouts.
  3. Any server-side configurations or SDK options that can help mitigate this issue.

Any advice or insights would be greatly appreciated!

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
3,132 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. AshokPeddakotla-MSFT 34,111 Reputation points
    2024-09-04T07:59:43.73+00:00

    Su Myat Hlaing Greetings!

    Please see below answers to your queries.

    Whether there is a specific timeout limit imposed by the Azure OpenAI service for file uploads.

    AFAIK, Azure OpenAI service has a maximum file size limit of 512MB per file for uploads. However, there isn't a specific timeout limit mentioned in file uploads. The timeout error you're encountering might be due to network latency or other factors affecting the upload process.

    Best practices for handling large file uploads to avoid timeouts.

    You can try below approaches.

    • Break large files into smaller chunks and upload them sequentially to manage network bandwidth and reduce the risk of timeouts.
    • Implement streaming to process files as they are uploaded, avoiding the need to store the entire file in memory.
    • Compress large files before uploading them to reduce their size and the time required for the upload.

    Any server-side configurations or SDK options that can help mitigate this issue.

    Try using asynchronous uploads and see if it helps.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.