Installation
Purpose and Scope
This page explains how to add the official OpenAI TypeScript and JavaScript SDK to an application and how to import it after installation. The package is published as openai for npm-based projects and is also available through JSR under the @openai/openai scope for Deno-oriented workflows. The repository README presents installation before usage because the SDK’s main developer path begins with a package install, a default import, and construction of an OpenAI client that calls generated REST API resources. Sources: README.md, package.json
The SDK is the official TypeScript library for the OpenAI API, and the package metadata identifies it with the npm package name openai. The README describes the library as convenient access to the OpenAI REST API from TypeScript or JavaScript and notes that it is generated from the OpenAPI specification with Stainless. That means installation is not only about fetching a helper library; it brings in a generated client surface whose import path, type declarations, and runtime module formats are defined by the package configuration. Sources: README.md, package.json
Relevant Source Files
README.md— Provides the public installation commands, JSR and Deno notes, primary import examples, and first usage snippets for the SDK.package.json— Defines the npm package name, version, type declarations, CommonJS and ESM entrypoints, export map, package manager, scripts, and optional peer dependencies.ecosystem-tests/bun/README.md— Gives the Bun-specific dependency installation and execution commands used by the repository’s ecosystem test for Bun.
Install from npm
For most Node.js, Bun, package-manager, and bundler workflows, install the SDK from npm with the package name shown in the README. The command is intentionally minimal because the package’s public entrypoint is the default package root. After installation, TypeScript and JavaScript code should import the default OpenAI client from openai. The README’s first usage example constructs a client with an API key from the environment and then calls the Responses API, which establishes openai as the primary package specifier for application code. Sources: README.md, package.json
npm install openaiimport OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env['OPENAI_API_KEY'],
});The npm package is configured to support both modern ESM import usage and CommonJS require usage through its export map. The package metadata names dist/index.mjs for import consumers and dist/index.js for require consumers, while dist/index.d.ts supplies the TypeScript declarations. The package itself is marked as CommonJS, but the export map is what application tooling should follow. In practice, users should prefer the documented top-level import rather than reaching into generated distribution files directly. Sources: package.json, README.md
Install from JSR and Deno
The README documents a separate JSR installation path. For Deno projects, deno add jsr:@openai/openai makes the package available through the JSR scope. For projects using the JSR command-line tooling from a Node-style environment, npx jsr add @openai/openai performs a comparable setup. These commands make the module importable from @openai/openai, which is different from the npm package specifier even though both refer to the same SDK family and public OpenAI client concept. Sources: README.md
deno add jsr:@openai/openai
npx jsr add @openai/openaiDeno can also import directly from JSR without a separate install step. The README shows this form with a JSR specifier and the same default OpenAI client import. Choose this direct import when a Deno program should resolve the package from the JSR registry at the import site, and choose the add command when you want the dependency recorded in the project’s dependency metadata. Either way, the application code still starts by constructing the client and calling generated resource methods. Sources: README.md
import OpenAI from 'jsr:@openai/openai';Runtime and Package-Manager Notes
The repository includes a Bun ecosystem test that mirrors the expected workflow for Bun users: install dependencies with Bun, then run the TypeScript entrypoint with Bun. That test documentation is intentionally small, but it confirms that Bun is treated as a first-class runtime scenario in the repository’s compatibility checks. For application developers, the practical implication is that Bun projects can install their dependencies using Bun’s package manager while continuing to use the SDK’s documented client import and generated API methods. Sources: ecosystem-tests/bun/README.md, package.json
bun install
bun run index.tsThe package metadata also shows the repository’s own development package manager as pnpm, but that is not the application installation command documented for consumers. Contributors working inside the SDK repository use repository scripts such as build, test, lint, and format, while downstream applications normally install the published package from npm or JSR. Keeping those two concerns separate helps avoid confusion: pnpm is part of repository maintenance, while npm install openai, Deno JSR commands, or Bun dependency installation are the paths relevant to SDK users. Sources: package.json, README.md, ecosystem-tests/bun/README.md
Entry Point Reference
The public package root is the main entrypoint developers should use. The README examples import the default OpenAI export from openai, and the package configuration backs that up with root exports for both ESM and CommonJS consumers. The metadata also exposes wildcard mappings for generated files, but normal application code should rely on the stable top-level client unless a documented example or reference page calls for a more specific import. This keeps code aligned with the generated API surface and avoids coupling an application to distribution layout details. Sources: README.md, package.json
| Scenario | Command or import | Notes |
|---|---|---|
| npm package install | npm install openai | Standard installation path for npm-based TypeScript and JavaScript projects. |
| npm/ESM import | import OpenAI from 'openai'; | Primary import form used by the README examples. |
| Deno dependency add | deno add jsr:@openai/openai | Records the JSR package for a Deno project. |
| JSR package add | npx jsr add @openai/openai | Adds the JSR-scoped package using the JSR CLI through npx. |
| Deno direct import | import OpenAI from 'jsr:@openai/openai'; | Uses a JSR specifier directly from Deno code. |
| Bun ecosystem flow | bun install, then bun run index.ts | Matches the repository’s Bun test README. |
After Installation
After the package is installed and imported, the next step is client configuration. The README usage path creates an OpenAI client and reads the API key from OPENAI_API_KEY, noting that this environment lookup is the default. From there, the first documented model interaction uses the Responses API through client.responses.create, while the README also preserves Chat Completions as the previous standard supported indefinitely. Installation therefore leads directly into authentication, model selection, request construction, and response handling rather than a separate manual transport layer. Sources: README.md
If you are choosing between install paths, use npm when your project already depends on Node package tooling, use JSR when working in Deno or when you want JSR-scoped dependency management, and use Bun’s package manager when your application runtime and scripts are Bun-based. Once installed, keep the import path consistent with the package source you selected, confirm that TypeScript can see the package declarations, and then move to the quickstart or client configuration material to make the first authenticated request. Sources: README.md, package.json, ecosystem-tests/bun/README.md