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
By default, this library uses `node-fetch` in Node, and expects a global `fetch` function in other environments.
401
+
402
+
If you would prefer to use a global, web-standards-compliant `fetch` function even in a Node environment,
403
+
(for example, if you are running Node with `--experimental-fetch` or using NextJS which polyfills with `undici`),
404
+
add the following import before your first import `from "OpenAI"`:
405
+
406
+
<!-- prettier-ignore -->
407
+
```ts
408
+
// Tell TypeScript and the package to use the global web fetch instead of node-fetch.
409
+
// Note, despite the name, this does not add any polyfills, but expects them to be provided if needed.
410
+
import"openai/shims/web";
411
+
importOpenAIfrom"openai";
412
+
```
413
+
414
+
To do the inverse, add `import "openai/shims/node"` (which does import polyfills).
415
+
This can also be useful if you are getting the wrong TypeScript types for `Response` - more details [here](https://github.com/openai/openai-node/src/_shims#readme).
416
+
417
+
You may also provide a custom `fetch` function when instantiating the client,
418
+
which can be used to inspect or alter the `Request` or `Response` before/after each request:
Note that if given a `DEBUG=true` environment variable, this library will log all requests and responses automatically.
435
+
This is intended for debugging purposes only and may change in the future without notice.
436
+
398
437
## Configuring an HTTP(S) Agent (e.g., for proxies)
399
438
400
439
By default, this library uses a stable agent for all http/https requests to reuse TCP connections, eliminating many TCP & TLS handshakes and shaving around 100ms off most requests.
0 commit comments