API для JavaScript / TypeScriptAPI for JavaScript / TypeScript

Для ботов, серверов и скриптов на Node.js. Ключ — из переменной окружения: так он не попадёт в код и в Git. Вставь ключ в поле ниже — сниппет соберётся под тебя.For bots, servers and scripts on Node.js. The key comes from an environment variable, so it never lands in code or Git. Paste your key below and the snippet will be built for you.

Base URL
API KeyAPI Key

Ключ не отправляется с этой страницы: команды собираются локально в браузере. Без галочки выше ключ исчезнет после закрытия страницы. Ключ — как пароль: не показывай его на скриншотах, не отправляй в чаты и не добавляй в Git. Нет ключа — зарегистрируйся: личный ключ выпустится сам. Кнопки скачивания готовых файлов (settings.json, codex-setup.bat) — на странице «Подключение» — генератор конфигураций.Your key never leaves this page: commands are assembled locally in your browser. Without the checkbox above, the key disappears when you close the page. Treat the key like a password: never show it in screenshots, chats, or Git. No key yet? Register — a personal key is issued automatically. Download buttons for ready-made files are on the full connection page.

Как подключить

Какая у тебя система?Your operating system?

API для JavaScript / TypeScriptAPI for JavaScript / TypeScript

Ключ из поля выше автоматически подставляется в команды и конфиги.Your key from the field above is inserted into the commands and configs automatically.

1

Установи Node.js и библиотеку

Уже стоит — переходи к шагу 2.

  1. Поставь Node.js версии 18 или новее.
  2. В папке проекта выполни: npm install openai
2

Ключ — в переменную окружения

Выбери систему и вставь команду целиком.

Windows. PowerShell, вставь команду целиком:

macOS / Linux. Terminal, вставь блок целиком:

После команды полностью перезапусти терминал и редактор — переменная действует только в новых окнах.

3

Запусти первый запрос

Создай файл test.js, вставь сниппет и сохрани.

Запусти в терминале: node test.js. Пришёл ответ с текстом — всё работает.

Никогда не вставляй ключ в код, который выполняется в браузере — его увидят все посетители. Ключ живёт только на сервере или в терминале.

1

Install Node.js and the library

Already installed? Skip to step 2.

  1. Install Node.js version 18 or newer.
  2. In your project folder, run: npm install openai
2

Put the key into an environment variable

Pick your system and paste the whole command.

Windows. PowerShell — paste the whole command:

macOS / Linux. Terminal — paste the whole block:

After the command, fully restart the terminal and the editor — the variable only works in new windows.

3

Run the first request

Create a test.js file, paste the snippet and save.

Run in the terminal: node test.js. An answer with text came back — everything works.

Never put the key into code that runs in the browser — every visitor would see it. The key only lives on the server or in the terminal.

Частые ошибки

process is not defined
Код запускается в браузере, а не в Node.js. Сниппет рассчитан на Node.js: запусти его файлом через node test.js. И главное — ключ нельзя показывать в браузере.
Cannot find module 'openai'
Библиотека не установлена в этой папке. Выполни npm install openai в той же папке, где лежит файл со сниппетом.
SyntaxError: Cannot use import statement outside a module
Твой проект CommonJS — используй первую строку как в сниппете (require). Если в package.json есть "type": "module" — наоборот, замени на import (вариант есть в комментарии сниппета).
401 — ключ не принят
Переменная окружения пустая: перезапусти терминал после её задания и проверь echo $env:AIDOSTUP_API_KEY (PowerShell) / echo $AIDOSTUP_API_KEY (macOS/Linux).
process is not defined
The code runs in the browser, not in Node.js. The snippet is for Node.js: run it as a file via node test.js. And most importantly — the key must never be shown in the browser.
Cannot find module 'openai'
The library isn't installed in this folder. Run npm install openai in the same folder where the file with the snippet lives.
SyntaxError: Cannot use import statement outside a module
Your project is CommonJS — use the first line as in the snippet (require). If package.json has "type": "module" — the other way around, replace it with import (the option is in the snippet's comment).
401 — the key is not accepted
The environment variable is empty: restart the terminal after setting it and check echo $env:AIDOSTUP_API_KEY (PowerShell) / echo $AIDOSTUP_API_KEY (macOS/Linux).

Ограничения и совместимость

Требуется Node.js 18 или новее.

Если используешь .env-файлы — добавь .env в .gitignore: ключ не должен попадать в репозиторий.

В браузерном коде ключ запрещён (увидят посетители) — только серверная часть.

Requires Node.js 18 or newer.

If you use .env files — add .env to .gitignore: the key must not land in the repository.

The key is forbidden in browser code (visitors would see it) — server-side only.

Вопросы и ответы

Будет ли работать в TypeScript?
Да: пакет openai содержит типы из коробки. Импорт — import OpenAI from "openai".
Как включить стриминг?
Добавь stream: true в параметры create() и читай части асинхронно. Примеры — в документации.
Можно ли вызывать API прямо из браузера?
Только с сервера-посредника: в браузерном коде ключ увидят все. Сервер хранит ключ и проксирует запросы.
Какая модель для старта?
gpt-5.6-terra — универсальная; для экономных задач — gpt-5.6-luna.
Will it work in TypeScript?
Yes: the openai package ships with types out of the box. Import — import OpenAI from "openai".
How do I enable streaming?
Add stream: true to the create() parameters and read the parts asynchronously. Examples — in the documentation.
Can I call the API right from the browser?
Only through a server in the middle: in browser code everyone would see the key. A server keeps the key and proxies the requests.
Which model to start with?
gpt-5.6-terra — the all-rounder; for budget tasks — gpt-5.6-luna.