Simple ChatGPT client in the terminal

I stumbled upon a tutorial on how to make a simple ChatGPT client, but they seemed a bit outdated so I fiddled until I had the very simple thing I wanted.

Firstly important: this does not really compute the AI answer on your machine, it is just a client interface to the OpenAI cloud solution.

You will need a API-key from OpenAI.
There might be a billing model attached by now; look that up before you spam the AI.


npm install -g openai


const openai = require('openai');
const readline = require('node:readline/promises');
const process = require('node:process');

// Set your OpenAI API key
const apiKey = "<<< your api key goes here >>>";
const configuration = new openai.Configuration({
const AI = new openai.OpenAIApi(configuration);

function queryInput() {
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout,

    rl.question("Ask me: ").then(ans => {

function processQuery(query) {
    const model = "text-davinci-003";

      prompt: query,
      temperature: 0.5,
    }).then((response) => {

# node test.js
Ask me: when did avryl lavigne change her hair color to blonde?

Avril Lavigne dyed her hair blonde in 2001

The above is based on this tutorial I found and the OpenAI client example application:

and additionally on official documentation since I wanted to run it like a script.

You can run the author's openai client example to generate animal names like this:

git clone .
cp .env.example .env
# Add your API key to .env
npm install
npm run dev

Or the same thing as docker container:

git clone .
cp .env.example .env
# Add your API key to .env
docker build -t chatbot-docker .
docker run -d -p 3000:3000 chatbot-docker
-> http://localhost:3000/


Enter your comment: