How can I hire a ready-made assistant? I am programming in node.js

I already have the assistant created, but in my own interface, I have already made a code but it gives me a 404 error. I followed the steps that the documentation gives us but it creates a new one every time I run the code.

What I want to achieve is to occupy one that I have already made.


// import the required dependencies
const { OpenAI, ToolType } = require(“openai”);
const readline = require(“readline”).createInterface({
input: process.stdin,
output: process.stdout,

// Create a OpenAI connection
const secretKey = process.env.OPENAI_API_KEY;
const openai = new OpenAI({
apiKey: secretKey,

// ID del asistente existente
const existingAssistantId = ‘asst_FIRh4F0IEZnsTyhNPw4RjSAB’;

async function askQuestion(question) {
return new Promise((resolve, reject) => {
readline.question(question, (answer) => {

async function main() {
try {
// Log the first greeting
“\nHola, soy especialista en el area de pintura, igualacion leo tu pregunta.\n”

// Create a thread associated with the existing assistant
const thread = await openai.beta.threads.create({
  assistant_id: existingAssistantId

// Use keepAsking as state for keep asking questions
let keepAsking = true;
while (keepAsking) {
  const userQuestion = await askQuestion("\n¿Cuál es tu pregunta? ");

  // Pass in the user question into the existing thread
  await openai.beta.threads.messages.create(, {
    role: "user",
    content: userQuestion,

  // Use runs to wait for the assistant response and then retrieve it
  const run = await openai.beta.threads.runs.create(, {
    assistant_id: existingAssistantId,

  let runStatus = await openai.beta.threads.runs.retrieve(,

  // Polling mechanism to see if runStatus is completed
  while (runStatus.status !== "completed") {
    await new Promise((resolve) => setTimeout(resolve, 2000));
    runStatus = await openai.beta.threads.runs.retrieve(,;

  // Get the last assistant message from the messages array
  const messages = await openai.beta.threads.messages.list(;

  // Find the last message for the current run
  const lastMessageForRun =
      (message) => message.run_id === && message.role === "assistant"

  // If an assistant message is found, console.log() it
  if (lastMessageForRun) {
    console.log(`${lastMessageForRun.content[0].text.value} \n`);

  // Then ask if the user wants to ask another question and update keepAsking state
  const continueAsking = await askQuestion(
    "¿quieres hacer mas preguntas? (si/no) "
  keepAsking = continueAsking.toLowerCase() === "si";

  // If the keepAsking state is falsy show an ending message
  if (!keepAsking) {
    console.log("Espero haber respondido tus preguntas!\n");

// close the readline

} catch (error) {

// Call the main function