TypeError: Messages.create() got an unexpected keyword argument 'file_ids'

After uploading some files and storing their ids in an array called files_id, I’m creating a message with the files_id.


message = client.beta.threads.messages.create(thread_id=my_thread.id,
                                                    role="user",
                                                    content=user_message,
                                                  file_ids=files_id
      )

Getting TypeError: Messages.create() got an unexpected keyword argument ‘file_ids’.

1 Like

You have to use attachments to attach files and tools:

      "attachments": [
        { "file_id": message_file.id, "tools": [{"type": "file_search"}] }
      ],
3 Likes

I’m getting this error: “openai.BadRequestError: Error code: 400 - {‘error’: {‘message’: “Unknown parameter: ‘attachments’.”, ‘type’: ‘invalid_request_error’, ‘param’: ‘attachments’, ‘code’: ‘unknown_parameter’}}” but my payload looks fine based off what you’re saying sps:

API Payload: {'thread_id': 'thread_tzYfdoF62ng0xZOuaoysWGAh', 'role': 'user', 'content': "Load the assigned dataset and send the message 'Dataset loaded' once complete", 'attachments': [{'file_id': 'assistant-28LGp2EGC11yUCD1VLB6qA0k', 'tools': [{'type': 'code_interpreter'}]}]}

Quoted so we can see what is attempted.

If you are sending to the API without a library, the thread ID is not part of the body when adding a message; it is part of the URL:

POST https://api.openai.com/v1/threads/{thread_id}/messages

or for initial thread creation:

POST https://api.openai.com/v1/threads

Using the messages parameter at initial thread creation, and showing one of several messages possible there, this is how a file attachment is given within the list of attachments.

messages=[
    {
        "role": "user",
        "content": "List files in Python mount point.",
        "attachments": [
          {
              "file_id": file_id,
              "tools": [{"type": "code_interpreter"}]
          }
      ]
    },
]

or creating a message with Python.

message = client.beta.threads.messages.create(
  thread_id,
  role="user",
  content="List files in Python mount point.",
  attachments=[
      {
          "file_id": file_id,
          "tools": [{"type": "code_interpreter"}]
      }
  ]
)
print(message.model_dump())

This pattern is for user-uploaded files that are only part of the one conversation.

1 Like

That’s helpful, thank you! Tried to replicate what you have:

conversation = {}
ASSISTANT_ID = 'asst_oOXxgFc9ERb4FwEMXPO3e2FE'
thread = thread_manager.create_thread()
conversation['thread_id'] = thread['id']
message = client.beta.threads.messages.create(
    thread_id=conversation['thread_id'], 
    role='user', 
    content=startup_prompt, 
    attachments = [
        {
            "file_id": "assistant-28LGp2EGC11yUCD1VLB6qA0k",
            "tools": ["code_interpreter"]
        }
    ]
    )
print(message.model_dump())

But I get this error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[35], line 5
      3 thread = thread_manager.create_thread()
      4 conversation['thread_id'] = thread['id']
----> 5 message = client.beta.threads.messages.create(
      6     thread_id=conversation['thread_id'], 
      7     role='user', 
      8     content=startup_prompt, 
      9     attachments = [
     10         {
     11             "file_id": "assistant-28LGp2EGC11yUCD1VLB6qA0k",
     12             "tools": ["code_interpreter"]
     13         }
     14     ]
     15     )
     16 print(message.model_dump())

TypeError: Messages.create() got an unexpected keyword argument 'attachments'

I’m running 1.53.0 of the Python library, not sure if that is causing the argument to not be recognized. I’m also using the Azure OpenAI Assistants client, the API version is 2024-02-15-preview, not sure if that also is causing the problem

You still are not sending the attachments correctly. Just compare the code block you pasted to what is immediately before, you’ll see “tools” objects is NOT replicated.

Azure requires particular regions and deployment for code interpreter.

You will want to bump the api up to as new as 2024-10-01-preview - remember, v2 header came significantly after your date.

I tried this in PHP, and I get the same error.

function createThreadWithFile($api_key, $thread_id, $message, $vector_id) {
$url = “https://api.openai.com/v1/threads/$thread_id/messages”;
$data = [
‘role’ => ‘user’,
‘content’ => $message,
‘attachments’ => [
‘tools’ => [
‘type’ => ‘file_search’ // Passando o ID do arquivo como vetor
]
]
];
return curlAPIPost($api_key, $url, $data);
}

Erro: HTTP Error #:400 Response: { "error": { "message": "Unknown parameter: 'attachments'.", "type": "invalid_request_error", "param": "attachments", "code": "unknown_parameter" } }