Skip to content

Commit 732d870

Browse files
stainless-app[bot]RobertCraigie
authored andcommitted
chore(docs): improve migration doc
1 parent 179a607 commit 732d870

File tree

1 file changed

+141
-143
lines changed

1 file changed

+141
-143
lines changed

MIGRATION.md

Lines changed: 141 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ For example, for a method that would call an endpoint at `/v1/parents/{parent_id
102102

103103
```ts
104104
// Before
105-
client.parents.children.create('p_123', 'c_456');
105+
client.parents.children.retrieve('p_123', 'c_456');
106106

107107
// After
108-
client.example.create('c_456', { parent_id: 'p_123' });
108+
client.parents.children.retrieve('c_456', { parent_id: 'p_123' });
109109
```
110110

111111
This affects the following methods:
@@ -136,73 +136,11 @@ For example:
136136

137137
```diff
138138
- client.example.retrieve(encodeURIComponent('string/with/slash'))
139-
+ client.example.retrieve('string/with/slash') // renders example/string%2Fwith%2Fslash
139+
+ client.example.retrieve('string/with/slash') // retrieves /example/string%2Fwith%2Fslash
140140
```
141141

142142
Previously without the `encodeURIComponent()` call we would have used the path `/example/string/with/slash`; now we'll use `/example/string%2Fwith%2Fslash`.
143143

144-
### Removed `httpAgent` in favor of `fetchOptions`
145-
146-
The `httpAgent` client option has been removed in favor of a [platform-specific `fetchOptions` property](https://github.com/stainless-sdks/openai-typescript#fetch-options).
147-
This change was made as `httpAgent` relied on `node:http` agents which are not supported by any runtime's builtin fetch implementation.
148-
149-
If you were using `httpAgent` for proxy support, check out the [new proxy documentation](https://github.com/stainless-sdks/openai-typescript#configuring-proxies).
150-
151-
Before:
152-
153-
```ts
154-
import OpenAI from 'openai';
155-
import http from 'http';
156-
import { HttpsProxyAgent } from 'https-proxy-agent';
157-
158-
// Configure the default for all requests:
159-
const client = new OpenAI({
160-
httpAgent: new HttpsProxyAgent(process.env.PROXY_URL),
161-
});
162-
```
163-
164-
After:
165-
166-
```ts
167-
import OpenAI from 'openai';
168-
import * as undici from 'undici';
169-
170-
const proxyAgent = new undici.ProxyAgent(process.env.PROXY_URL);
171-
const client = new OpenAI({
172-
fetchOptions: {
173-
dispatcher: proxyAgent,
174-
},
175-
});
176-
```
177-
178-
### HTTP method naming
179-
180-
Some methods could not be named intuitively due to an internal naming conflict. This has been resolved and the methods are now correctly named.
181-
182-
```ts
183-
// Before
184-
client.chat.completions.del();
185-
client.files.del();
186-
client.models.del();
187-
client.vectorStores.del();
188-
client.vectorStores.files.del();
189-
client.beta.assistants.del();
190-
client.beta.threads.del();
191-
client.beta.threads.messages.del();
192-
client.responses.del();
193-
194-
// After
195-
client.chat.completions.delete();
196-
client.files.delete();
197-
client.models.delete();
198-
client.vectorStores.delete();
199-
client.vectorStores.files.delete();
200-
client.beta.assistants.delete();
201-
client.beta.threads.delete();
202-
client.beta.threads.messages.delete();
203-
client.responses.delete();
204-
```
205-
206144
### Removed request options overloads
207145

208146
When making requests with no required body, query or header parameters, you must now explicitly pass `null`, `undefined` or an empty object `{}` to the params argument in order to customise request options.
@@ -234,106 +172,69 @@ This affects the following methods:
234172
- `client.responses.retrieve()`
235173
- `client.responses.inputItems.list()`
236174

237-
### Pagination changes
238-
239-
Note that the `for await` syntax is _not_ affected. This still works as-is:
240-
241-
```ts
242-
// Automatically fetches more pages as needed.
243-
for await (const fineTuningJob of client.fineTuning.jobs.list()) {
244-
console.log(fineTuningJob);
245-
}
246-
```
247-
248-
#### Simplified interface
175+
### HTTP method naming
249176

250-
The pagination interface has been simplified:
177+
Previously some methods could not be named intuitively due to an internal naming conflict. This has been fixed and the affected methods are now correctly named.
251178

252179
```ts
253180
// Before
254-
page.nextPageParams();
255-
page.nextPageInfo();
256-
// Required manually handling { url } | { params } type
181+
client.chat.completions.del();
182+
client.files.del();
183+
client.models.del();
184+
client.vectorStores.del();
185+
client.vectorStores.files.del();
186+
client.beta.assistants.del();
187+
client.beta.threads.del();
188+
client.beta.threads.messages.del();
189+
client.responses.del();
257190

258191
// After
259-
page.nextPageRequestOptions();
192+
client.chat.completions.delete();
193+
client.files.delete();
194+
client.models.delete();
195+
client.vectorStores.delete();
196+
client.vectorStores.files.delete();
197+
client.beta.assistants.delete();
198+
client.beta.threads.delete();
199+
client.beta.threads.messages.delete();
200+
client.responses.delete();
260201
```
261202

262-
#### Removed unnecessary classes
263-
264-
Page classes for individual methods are now type aliases:
265-
266-
```ts
267-
// Before
268-
export class FineTuningJobsPage extends CursorPage<FineTuningJob> {}
269-
270-
// After
271-
export type FineTuningJobsPage = CursorPage<FineTuningJob>;
272-
```
203+
### Removed `httpAgent` in favor of `fetchOptions`
273204

274-
If you were importing these classes at runtime, you'll need to switch to importing the base class or only import them at the type-level.
205+
The `httpAgent` client option has been removed in favor of a [platform-specific `fetchOptions` property](https://github.com/stainless-sdks/openai-typescript#fetch-options).
206+
This change was made as `httpAgent` relied on `node:http` agents which are not supported by any runtime's builtin fetch implementation.
275207

276-
### File handling
208+
If you were using `httpAgent` for proxy support, check out the [new proxy documentation](https://github.com/stainless-sdks/openai-typescript#configuring-proxies).
277209

278-
The deprecated `fileFromPath` helper has been removed in favor of native Node.js streams:
210+
Before:
279211

280212
```ts
281-
// Before
282-
OpenAI.fileFromPath('path/to/file');
213+
import OpenAI from 'openai';
214+
import http from 'http';
215+
import { HttpsProxyAgent } from 'https-proxy-agent';
283216

284-
// After
285-
import fs from 'fs';
286-
fs.createReadStream('path/to/file');
217+
// Configure the default for all requests:
218+
const client = new OpenAI({
219+
httpAgent: new HttpsProxyAgent(process.env.PROXY_URL),
220+
});
287221
```
288222

289-
Note that this function previously only worked on Node.js. If you're using Bun, you can use [`Bun.file`](https://bun.sh/docs/api/file-io) instead.
290-
291-
### Shims removal
292-
293-
Previously you could configure the types that the SDK used like this:
223+
After:
294224

295225
```ts
296-
// Tell TypeScript and the package to use the global Web fetch instead of node-fetch.
297-
import 'openai/shims/web';
298226
import OpenAI from 'openai';
299-
```
300-
301-
The `openai/shims` imports have been removed. Your global types must now be [correctly configured](#minimum-types-requirements).
302-
303-
### `openai/src` directory removed
304-
305-
Previously IDEs may have auto-completed imports from the `openai/src` directory, however this
306-
directory was only included for an improved go-to-definition experience and should not have been used at runtime.
307-
308-
If you have any `openai/src` imports, you must replace it with `openai`.
309-
310-
```ts
311-
// Before
312-
import OpenAI from 'openai/src';
227+
import * as undici from 'undici';
313228

314-
// After
315-
import OpenAI from 'openai';
229+
const proxyAgent = new undici.ProxyAgent(process.env.PROXY_URL);
230+
const client = new OpenAI({
231+
fetchOptions: {
232+
dispatcher: proxyAgent,
233+
},
234+
});
316235
```
317236

318-
### Headers
319-
320-
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>`.
321-
322-
### Removed exports
323-
324-
#### Resource classes
325-
326-
If you were importing resource classes from the root package then you must now import them from the file they are defined in.
327-
This was never valid at the type level and only worked in CommonJS files.
328-
329-
```typescript
330-
// Before
331-
const { Completions } = require('openai');
332-
333-
// After
334-
const { OpenAI } = require('openai');
335-
OpenAI.Completions; // or import directly from openai/resources/completions
336-
```
237+
### Changed exports
337238

338239
#### Refactor of `openai/core`, `error`, `pagination`, `resource`, `streaming` and `uploads`
339240

@@ -359,6 +260,20 @@ import 'openai/core/uploads';
359260

360261
If you were relying on anything that was only exported from `openai/core` and is also not accessible anywhere else, please open an issue and we'll consider adding it to the public API.
361262

263+
#### Resource classes
264+
265+
Previously under certain circumstances it was possible to import resource classes like `Completions` directly from the root of the package. This was never valid at the type level and only worked in CommonJS files.
266+
Now you must always either reference them as static class properties or import them directly from the files in which they are defined.
267+
268+
```typescript
269+
// Before
270+
const { Completions } = require('openai');
271+
272+
// After
273+
const { OpenAI } = require('openai');
274+
OpenAI.Completions; // or import directly from openai/resources/completions
275+
```
276+
362277
#### Cleaned up `uploads` exports
363278

364279
As part of the `core` refactor, `openai/uploads` was moved to `openai/core/uploads`
@@ -395,3 +310,86 @@ import { APIClient } from 'openai/core';
395310
// After
396311
import { OpenAI } from 'openai';
397312
```
313+
314+
### File handling
315+
316+
The deprecated `fileFromPath` helper has been removed in favor of native Node.js streams:
317+
318+
```ts
319+
// Before
320+
OpenAI.fileFromPath('path/to/file');
321+
322+
// After
323+
import fs from 'fs';
324+
fs.createReadStream('path/to/file');
325+
```
326+
327+
Note that this function previously only worked on Node.js. If you're using Bun, you can use [`Bun.file`](https://bun.sh/docs/api/file-io) instead.
328+
329+
### Shims removal
330+
331+
Previously you could configure the types that the SDK used like this:
332+
333+
```ts
334+
// Tell TypeScript and the package to use the global Web fetch instead of node-fetch.
335+
import 'openai/shims/web';
336+
import OpenAI from 'openai';
337+
```
338+
339+
The `openai/shims` imports have been removed. Your global types must now be [correctly configured](#minimum-types-requirements).
340+
341+
### Pagination changes
342+
343+
The `for await` syntax **is not affected**. This still works as-is:
344+
345+
```ts
346+
// Automatically fetches more pages as needed.
347+
for await (const fineTuningJob of client.fineTuning.jobs.list()) {
348+
console.log(fineTuningJob);
349+
}
350+
```
351+
352+
The interface for manually paginating through list results has been simplified:
353+
354+
```ts
355+
// Before
356+
page.nextPageParams();
357+
page.nextPageInfo();
358+
// Required manually handling { url } | { params } type
359+
360+
// After
361+
page.nextPageRequestOptions();
362+
```
363+
364+
#### Removed unnecessary classes
365+
366+
Page classes for individual methods are now type aliases:
367+
368+
```ts
369+
// Before
370+
export class FineTuningJobsPage extends CursorPage<FineTuningJob> {}
371+
372+
// After
373+
export type FineTuningJobsPage = CursorPage<FineTuningJob>;
374+
```
375+
376+
If you were importing these classes at runtime, you'll need to switch to importing the base class or only import them at the type-level.
377+
378+
### `openai/src` directory removed
379+
380+
Previously IDEs may have auto-completed imports from the `openai/src` directory, however this
381+
directory was only included for an improved go-to-definition experience and should not have been used at runtime.
382+
383+
If you have any `openai/src/*` imports, you will need to replace them with `openai/*`.
384+
385+
```ts
386+
// Before
387+
import OpenAI from 'openai/src';
388+
389+
// After
390+
import OpenAI from 'openai';
391+
```
392+
393+
### Headers
394+
395+
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>`.

0 commit comments

Comments
 (0)