Install the OpenAI SDK and Run an API Call
JavaScript
Python
.NET
Java
Go
Ruby
JavaScript
To use the OpenAI API in server-side JavaScript environments like Node.js, Deno, or Bun, you can use the official
OpenAI SDK for TypeScript and JavaScript
. Get started by installing the SDK using
npm
or your preferred package manager:
Install the OpenAI SDK with npm
1
npm
install
openai
With the OpenAI SDK installed, create a file called
example.mjs
and copy the example code into it:
Test a basic API request
1
2
3
4
5
6
7
8
9
import
OpenAI
from
"openai"
;
const
client
=
new
OpenAI
();
const
response
=
await
client.responses.
create
({
model:
"gpt-6-astra"
,
input:
"Write a one-sentence bedtime story about a unicorn."
,
});
console.
