Skip to content
Home / Migrations / OpenAI SDK v3 (Node)OpenAI SDK v4

OpenAI SDK v3 (Node) OpenAI SDK v4

medium

v4 is a complete rewrite — first-class TypeScript, async iterators for streaming, resource-based methods. Worth the upgrade.

Estimated: 2-5h · 5 steps
Progress0%
Step 1: Install v4
npm install openai@^4
Step 2: Replace client construction

new OpenAIApi(new Configuration({ apiKey })) → new OpenAI({ apiKey }).

import OpenAI from 'openai'
const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY })
Step 3: Update method paths

openai.createChatCompletion(...) → openai.chat.completions.create(...). Same shape for embeddings, images, audio.

Step 4: Migrate streaming

Old: stream + data event listeners. New: for await (const chunk of stream) { ... }.

const stream = await client.chat.completions.create({ model, messages, stream: true })
for await (const chunk of stream) console.log(chunk.choices[0]?.delta?.content)
Step 5: Adopt helpers

client.chat.completions.stream() and runTools() helpers simplify tool-use flows.

All AI features work. Types flow through correctly.

What this migration involves

Moving from OpenAI SDK v3 (Node) to OpenAI SDK v4 is rated medium and takes about 2-5h on a typical project. The guide breaks it into 5 steps, 3 of which ship with runnable commands and 1 with a verification check.

FAQ

How long does migrating from OpenAI SDK v3 (Node) to OpenAI SDK v4 take?

Around 2-5h for a typical project — 5 steps, difficulty rated medium, 3 of them with copy-paste commands.

Is moving from OpenAI SDK v3 (Node) to OpenAI SDK v4 reversible?

No reverse guide is tracked yet, so treat this as a one-way move and keep a full export of your OpenAI SDK v3 (Node) data before you start.

What does OpenAI SDK v4 cost compared to OpenAI SDK v3 (Node)?

Pricing for both tools is contact-based or not tracked yet.