Registry / llm-agents / openai

openai

JSON →
library2.41.0jsnpmunverified

The official TypeScript and Node.js SDK for the OpenAI API, providing convenient access to frontier models like GPT-5.4, GPT-5.4-mini, and Sora 2. Currently at version 6.34.0, it features auto-retries, native streaming, structured data handling, and robust typing. It is the recommended standard to interact with OpenAI from server-side JavaScript runtimes (Node.js, Deno, Bun, Cloudflare Workers), abstracting away raw HTTP calls and providing seamless integration with advanced capabilities like Computer Use, Tool Search, and WebSocket-based Realtime streams.

npm install openai
INSTALL
IMPORT
SIG · OPENAI
O
openai
llm-agentsjavascriptv2.41.0
Install
Import
1927ms
Disk
45MB
Pass rate
10/ 16
Env Coverage10 / 16
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
node 18
✕ build_error
✕ build_error
node 20
✕ build_error
✕ build_error
node 22
✕ build_error
✕ build_error
node 3.10
✓ —
✓ —
node 3.11
✓ —
✓ —
node 3.12
✓ —
✓ —
node 3.13
✓ —
✓ —
node 3.9
✓ —
✓ —
45MB installed
● package 45MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

OpenAI
import OpenAI from 'openai'; const openai = new OpenAI();
import { Configuration, OpenAIApi } from 'openai'; const configuration = new Configuration({}); const openai = new OpenAIApi(configuration);
Version 4.0 and above completely rewrote the SDK, removing the separate Configuration and OpenAIApi classes in favor of a single unified default export.
Auth Providers
import { azureManagedIdentityTokenProvider } from 'openai/auth';
import { azureManagedIdentityTokenProvider } from 'openai';
Advanced authentication token providers (like Azure Managed Identity or GCP ID token providers) are exposed via the 'openai/auth' subpath to keep the main bundle streamlined.

A basic Chat Completions API request using the latest gpt-5.4-mini model, illustrating the standard async initialization and usage pattern.

import OpenAI from 'openai'; const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY }); async function main() { const response = await client.chat.completions.create({ model: 'gpt-5.4-mini', messages: [{ role: 'user', content: 'What is the speed of light?' }], }); console.log(response.choices[0].message.content); } main();
Debug
Known issues
breakingThe v4.0 release was a complete architectural rewrite. Code written for v3 using `Configuration` and `OpenAIApi` will instantly fail and requires a full migration to the new `OpenAI` client instance architecture.
fix
Rewrite initialization to use `new OpenAI()` and migrate method calls from `openai.createChatCompletion` to `openai.chat.completions.create`.
affects: >=4.0.0
gotchaAttempting to use the SDK in a browser environment will intentionally throw an error by default to prevent leaking API keys to the client side.
fix
Pass `dangerouslyAllowBrowser: true` to the constructor ONLY if you are absolutely sure about the security implications or are proxying requests securely through a backend.
affects: All
gotchaWith the introduction of new generation capabilities (like Codex and Computer Use), OpenAI implemented automated cybersecurity safeguards. Suspicious traffic patterns may result in sudden HTTP 403 or `cyber_policy` errors.
fix
Implement a unique `safety_identifier` per end-user. If access is revoked due to suspicious activity, passing this identifier ensures it only impacts the offending user rather than your entire organization.
affects: >=6.0.0
Errors
Common errors & fixes
Error 429: You exceeded your current quota, please check your plan and billing details
You are attempting to use the API without pre-paid credits. OpenAI APIs are no longer free and require a pre-funded balance, even on newly created accounts or accounts with a ChatGPT Plus subscription (which is billed separately).
fix
Navigate to platform.openai.com/account/billing, attach a valid payment method, and add an initial credit balance.
Error: It looks like you're running in a browser-like environment. This is disabled by default
The SDK detected a browser environment (like React, Vue, or Next.js client-components). OpenAI blocks this to prevent developers from accidentally exposing their secret `OPENAI_API_KEY` in client-side bundles.
fix
Move the API call to a backend server/serverless API route. If you must run it in the client, instantiate with `new OpenAI({ dangerouslyAllowBrowser: true })`.
Error 400: Purpose must be fine-tune/assistants
When uploading files via `openai.files.create`, a `purpose` argument is required to validate the file format. The endpoint strictly expects certain enumerations like 'fine-tune' or 'assistants'.
fix
Ensure you provide a valid purpose string. Example: `await openai.files.create({ file: fs.createReadStream('data.jsonl'), purpose: 'assistants' });`
Upgrade
Version history
2.41.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
46 hits · last 30 days
node
34
Bingbot
1
OpenAI (training)
1
Resources