openai/openai-node
Official JavaScript / TypeScript library for the OpenAI API
OpenAI Node.js / TypeScript SDK
What it is
- An official client library that lets JavaScript or TypeScript code call the OpenAI REST API.
- Generated from OpenAI’s OpenAPI spec, so the SDK mirrors the live API surface.
Core capabilities
- Text generation via the new Responses API and the classic Chat Completions API.
- Vision – send images together with text prompts and receive descriptive output.
- Streaming – receive partial results as Server‑Sent Events, useful for real‑time UI.
- File handling – helpers (
toFile,toStreamingFile) make uploading fine‑tune data easy. - Workload‑identity authentication – use short‑lived tokens from Kubernetes, Azure, GCP, or X.509 client certificates instead of static API keys.
- Realtime API – low‑latency, multimodal (text + audio) conversations over WebSocket, with function calling support.
- Azure OpenAI & Amazon Bedrock adapters – drop‑in support for the respective cloud‑provider endpoints.
- Automatic pagination, retries, timeouts, and cancellation – sane defaults that can be overridden.
- Webhook verification – built‑in methods to validate and parse OpenAI‑sent webhooks.
Typical use cases
- Building chat assistants, code generators, or any LLM‑driven feature in a web or server app.
- Processing images with LLMs (e.g., OCR, captioning) via the Vision endpoint.
- Running fine‑tuning jobs and managing uploaded training files.
- Deploying low‑latency voice assistants using the Realtime API.
- Integrating OpenAI models into Kubernetes‑based services using workload‑identity for secret‑less auth.
Installation
npm install openai # or use Deno: import OpenAI from 'npm:openai'
Quick start (text generation with the Responses API)
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env.OPENAI_API_KEY, // optional – falls back to env var
});
const response = await client.responses.create({
model: 'gpt-5.5',
instructions: 'You are a coding assistant that talks like a pirate',
input: 'Are semicolons optional in JavaScript?',
});
console.log(response.output_text);
Where to learn more
- Full method list:
api.mdin the repo. - Example code:
examples/directory (e.g., multi‑turn conversations, streaming, workload‑identity). - Official API reference: https://platform.openai.com/docs/api-reference.
- Docs for advanced topics:
docs/realtime.md,docs/azure.md, and the X.509 workload‑identity guide.
Who maintains it
- Developed and maintained by OpenAI, with regular releases on npm.
All details are taken directly from the repository’s README; no external assumptions are added.
Related
- Project
- Project
- Project
- Project
- Project