Create file upload with custom ID?

Is there a way to control the unique ID that is added to an uploaded file? In other words, can I upload a file and simultaneously give it a custom ID, or does Open AI entirely control the ID that gets used?

Welcome @rpivo

file_id is returned in the file object as the result of a successful upload and uniquely identifies files on the org.

It’s not possible to assign a file_id to a file

Good guestion. I thought for sure there would be metadata key like most other objects where you could store your own custom IDs, but I just checked, guess not. Maybe OpenAI can add that, would be useful. All the objects should have optional metadata. Curious, why do you need a custom ID, maybe there’s another way to accomplish what you are trying to do.

image

It’s because I would like to provide a more valuable response from the assistant API. If I know what file the assistant is referring to, then I can enrich the response appropriately. As far as I can tell, the assistant API will tell me the id of the file in an annotation, but not the file name.

What I can do is create a map that maps the id to the file name ahead of time, but it would be easier if I could just give the file a custom ID where the ID has some encoded info in it that would allow me to skip the mapping.

You can use the retrieve file request to query the file object for the file_id.

Every file object has the filename attribute which has the original name of the uploaded file:

{
  "id": "file-abc123",
  "object": "file",
  "bytes": 120000,
  "created_at": 1677610602,
  "filename": "mydata.jsonl",
  "purpose": "fine-tune",
}
1 Like