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
feat: opt-in HTTP/2 multiplexing transport via undici 7 (Node >= 20.18.1) (#791)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Tony Deng <tony@runloop.ai>
Co-authored-by: sid-rl <siddarth@runloop.ai>
Co-authored-by: Reflex <agent@reflex.dev>
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:
361
+
362
+
<!-- prettier-ignore -->
363
+
```ts
364
+
const runloop =newRunloopSDK({
365
+
http2: true,
366
+
});
367
+
```
368
+
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`:
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.
383
+
358
384
## Semantic versioning
359
385
360
386
This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:
@@ -374,7 +400,7 @@ TypeScript >= 4.5 is supported.
374
400
The following runtimes are supported:
375
401
376
402
- Web browsers (Up-to-date Chrome, Firefox, Safari, Edge, and more)
377
-
- Node.js 18 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions.
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`.)
// Emitted at most once per process when `http2` and `httpAgent` are combined (see
363
+
// the constructor). Module-scoped flag mirrors the `fileFromPathWarned` pattern in
364
+
// _shims/node-runtime.ts.
365
+
lethttp2HttpAgentWarned=false;
366
+
330
367
exportclassRunloopextendsCore.APIClient{
331
368
bearerToken: string;
332
369
@@ -340,6 +377,7 @@ export class Runloop extends Core.APIClient {
340
377
* @param {number} [opts.timeout=30 seconds] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
341
378
* @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
342
379
* @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
380
+
* @param {boolean | import('undici').Dispatcher} [opts.http2=false] - Send requests over HTTP/2 (Node only; ignored when `fetch` is provided). `true` uses the default bounded pool; pass an undici `Dispatcher` to control the pool yourself.
343
381
* @param {number} [opts.maxRetries=5] - The maximum number of times the client will retry a request.
344
382
* @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
345
383
* @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
@@ -361,13 +399,30 @@ export class Runloop extends Core.APIClient {
361
399
baseURL: baseURL||`https://api.runloop.ai`,
362
400
};
363
401
402
+
// `httpAgent` (a Node `http.Agent`) does not apply to the HTTP/2 transport —
403
+
// undici manages its own dispatcher and has no `http.Agent` concept. Warn once
404
+
// instead of silently ignoring it. (Skipped when a custom `fetch` supersedes
0 commit comments