# How can I access the assistants data through API?

**URL:** <https://community.openai.com/t/how-can-i-access-the-assistants-data-through-api/627366>\
**Category:** API\
**Tags:** gpt-35-turbo, api\
**Created:** [February 15, 2024, 5:42am UTC](https://community.openai.com/t/how-can-i-access-the-assistants-data-through-api/627366 "2024-02-15T05:42:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![admin115](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@admin115](https://community.openai.com/u/admin115)\
**Post date:** [February 15, 2024, 5:42am UTC](https://community.openai.com/t/how-can-i-access-the-assistants-data-through-api/627366/1 "2024-02-15T05:42:04Z")

</div>

I have trained my assistance with my data.

I have the assistance ID, API key, and thread ID how can I access the trained data using the assistance API?

I want to retrieve my trained data through API using node js.

```auto
const OpenAI = require('openai');
const dotenv = require('dotenv');

dotenv.config();

const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });

async function main() {
  const threadMessages = await openai.beta.threads.messages.create(
    "thre9kzUr",
    { role: "user", content: "How can I contact your technical support team?" }
  );

  console.log(threadMessages);
}

main();

```

This code gives the value of the same as what I am asking. How can I modify this code to get the desired output?

---

<div class="post-metadata">

**Author:** ![\_j](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/_j/32/766292_2.png) [@\_j](https://community.openai.com/u/_j)\
**Post date:** [February 15, 2024, 5:58am UTC](https://community.openai.com/t/how-can-i-access-the-assistants-data-through-api/627366/2 "2024-02-15T05:58:18Z")

</div>

After loading a user message into a thread, after configuring an assistant, you must invoke a run with the assistant and thread ID. You must then continue polling to wait for a reply to be ready.

**Documentation** and **API reference** are two links in the sidebar on the left or menu of this forum. Each have a section for assistants.

---

<div class="post-metadata">

**Author:** ![admin115](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@admin115](https://community.openai.com/u/admin115)\
**Post date:** [February 15, 2024, 6:44am UTC](https://community.openai.com/t/how-can-i-access-the-assistants-data-through-api/627366/3 "2024-02-15T06:44:37Z")

</div>

@_j After referring I come up with the below solution. By running this code I am getting the same response.

```auto
const OpenAI = require('openai');
const dotenv = require('dotenv');

dotenv.config();

const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });

const sumfun = async () => {

const thread = await openai.beta.threads.create({
  messages: [
    {
      "role": "user",
      "content": "How can I contact your technical support team?",
    }
  ]
});

const run = await openai.beta.threads.runs.create(
  thread.id,
  {
    assistant_id: "asst_65QoRVZBT",
  }
);

const run_response = await openai.beta.threads.runs.retrieve(
  thread.id,
  run.id
);
console.log("run respnse: => " + run_response);

const threadMessages = await openai.beta.threads.messages.list(
  thread.id
);

console.log(threadMessages.data[0].content[0]);

}

sumfun();

```

Response:

```auto
{
  type: 'text',
  text: {
    value: 'How can I contact your technical support team?',
    annotations: []
  }
}

```

Are there any modifications that need to be made?

---

<div class="post-metadata">

**Author:** ![\_j](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/_j/32/766292_2.png) [@\_j](https://community.openai.com/u/_j)\
**Post date:** [February 15, 2024, 6:50am UTC](https://community.openai.com/t/how-can-i-access-the-assistants-data-through-api/627366/4 "2024-02-15T06:50:26Z")

</div>

The AI doesn’t have an answer ready milliseconds after you set the run into motion.

#### [Polling for updates](https://platform.openai.com/docs/assistants/how-it-works/polling-for-updates)

In order to keep the status of your run up to date, you will have to periodically [retrieve the Run](https://platform.openai.com/docs/api-reference/runs/getRun) object. You can check the status of the run each time you retrieve the object to determine what your application should do next. We plan to add support for streaming to make this simpler in the near future.

 ![diagram-1](https://us1.discourse-cdn.com/openai1/original/4X/d/f/6/df668fce0ed03e29586196b6521eb220d0b246d2.png)

---

<div class="post-metadata">

**Author:** ![admin115](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@admin115](https://community.openai.com/u/admin115)\
**Post date:** [February 15, 2024, 7:01am UTC](https://community.openai.com/t/how-can-i-access-the-assistants-data-through-api/627366/5 "2024-02-15T07:01:33Z")

</div>

Yeah, I got it. I am getting the response that I want. Thank you.
