Problem: Assistant via API fails to process files, unlike Playground

Hi Community,

I’m using the Assistants API and facing an issue: when I upload a file via the API and send it to the assistant with a prompt, in about 90% of cases the assistant fails to understand the file and does not return a valid JSON response.

At the same time, when I use the same file and the same prompt via the OpenAI Playground, everything works perfectly — the assistant returns the correct JSON.

I’ve confirmed that the file is properly uploaded and marked as processed. It’s attached to the message using the code_interpreter tool, and then a run is executed with the same prompt.

But the result is often either a response saying it can’t understand the file or a plain text output, not a JSON.

My goal is to send a file to the assistant and receive a final result in JSON format. This works reliably in the Playground but fails through the API.

Here’s an example of how I send the message:

await openAiClient.beta.threads.messages.create(thread.id, {
  role: 'user',
  content: prompt,
  attachments: [
    {
      file_id: uploadedFile.id,
      tools: [{ type: 'code_interpreter' }],
    },
  ],
});

await openAiClient.beta.threads.messages.create(thread.id, {
  role: 'user',
  content: prompt,
});

const run = await openAiClient.beta.threads.runs.create(thread.id, {
  assistant_id,
  instructions: prompt,
});

Questions:

  1. Is there a difference in how the Playground interprets files compared to the API?
  2. Should I wait longer after the file is marked as processed before sending the prompt?
  3. Is it necessary to include both the prompt and file in one message, or are separate messages okay?
  4. Is there a way to tell the assistant to “re-read” the file or ensure it uses the file already uploaded?
  5. Could I be missing something in the assistant setup or the way I’m creating threads/runs?

Thanks in advance! I’m happy to share file examples or API responses to help troubleshoot this.