#How do I get the raw response using the Node.js SDK?

1 messages · Page 1 of 1 (latest)

opal garden
#

I'm trying to save a file in node but it's returning a string. I've been told to use the API directly but the Python SDK supports files.with_raw_response

#

Code for reference

async function fileTest() {
    const file = await openai.files.retrieveContent("file-CrEM19MAQeV2UqvCTCkgPN3w");
    fs.writeFileSync("./test.png", Buffer.from(file));
}
burnt glen
#

Having the same problem here. Looks like the python client is more flexible 😦

opal garden
#

It's a pain but you gotta do what you gotta do

burnt glen
#

I think this is not the best way to do it but sort of figured it out ```const main = async () => {
const writeStream = createWriteStream(__dirname + "/myImage.png");

const response = await fetch(
"https://api.openai.com/v1/files/{file-id}/content",
{
headers: {
Authorization:
"Bearer {Your OpenAI key}",
},
}
).then((res) => res.blob());

response.arrayBuffer().then((buffer) => {
writeStream.write(Buffer.from(buffer));
});
};

main();

#

Let me know if that works or if you have a better way to do it 🙌

opal garden
#

I think that's the only way to do it right now. Just gotta wait for OpenAI to come up with a fix because I don't wanna have to write that every time I have a project like this one.