How to specify file name when uploading a file with Python API

I am uploading a file using the Python API with the following code:

file = client.files.create(
  file=open("", "rb"),

However all my uploads appear as “upload” in the file section. How can I change the displayed name to something more friendly? I tried to use the query_param but with no success. Thank you

What is the “file section”?

You can write your own file browser and get the file objects, to present as you wish:

  "id": "file-abc123",
  "object": "file",
  "bytes": 120000,
  "created_at": 1677610602,
  "filename": "salesOverview.pdf",
  "purpose": "assistants",

There is no other metadata that you can add, except by tracking with your own database.

You could thus make your own “assistants file attacher” interface or such.

You can use a tuple like this:

with open("", "rb") as fp:
    file = client.files.create(
        file=("", fp),

After struggling with the same problem, I found the answer by digging through the OpenAI code: openai._types.FileTypes.

1 Like