FG
💻 Software🤖 AI & LLMsOpenAI

files.retrieveContent only returns strings, and not bytes/binary data

Fresh5 days ago
Mar 14, 20260 views
Confidence Score50%
50%

Problem

Confirm this is a Node library issue and not an underlying OpenAI API issue - [X] This is an issue with the Node library Describe the bug See this issue for the python library. I don't see an equivalent method to with_raw_response in the node sdk. To Reproduce [code block] This saves a corrupt file, though the file can be downloaded from the playground without a problem. Code snippets _No response_ OS windows 11 Node version Node.js v20.9.0 Library version "openai": "^4.16.1"

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Implement Raw Response Handling for Binary Data in Node SDK

Medium Risk

The Node.js OpenAI library does not currently support retrieving raw binary data directly from the API responses, which results in files being saved as corrupt strings instead of proper binary files. This is due to the absence of a method equivalent to Python's 'with_raw_response' that allows for raw response handling.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Check for Existing Raw Response Methods

    Review the latest OpenAI Node.js SDK documentation and source code to confirm the absence of a method for raw response handling similar to Python's 'with_raw_response'.

  2. 2

    Modify the SDK to Include Raw Response Handling

    Implement a new method in the Node.js SDK that allows users to request raw binary data from the API. This method should handle the response as a Buffer instead of a string.

    typescript
    const response = await openai.files.retrieveContent({ fileId, raw: true });
    const binaryData = Buffer.from(response.data);
  3. 3

    Update Documentation

    Once the new method is implemented, update the SDK documentation to include examples of how to use the raw response feature for binary file retrieval.

  4. 4

    Test the New Functionality

    Create unit tests to verify that the new method correctly retrieves binary data and that files saved using this method are not corrupt.

    typescript
    it('should retrieve binary data correctly', async () => {
      const binaryData = await openai.files.retrieveContent({ fileId, raw: true });
      expect(binaryData).toBeInstanceOf(Buffer);
    });

Validation

Confirm that the new method retrieves binary data correctly by testing it with various file types and ensuring that the saved files are not corrupt. Additionally, verify that the documentation reflects the new functionality.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

openaigptllmapienhancement