You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: MIGRATION.md
+97-78Lines changed: 97 additions & 78 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,95 +4,40 @@ This guide outlines the changes and steps needed to migrate your codebase to the
4
4
5
5
The main changes are that the SDK now relies on the [builtin Web fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) instead of `node-fetch` and has zero dependencies.
6
6
7
+
## Migration CLI
8
+
9
+
Most programs will only need minimal changes, but to assist there is a migration tool that will automatically update your code for the new version.
10
+
To use it, upgrade the `openai` package, then run `./node_modules/.bin/openai migrate ./your/src/folders` to update your code.
11
+
To preview the changes without writing them to disk, run the tool with `--dry`.
12
+
7
13
## Environment requirements
8
14
9
15
The minimum supported runtime and tooling versions are now:
10
16
11
-
- Node.js 18.x last LTS (Required for built-in fetch support)
17
+
- Node.js 18.x last LTS (Required for builtin fetch support)
12
18
- This was previously documented as the minimum supported Node.js version but Node.js 16.x mostly worked at runtime; now it will not.
13
19
- TypeScript 4.9
14
20
- Jest 28
15
21
16
-
## Minimum types requirements
17
-
18
-
### DOM
19
-
20
-
`tsconfig.json`
21
-
22
-
```jsonc
23
-
{
24
-
"target":"ES2015", // note: we recommend ES2020 or higher
25
-
"lib": ["DOM", "DOM.Iterable", "ES2018"]
26
-
}
27
-
```
28
-
29
-
### Node.js
30
-
31
-
`tsconfig.json`
32
-
33
-
```jsonc
34
-
{
35
-
"target":"ES2015"// note: we recommend ES2020 or higher
36
-
}
37
-
```
38
-
39
-
`package.json`
40
-
41
-
```json
42
-
{
43
-
"devDependencies": {
44
-
"@types/node": ">= 18.18.7"
45
-
}
46
-
}
47
-
```
48
-
49
-
### Cloudflare Workers
50
-
51
-
`tsconfig.json`
52
-
53
-
```jsonc
54
-
{
55
-
"target":"ES2015", // note: we recommend ES2020 or higher
56
-
"lib": ["ES2020"], // <- needed by @cloudflare/workers-types
57
-
"types": ["@cloudflare/workers-types"]
58
-
}
59
-
```
60
-
61
-
`package.json`
62
-
63
-
```json
64
-
{
65
-
"devDependencies": {
66
-
"@cloudflare/workers-types": ">= 0.20221111.0"
67
-
}
68
-
}
69
-
```
70
-
71
-
### Bun
22
+
## Breaking changes
72
23
73
-
`tsconfig.json`
24
+
### Web types for `withResponse`, `asResponse`, and `APIError.headers`
74
25
75
-
```jsonc
76
-
{
77
-
"target":"ES2015"// note: we recommend ES2020 or higher
78
-
}
79
-
```
80
-
81
-
`package.json`
26
+
Because we now use the builtin Web fetch API on all platforms, if you wrote code that used `withResponse` or `asResponse` and then accessed `node-fetch`-specific properties on the result, you will need to switch to standardized alternatives.
27
+
For example, `body` is now a [Web `ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) rather than a [node `Readable`](https://nodejs.org/api/stream.html#readable-streams).
82
28
83
-
```json
84
-
{
85
-
"devDependencies": {
86
-
"@types/bun": ">= 1.2.0"
87
-
}
88
-
}
29
+
```ts
30
+
// Before:
31
+
const res =awaitclient.example.retrieve('string/with/slash').asResponse();
32
+
res.body.pipe(process.stdout);
33
+
34
+
// After:
35
+
import { Readable } from'node:stream';
36
+
const res =awaitclient.example.retrieve('string/with/slash').asResponse();
37
+
Readable.fromWeb(res.body).pipe(process.stdout);
89
38
```
90
39
91
-
### Deno
92
-
93
-
No config needed!
94
-
95
-
## Breaking changes
40
+
Additionally, the `headers` property on `APIError` objects is now an instance of the Web [Headers](https://developer.mozilla.org/en-US/docs/Web/API/Headers) class. It was previously defined as `Record<string, string | null | undefined>`.
96
41
97
42
### Named path parameters
98
43
@@ -409,6 +354,80 @@ import OpenAI from 'openai/src';
409
354
importOpenAIfrom'openai';
410
355
```
411
356
412
-
### Headers
357
+
## TypeScript troubleshooting
358
+
359
+
When referencing the library after updating, you may encounter new type errors related to JS features like private properties or fetch classes like Request, Response, and Headers.
360
+
To resolve these issues, configure your tsconfig.json and install the appropriate `@types` packages for your runtime environment using the guidelines below:
361
+
362
+
### Browsers
363
+
364
+
`tsconfig.json`
365
+
366
+
```jsonc
367
+
{
368
+
"target":"ES2018", // note: we recommend ES2020 or higher
369
+
"lib": ["DOM", "DOM.Iterable", "ES2018"]
370
+
}
371
+
```
372
+
373
+
### Node.js
413
374
414
-
The `headers` property on `APIError` objects is now an instance of the Web [Headers](https://developer.mozilla.org/en-US/docs/Web/API/Headers) class. It was previously just `Record<string, string | null | undefined>`.
375
+
`tsconfig.json`
376
+
377
+
```jsonc
378
+
{
379
+
"target":"ES2018"// note: we recommend ES2020 or higher
380
+
}
381
+
```
382
+
383
+
`package.json`
384
+
385
+
```json
386
+
{
387
+
"devDependencies": {
388
+
"@types/node": ">= 18.18.7"
389
+
}
390
+
}
391
+
```
392
+
393
+
### Cloudflare Workers
394
+
395
+
`tsconfig.json`
396
+
397
+
```jsonc
398
+
{
399
+
"target":"ES2018", // note: we recommend ES2020 or higher
400
+
"lib": ["ES2020"], // <- needed by @cloudflare/workers-types
401
+
"types": ["@cloudflare/workers-types"]
402
+
}
403
+
```
404
+
405
+
`package.json`
406
+
407
+
```json
408
+
{
409
+
"devDependencies": {
410
+
"@cloudflare/workers-types": ">= 0.20221111.0"
411
+
}
412
+
}
413
+
```
414
+
415
+
### Bun
416
+
417
+
`tsconfig.json`
418
+
419
+
```jsonc
420
+
{
421
+
"target":"ES2018"// note: we recommend ES2020 or higher
0 commit comments