Not allowed to download files of purpose: assistants

I’m testing different parts of the Assistants API and I stumbled upon a problem when retrieving file content.

When I run client.files.retrieve_content(file_id) as described here, I get Error code 400 - Not allowed to download files of purpose: assistants with type invalid_request_error.

I can get a list of files, pull their IDs, get info about the file, upload a new one, or remove it, but can’t download it (or get the content of the file)?

Can you try via Assistant object?

async function main() {
  const myAssistantFile = await openai.beta.assistants.files.retrieve(
    "asst_abc123",
    "file-abc123"
  );
  console.log(myAssistantFile);
}

See Reference page

Only files that are generated by assistants (e.g., files generated by the code interpreter tool) can be downloaded. You can’t download files that you’ve uploaded to the assistants yourself. If these files are important, you should consider storing a copy of these files before they’re uploaded.

5 Likes

I was getting the same error, until I realize that the file I was trying to download wasn’t the generated file but a file that was part of my initial message. You should iterate over your messages to get files that are generated by gpt, and make sure you download those. You should also make sure that the file you try to create an image for is indeed image file. You can verify that by checking the type attribute of message content

I think this is the case - it seems to not be possible to download the files attached to assistants, even if the file was uploaded through API and not attached to a specific assistant, it’s still not downloadable.

The client.files.content("file-abc123") works, but only with files generated through the threads.

It’s not ideal, but when I’m creating any dynamic files that I want to make accessible to assistants, I keep a local copy with info about the ID coming back from the API so I can reference it later from local storage.