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
On Node.js, the SDK can send requests over HTTP/2, which multiplexes many concurrent requests over a small number of TLS connections instead of opening a connection per request. Enable it with the `http2` option:
360
+
On Node.js, the SDK sends requests over HTTP/2 **by default**, multiplexing many concurrent requests over a small number of TLS connections instead of opening a connection per request. The transport is built on Node's native `node:http2` and manages a bounded pool of persistent H2 sessions per origin, auto-scaling with load. On the web, Deno, and other runtimes the platform `fetch` already speaks HTTP/2, so this option is a no-op there.
361
+
362
+
To tune the pool — for example to raise the number of connections for a high-concurrency workload — pass options as `http2`:
361
363
362
364
<!-- prettier-ignore -->
363
365
```ts
364
366
const runloop =newRunloopSDK({
365
-
http2: true,
367
+
http2: { maxConnections: 20 },
366
368
});
367
369
```
368
370
369
-
Requests are routed through an [undici](https://github.com/nodejs/undici) connection pool with HTTP/2 enabled, falling back to HTTP/1.1 for origins that don't negotiate h2 via ALPN. It is intended for HTTP/2-capable origins such as the Runloop API. This transport uses undici and therefore **requires Node.js >= 20.18.1** (see Requirements).
370
-
371
-
`http2: true` uses a default bounded pool. To control the pool yourself — for example to raise the number of connections or multiplexed streams for a high-concurrency workload — pass a configured undici `Dispatcher` (such as an `Agent`) instead. The SDK uses it verbatim and does not manage its lifecycle, the same way it treats a custom `httpAgent`:
371
+
To opt out and use the HTTP/1.1 `node-fetch` transport, set `http2: false`:
The `httpAgent` option does not apply to the HTTP/2 transport (undici has no Node `http.Agent`concept); set `http2` to a `Dispatcher` to tune connections. A one-time warning is emitted if both `http2` and `httpAgent` are provided.
380
+
The `httpAgent` option only applies to the HTTP/1.1 transport. A Node `http.Agent`configures HTTP/1.1 socket pooling (keep-alive, max sockets), which has no equivalent under HTTP/2 — the H2 transport multiplexes over its own managed connections — so `httpAgent` has no effect there. To tune HTTP/2 connection behavior, use `http2: { … }` instead. To keep an existing `httpAgent` working, passing one without an explicit `http2` value keeps the client on HTTP/1.1 (with a one-time warning); pass `http2: false` to select HTTP/1.1 explicitly and silence the warning. If both `httpAgent` and `http2` are set, `httpAgent` is ignored (also warned once). A custom `fetch` always takes precedence over `http2`.
383
381
384
382
## Semantic versioning
385
383
@@ -400,7 +398,7 @@ TypeScript >= 4.5 is supported.
400
398
The following runtimes are supported:
401
399
402
400
- Web browsers (Up-to-date Chrome, Firefox, Safari, Edge, and more)
403
-
- Node.js 20.18.1 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions. (Raised from 18 because the SDK now depends on undici 7 on Node; the HTTP/2 transport needs the undici >= 7.23.0 crash fix, and the package pins `^7.26.0`.)
401
+
- Node.js 20.18.1 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions.
// Emitted at most once per process when `http2` and `httpAgent` are combined (see
345
-
// the constructor). Module-scoped flag mirrors the `fileFromPathWarned` pattern in
346
-
// _shims/node-runtime.ts.
347
-
lethttp2HttpAgentWarned=false;
348
-
349
351
exportclassRunloopextendsCore.APIClient{
350
352
bearerToken: string;
351
353
@@ -359,7 +361,7 @@ export class Runloop extends Core.APIClient {
359
361
* @param {number} [opts.timeout=30 seconds] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
360
362
* @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
361
363
* @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
362
-
* @param {boolean | H2FetchOptions} [opts.http2=false] - Send requests over HTTP/2 (Node only; ignored when `fetch` is provided). `true` uses the default bounded pool; pass H2FetchOptions to tune.
364
+
* @param {boolean | H2FetchOptions} [opts.http2=true] - Send requests over HTTP/2. Enabled by default on Node.js; pass `false` to use HTTP/1.1, or H2FetchOptions to tune the pool. Has no effect on browsers/Deno/Bun (their platform `fetch` already uses HTTP/2) or when a custom `fetch` is provided.
363
365
* @param {number} [opts.maxRetries=5] - The maximum number of times the client will retry a request.
364
366
* @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
365
367
* @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
@@ -381,28 +383,15 @@ export class Runloop extends Core.APIClient {
381
383
baseURL: baseURL||`https://api.runloop.ai`,
382
384
};
383
385
384
-
// `httpAgent` does not apply to the HTTP/2 transport — it manages its own
385
-
// persistent connections. Warn once instead of silently ignoring.
0 commit comments