openai/openai-node

Official JavaScript / TypeScript library for the OpenAI API

openai/openai-node – Official OpenAI JavaScript/TypeScript SDK

What it is – A first‑party client library that lets you call OpenAI’s REST API from Node.js, Deno, or the browser using idiomatic TypeScript/JavaScript. It is generated from OpenAI’s OpenAPI spec and covers all current endpoints (chat, completions, embeddings, files, fine‑tuning, realtime, etc.).

Key capabilities

  • Simple new OpenAI({ apiKey }) construction (or workload‑identity auth for cloud‑native environments).
  • High‑level helpers for the Responses API (the newest text‑generation endpoint) and the classic Chat Completions API.
  • Built‑in support for vision (image input), streaming (SSE), file uploads, webhook verification, and realtime audio‑text conversations via WebSocket.
  • Automatic pagination, retry logic, configurable timeouts, and request cancellation via AbortSignal.
  • First‑class integrations for Azure OpenAI, Amazon Bedrock, and X.509 workload‑identity authentication.

Typical usage

import OpenAI from 'openai';

const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });

// Text generation (Responses API)
const resp = await client.responses.create({
  model: 'gpt-5.5',
  instructions: 'You are a pirate‑talking coding assistant',
  input: 'Are semicolons optional in JavaScript?'
});
console.log(resp.output_text);

// Chat completions (legacy API)
const chat = await client.chat.completions.create({
  model: 'gpt-5.5',
  messages: [{ role: 'user', content: 'Explain closures.' }]
});
console.log(chat.choices[0].message.content);

Installation

npm install openai   # Node / npm
# Deno users can import directly:
import OpenAI from 'npm:openai';

Where to learn more – The repository ships an api.md reference, a rich examples/ folder, and links to the official OpenAI API docs.

Why it matters – By handling auth, pagination, retries, streaming, and type safety for you, this SDK lets developers focus on building AI‑powered products rather than plumbing HTTP calls.

Related

  • Project
  • Project
  • Project
  • Project
  • Project