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 openaiVerified import paths — ran on the pinned version, not inferred.
A basic Chat Completions API request using the latest gpt-5.4-mini model, illustrating the standard async initialization and usage pattern.
Rewrite initialization to use `new OpenAI()` and migrate method calls from `openai.createChatCompletion` to `openai.chat.completions.create`.
Pass `dangerouslyAllowBrowser: true` to the constructor ONLY if you are absolutely sure about the security implications or are proxying requests securely through a backend.
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.
Navigate to platform.openai.com/account/billing, attach a valid payment method, and add an initial credit balance.
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 })`.Ensure you provide a valid purpose string. Example: `await openai.files.create({ file: fs.createReadStream('data.jsonl'), purpose: 'assistants' });`No dependency data recorded yet.