How to use the assistant's API to create a feature that converts DOCX and Excel files to Markdown?

I am trying to complete this feature using the Azure OpenAI SDK, but I always encounter errors when adding the file ID in the create_message step. Can any hero tell me how to do this, and can you help me write the API call process? Below is my code:

import fs from 'node:fs'
import { setLogLevel } from '@azure/logger'
import { AssistantsClient } from '@azure/openai-assistants'
import { AzureKeyCredential } from '@azure/openai'


const assistantsClient = new AssistantsClient(
	new AzureKeyCredential(apiKey),
	{ apiVersion: "2024-05-01-preview", allowInsecureConnection: true}

const run = async () => {
// 0. upload file
	const filename = "example.docx";
	const docx = fs.readFileSync(filename)
	const uploadAssistantFile = await assistantsClient.uploadFile(
		docx, "assistants", { filename }

// 1. create assistant
	const assistant = await assistantsClient.createAssistant({
		model: "gpt-4-0125",
		name: "office converter",
		instructions: "you are a office file converter,help user convert office file to other format",
		tools: [{ type: "code_interpreter" }], // ? I am using code_interpreter here, but I am not sure if it is correct.


// 2. create thread
	const assistantThread = await assistantsClient.createThread();

	//3. create message to add to thread
	const question = "please convert the docx file to markdown";
	const messageResponse = await assistantsClient.createMessage(, "user", question, {
		fileIds: [], // This is where the error occurs; it always prompts that file_ids is an invalid parameter, with status code 400.


	let runResponse = await assistantsClient.createRun(, {
		instructions: "Please convert the docx file to markdown",

	do {
		await new Promise((resolve) => setTimeout(resolve, 5000));
		runResponse = await assistantsClient.getRun(,;
		if (runResponse.status === "failed") {
			throw new Error("Run failed");
	} while (runResponse.status === "queued" || runResponse.status === "in_progress")

	await new Promise((resolve) => setTimeout(resolve, 30000));

	const runMessages = await assistantsClient.listMessages(;
	for (const runMessageDatum of {
		for (const item of runMessageDatum.content) {
			console.log('\n:::::', item, ':::::\n')



This part of the API has recently changed … Check the attachments session of this page.

Thanks a lot,Am I using the code_interpreter correctly?

It seems that there is no relevant community for Azure. :worried:

I think you code is wrong, Im doing this on my side to make the code_execution working!

        await openai.beta.threads.update(threadId!, {
                code_interpreter: {
                    file_ids: [],

You can find the full code on my github on how I make it work

Thank you very much, I will refer to it.

1 Like