Handle Web-standard Response and Error types
mainThe SDK now uses the builtin Web fetch API. This changes how withResponse, asResponse, and APIError.headers behave:
- Response Bodies: The
bodyproperty is now a WebReadableStreaminstead of a Node.jsReadable. To use Node.js stream methods (like.pipe()), you must convert it usingReadable.fromWeb()from thenode:streammodule. - Error Headers: The
headersproperty onAPIErrorobjects is now an instance of the WebHeadersclass, rather than a plainRecord<string, string | null | undefined>object.
// Converting a Web ReadableStream body to a Node.js stream
import { Readable } from 'node:stream';
const res = await client.example.retrieve('string/with/slash').asResponse();
Readable.fromWeb(res.body).pipe(process.stdout);