How to list message content in openai assistants api

I’m using this example code from the api reference:

import OpenAI from "openai";

const secretKey = process.env.OPENAI_API_KEY;
const openai = new OpenAI({
  apiKey: secretKey,
});
async function main() {
  const threadMessages = await openai.beta.threads.messages.list(
    "thread_Vq6jODhz4MMCLREefGCalAQc"
  );

  console.log(threadMessages.data);
  
}

main();

and the response shows up like this

[
  {
    id: 'msg_dqdJfsA9P8LS6HGGLc6UTV19',
    object: 'thread.message',
    created_at: 1699890178,
    thread_id: 'thread_Vq6jODhz4MMCLREefGCalAQc',
    role: 'assistant',
    content: [ [Object] ],
    file_ids: [],
    assistant_id: 'asst_KY63Cucqs8pIXeRcoeJmEYq1',
    run_id: 'run_3RdB35oXNjCIEaOj5l1sATP1',
    metadata: {}
  },
  {
    id: 'msg_dBLzGTjaNYcYriIdHHTxPQ90',
    object: 'thread.message',
    created_at: 1699890174,
    thread_id: 'thread_Vq6jODhz4MMCLREefGCalAQc',
    role: 'assistant',
    content: [ [Object] ],
    file_ids: [],
    assistant_id: 'asst_KY63Cucqs8pIXeRcoeJmEYq1',
    run_id: 'run_3RdB35oXNjCIEaOj5l1sATP1',
    metadata: {}
  },
  {
    id: 'msg_9RJ4soRUk4kgiz3iAHrkshkb',
    object: 'thread.message',
    created_at: 1699890170,
    thread_id: 'thread_Vq6jODhz4MMCLREefGCalAQc',
    role: 'user',
    content: [ [Object] ],
    file_ids: [],
    assistant_id: null,
    run_id: null,
    metadata: {}
  }
]

Why does the text show up as [Object]? I want to just see the plain text.

Any help would be appreciated :smile:

1 Like

Having the same issue- content is being returned as [Object]. Were you able to get this resolved?

Check the Reference page for Message object

{
  "id": "msg_abc123",
  "object": "thread.message",
  "created_at": 1698983503,
  "thread_id": "thread_abc123",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": {
        "value": "Hi! How can I help you today?",
        "annotations": []
      }
    }
  ],
  "file_ids": [],
  "assistant_id": "asst_abc123",
  "run_id": "run_abc123",
  "metadata": {}
}