How to get formatting from assistant API?

I have an assistant that I call the following way

  await openai.beta.threads.messages.create(thread.id, {
    role: 'user',
    content: generateUserDefaultMessage({
      challenge,
    }),
  });
  const run = await openai.beta.threads.runs.createAndPoll(thread.id, {
    assistant_id: assistantService.getAssistant().id,
    instructions: generateAssistantDefaultAnalysis(),
    response_format: zodResponseFormat(
      AssistantAnalysis,
      'ranalysis'
    ),
  });

Now from the DOC I see I need to do

  if (run.status === 'completed') {
    const messages = await openai.beta.threads.messages.list(run.thread_id) ;
    const message = messages.data?.at(-1);
  // message is my message

But how do I access the parsed version like the doc for GPT suggest ?

Is there some failure in my implementation ?

Usually, openai’s methods will return exactly that object (pretty convenient) so I just have to .thisproperty or .thatmethod right away. Can you check your variables if their types are parsed?

I had expected the run response to have the message response in it somewhere like it does for a structured function response, but it didn’t. So here is how I am doing this, but I will keep an eye out here to see if there is some best practice others can share. This obviously could better handle conditions where there are missing or more data & content values but I am not sure yet under what conditions that could be the case.

const messages = await openai.beta.threads.messages.list(run.thread_id);
const lastMessageText = messages.data[0].content[0].text.value;
const parsedResult = JSON.parse(lastMessageText);