Can't get response from api

import OpenAI from "openai";
import { readFile, writeFile } from "fs/promises";

const fileName = "./test.txt"; 

// Функция для перевода текста с использованием OpenAI API
async function translateText(text) {
  try {
    const openai = new OpenAI({
      apiKey: process.env.OPENAI_API_KEY,
    });

    console.log("Before API Call - User Input:", text);

    const response = await openai.chat.completions.create({
      model: "gpt-3.5-turbo",
      messages: [
        {
          role: "system",
          content: "You are a translation assistant. Translate the following English text to Russian while preserving any text within [], {}, or ().",
        },
        { role: "user", content: text },
      ],
    });

    console.log("After API Call - Response:", response);

    const choices = response.data.choices;

    if (choices && choices.length > 0) {
      const translatedText = choices[0].message.content;
      console.log(`Переведенный текст: ${translatedText}`);
      return translatedText;
    } else {
      console.error("Ошибка: Нет данных о выборе в ответе от OpenAI.");
      return null;
    }
  } catch (err) {
    console.error("Ошибка при обращении к OpenAI API:", err);
    return null;
  }
}

async function processFile() {
  try {
    const data = await readFile(fileName, "utf-8");


    let lines = data.split("\n");

    // Отправить группы строк для перевода
    for (let i = 0; i < lines.length; i += 200) {
      const group = lines.slice(i, i + 200).join("\n");
      await translateText(group); // Просто вызываем функцию перевода
    }

    console.log("Файл успешно переведен.");
  } catch (err) {
    console.error("Ошибка при обработке файла:", err);
  }
}


processFile();

By “can’t get response” do you mean you are getting some error?

i mean i get nothing. maybe i do something wrong? DONT UNDERSTAND MY FAIL

There cannot be “nothing”. Please post your full openai response here (contents of the response variable).

node openai.js
Before API Call - User Input: Hello my little pony
After API Call - Response: {
  id: 'chatcmpl-8SP7VB5JehIBdXgwYFOPCc00etgT9',
  object: 'chat.completion',
  created: 1701780437,
  model: 'gpt-3.5-turbo-0613',
  choices: [ { index: 0, message: [Object], finish_reason: 'stop' } ],
  usage: { prompt_tokens: 37, completion_tokens: 14, total_tokens: 51 },
  system_fingerprint: null
}
Ошибка при обращении к OpenAI API: TypeError: Cannot read properties of undefined (reading 'choices')

here seem to be something here