client = Stream(
api_key=api_key,
api_secret=api_secret,
max_conns_per_host=20,
idle_timeout=55.0,
connect_timeout=5.0,
request_timeout=20.0,
)Connection pooling
Every backend SDK ships with HTTP connection pooling configured by default. The SDK emits one INFO-level log on client construction listing the effective values so you can verify your configuration.
Defaults
| Setting | Default | What it does |
|---|---|---|
| Max connections per host | 5 | Upper bound on concurrent TCP connections to a single host. |
| Idle timeout | 55 s | Closes a connection that has been idle for this duration. |
| Connect timeout | 10 s | Caps the TCP + TLS handshake. |
| Request timeout | 30 s | Default per-call deadline from request send to full response. Override per call. |
| Keep-alive | always on | HTTP persistent connection reuse. Not user-tunable. |
Tune the knobs
Pass the four knobs at client construction.
Per-call request timeout
Override the request timeout for a single call without rebuilding the client.
import httpx
response = client.get_app(timeout=httpx.Timeout(5.0))Bring your own HTTP client
When you pass a pre-built HTTP client, the SDK uses it as-is and applies none of the four knobs above. You own all transport behavior, including timeouts, retries, and response decompression.
import httpx
client = Stream(api_key=api_key, api_secret=api_secret, http_client=httpx.Client(timeout=10.0))SDK-specific notes
-
Node.js: the Node SDK uses the built-in Fetch API, whose default connection pool has no cap on maximum connections. To cap it, or to change any other transport setting, install the
undicilibrary and pass your ownAgentto the client:import { Agent } from "undici"; const client = new StreamClient(apiKey, apiSecret, { agent: new Agent({ connections: 100 }), }); -
PHP:
maxConnsPerHostandidleTimeoutare enforced via libcurl's persistent multi-handle pool (CURLMOPT_MAX_HOST_CONNECTIONSandCURLOPT_MAXLIFETIME_CONN). They take effect only when the SDK client is reused across requests within a single PHP process: long-running runtimes such as Swoole, RoadRunner, ReactPHP, and CLI daemons. Instantiate the SDK client once and reuse it. Under PHP-FPM (and one-shot CLI scripts) the PHP process exits at the end of each request, so there is no cross-request pool to size; the per-call request and connect timeouts still apply.idleTimeoutrequires libcurl 7.80.0 (Nov 2021) or later. -
Ruby: pooling relies on the
net_http_persistentFaraday adapter. If a customfaraday_adapter:you pass cannot be configured, the SDK logs a warning and falls back to Faraday's default (non-pooling) adapter; the INFO log on construction reports the effective adapter. -
Java: the environment variables
STREAM_API_TIMEOUTandSTREAM_API_CONNECTION_MAX_AGE(and their system-property equivalentsio.getstream.timeoutandio.getstream.connection.maxAge) still take effect and are folded into the default options. -
.NET: on the escape-hatch path the SDK does not configure gzip decompression on your handler. Enable
AutomaticDecompression = DecompressionMethods.GZipon your ownSocketsHttpHandlerif you need it.