Help with extracting data from a file

I’m trying to use the assistants API to summarize some PDF-s (extract some CSV data). But I’m getting an error after the run ‘completes’ (fails) with a server error…

I still think the issue is with me doing wrong. Here’s how my flow:

  1. Create the file via this URL: “https://api.openai.com/v1/files” (File purpose - assistants).
  2. Create thread.
  3. Create a message in the thread with an Attachment which holds the file ID and the code interpreter tool.
  4. Create run for the thread with an assistant that ‘holds’ every tool.

This is the JSON of the message object

{
  "id": "msg_my_msg_id",
  "created_at": 1731529254,
  "assistant_id": null,
  "thread_id": "thread_my_thread_id",
  "run_id": null,
  "role": "user",
  "content": [
    {
      "type": "text",
      "text": {
        "value": "Build a csv from this data",
        "annotations": []
      },
      "image_file": null,
      "image_url": null
    }
  ],
  "attachments": [
    {
      "file_id": "file-M5mbO7YthlipD7Y6bEw6htDc",
      "tools": [
        {
          "type": "code_interpreter"
        }
      ]
    }
  ],
  "metadata": {}
}

And this is the JSON of the run object I get back right now

{
  "id": "msg_my_msg_id",
  "created_at": 1731529254,
  "assistant_id": null,
  "thread_id": "thread_my_thread_id",
  "run_id": null,
  "role": "user",
  "content": [
    {
      "type": "text",
      "text": {
        "value": "Build a csv from this data",
        "annotations": []
      },
      "image_file": null,
      "image_url": null
    }
  ],
  "attachments": [
    {
      "file_id": "file-M5mbO7YthlipD7Y6bEw6htDc",
      "tools": [
        {
          "type": "code_interpreter"
        }
      ]
    }
  ],
  "metadata": {}
}

My first try was with a PDF file, after it failed, I created a small .txt file just to test, after it failed as well, I came here. Please help me internet.

Any other info I can provide if needed.

One thing to check is the tool setup in your attachment JSON. The code interpreter tool should be linked properly to handle that file, but if something’s off in how it’s assigned, it can throw errors like the one you’re seeing. Adding some debug logs or printing the responses from the API calls step by step might help spot where things are going sideways.