OpenAI SDK v3 (Node) → OpenAI SDK v4
mediumv4 is a complete rewrite — first-class TypeScript, async iterators for streaming, resource-based methods. Worth the upgrade.
npm install openai@^4
new OpenAIApi(new Configuration({ apiKey })) → new OpenAI({ apiKey }).
import OpenAI from 'openai'
const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY })openai.createChatCompletion(...) → openai.chat.completions.create(...). Same shape for embeddings, images, audio.
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)client.chat.completions.stream() and runTools() helpers simplify tool-use flows.
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.