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
This library is typed for convenient access to the documented API. If you need to access undocumented
443
+
endpoints, params, or response properties, the library can still be used.
444
+
445
+
#### Undocumented endpoints
446
+
447
+
To make requests to undocumented endpoints, you can use `client.get`, `client.post`, and other HTTP verbs.
448
+
Options on the client, such as retries, will be respected when making these requests.
449
+
450
+
```ts
451
+
awaitclient.post('/some/path', {
452
+
body: { some_prop: 'foo' },
453
+
query: { some_query_arg: 'bar' },
454
+
});
455
+
```
456
+
457
+
#### Undocumented params
458
+
459
+
To make requests using undocumented parameters, you may use `// @ts-expect-error` on the undocumented
460
+
parameter. This library doesn't validate at runtime that the request matches the type, so any extra values you
461
+
send will be sent as-is.
462
+
463
+
```ts
464
+
client.foo.create({
465
+
foo: 'my_param',
466
+
bar: 12,
467
+
// @ts-expect-error baz is not yet public
468
+
baz: 'undocumented option',
469
+
});
470
+
```
471
+
472
+
For requests with the `GET` verb, any extra params will be in the query, all other requests will send the
473
+
extra param in the body.
474
+
475
+
If you want to explicitly send an extra argument, you can do so with the `query`, `body`, and `headers` request
476
+
options.
477
+
478
+
#### Undocumented properties
479
+
480
+
To access undocumented response properties, you may access the response object with `// @ts-expect-error` on
481
+
the response object, or cast the response object to the requisite type. Like the request params, we do not
482
+
validate or strip extra properties from the response from the API.
483
+
484
+
### Customizing the fetch client
441
485
442
486
By default, this library uses `node-fetch` in Node, and expects a global `fetch` function in other environments.
443
487
@@ -455,6 +499,8 @@ import OpenAI from 'openai';
455
499
To do the inverse, add `import "openai/shims/node"` (which does import polyfills).
456
500
This can also be useful if you are getting the wrong TypeScript types for `Response` ([more details](https://github.com/openai/openai-node/tree/master/src/_shims#readme)).
457
501
502
+
### Logging and middleware
503
+
458
504
You may also provide a custom `fetch` function when instantiating the client,
459
505
which can be used to inspect or alter the `Request` or `Response` before/after each request:
460
506
@@ -475,7 +521,7 @@ const client = new OpenAI({
475
521
Note that if given a `DEBUG=true` environment variable, this library will log all requests and responses automatically.
476
522
This is intended for debugging purposes only and may change in the future without notice.
477
523
478
-
## Configuring an HTTP(S) Agent (e.g., for proxies)
524
+
###Configuring an HTTP(S) Agent (e.g., for proxies)
479
525
480
526
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