One of my colleagues asked me to explain how to programmatically call the OpenAI API (ChatGPT). I figured I’d search the Internet for the simplest possible example and point him to it, but literally every example I found wasn’t very simple at all. So here’s my version of the simplest possible programmatic OpenAI API (ChatGPT) call, using the JavaScript language with node.js, running on a Windows machine.
Note: ChatGPT is an application (program) that uses the OpenAI (company) API (interface to a large language model) to access a GPT large language model. The terms are sometimes used interchangeably.
Note: an important alternative to using JavaScript is using the Python language — I’ll do another post sometime.
There are several ways to call the OpenAI API. The version presented here is a JavaScript program, running in the node.js environment, on a Windows machine. Calling the OpenAI API from a Web page is similar, but definitely more complicated because you have to deal with all the HTML.
Overview:
1. Install node.js if necessary
2. Create an OpenAI account and get an API key
3. Write a JavaScript program
4. Run the program using node.js
1. Install node.js (includes NPM). Go to https://nodejs.org/en/download. Click on the “Windows Installer (.msi)” button. This will download a file with a name like “node-v22.17.1-x64.msi” to your Downloads directory. Go to Downloads and double-clikck on the msi file.
A setup wizard will guide you with 9 windows. You can accept all the defaults. On the “Tools for Native Modules” screen, I unchecked the “Automatically install the necessary tools” option because I wasn’t going to use any complicated NPM modules that require compiling.
When finished, open a command shell and issue the command “node -v” followed by the command “npm -v” to display the versions you just installed (and verify that they were in fact installed).
2a. Create an OpenAI account. Note: Instead of creating a dedicated OpenAI account, I suggest using an existing Google gmail account — create one if necessary — quite a bit simpler than using a separate OpenAI account.
Go to: platform.openai.com. If you don’t have an account, click on the “Sign Up” button. Then, on the next screen, select the “Continue with Google” option. On subsequent visits to platform.openai.com, select the “Log in” option.
Note: The OpenAI web site changes every few weeks or so. Irritating.
2b. Set up billing. In the upper right, click on the Settings gear icon. On the next page, in the left border, click on the Billing option. From this page you can enter “Payment methods” using your credit card information.
2c. Get an API key for the demo. In the left border, click on the “API keys”. There will be a window where you give the key a name, like “MyTestKey”. Then select the “Default project” from the Project dropdown. Click “Create secret key”.
When the key is created, click on the “Copy” button to copy the key value (it’s really long) and then save it in a text file somewhere on your computer. This is your only chance to save the key.
3. Write a JavaScript program. Open a command shell. Create a dedicated directory for your demo, for example at C:\JavaScript\ChatGPT\HelloWorld. Navigate to the directory and issue the command “npm install openai”.
Open Notepad or any editor (you don’t need anything fancy) and copy-paste this program, and then save it as “chatgpt_hello.js”. Replace the key with your key. Note: you can use Visual Studio Code instead of Notepad.
// chatgpt_hello.js
// assumes: npm install openai
import OpenAI from "openai";
console.log("\nBegin ChatGPT demo ");
const client = new OpenAI({apiKey: '...use your key here...'});
const response = await client.responses.create({
model: "gpt-4.1-mini",
input: "Tell me hello in a clever way"
});
console.log(response.output_text);
console.log("\nEnd demo ");
In directory, issue command “node chatgpt_hello.js” and pray to the computer gods.
Sample output:
C:\JavaScript\ChatGPT\HelloWorld>node chatgpt_hello.js (node:27176) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///C:/JavaScript/ChatGPT/HelloWorld/chatgpt_hello.js is not specified and it doesn't parse as CommonJS. Reparsing as ES module because module syntax was detected. This incurs a performance overhead. To eliminate this warning, add "type": "module" to C:\JavaScript\ChatGPT\package.json. (Use `node --trace-warnings ...` to show where the warning was created) Begin ChatGPT demo Greetings, Earthling! You've just initiated a cosmic connection—hello from the other side of the screen! End demo
OK, so there you have it, the simplest possible example of calling the ChatGPT API.

I asked the Google Gemini tool to draw me three portraits, ranging from simplest possible to detailed. Gemini did quite nicely I think.



.NET Test Automation Recipes
Software Testing
SciPy Programming Succinctly
Keras Succinctly
R Programming
2026 Visual Studio Live
2025 Summer MLADS Conference
2025 DevIntersection Conference
2025 Machine Learning Week
2025 Ai4 Conference
2025 G2E Conference
2025 iSC West Conference
You must be logged in to post a comment.