Client Configuration

Stream's server-side SDKs ship with default HTTP settings designed for typical use. For high-traffic applications or specific network environments, you may need to tune these settings.

Default Settings

SDKRequest TimeoutConnect TimeoutConnection PoolIdle TimeoutKeep-AliveRetries
Node3s-Default (fetch/Undici)-EnabledNone
Python6s-10 per host (httpx)-EnabledNone
Go6s-~100 idle (http.Transport)90sEnabledNone
Java10s-5 idle connections (OkHttp)59sEnabledNone
PHP30s10sDefault (Guzzle)-Enabled3x on 429
Ruby30s-Default (Faraday)-Enabled3x exponential
.NET100s-Managed (SocketsHttpHandler)-EnabledNone

Customizing Settings

Node

const { Agent } = require("undici");

const client = new StreamClient("YOUR_API_KEY", "YOUR_API_SECRET", {
  timeout: 10000, // Request timeout in milliseconds
  agent: new Agent({
    keepAliveTimeout: 30000, // Keep-alive timeout in ms
    keepAliveMaxTimeout: 60000, // Max keep-alive timeout in ms
    connections: 50, // Max concurrent connections per host
    pipelining: 1, // HTTP pipelining
  }),
});
OptionTypeDefaultDescription
timeoutnumber3000Request timeout in milliseconds.
agentAgentDefaultCustom Undici agent for connection pooling and keep-alive tuning.

Python

client = Stream(
    api_key="YOUR_API_KEY",
    api_secret="YOUR_API_SECRET",
    timeout=10.0,  # Request timeout in seconds
)
ParameterTypeDefaultDescription
timeoutfloat6.0Request timeout in seconds.

The Python SDK uses httpx.Client internally with a pool of 10 connections per host. For advanced pooling, extend the base client with a custom httpx.Client.

Go

// Create HTTP client with persistent connections and tuned settings
transport := &http.Transport{
    DialContext: (&net.Dialer{
        Timeout:   30 * time.Second,
        KeepAlive: 30 * time.Second,
    }).DialContext,
    MaxIdleConns:        100,
    MaxIdleConnsPerHost: 100,
    IdleConnTimeout:     90 * time.Second,
    TLSHandshakeTimeout: 10 * time.Second,
}

httpClient := &http.Client{
    Transport: transport,
    Timeout:   30 * time.Second,
}

client := getstream.NewStream("YOUR_API_KEY", "YOUR_API_SECRET",
    getstream.WithTimeout(30 * time.Second),
    getstream.WithHTTPClient(httpClient),
)
OptionDefaultDescription
WithTimeout(duration)6sRequest timeout.
WithHTTPClient(client)Default http.ClientCustom HTTP client with full transport control.
WithLogger(logger)Default loggerCustom logger for debugging.

Transport settings:

SettingDefaultRecommendedDescription
DialContext.Timeout30s30sTCP connection establishment timeout.
DialContext.KeepAlive30s30sTCP keep-alive probe interval.
MaxIdleConns100100-200Max idle connections across all hosts.
MaxIdleConnsPerHost250-100Max idle connections per host. Increase for high throughput.
IdleConnTimeout90s90sHow long idle connections stay in the pool.
TLSHandshakeTimeout10s10sTLS handshake timeout.

Java

// Via properties
Properties props = new Properties();
props.put("io.getstream.apiKey", "YOUR_API_KEY");
props.put("io.getstream.apiSecret", "YOUR_API_SECRET");
props.put("io.getstream.timeout", "15000");  // Request timeout in milliseconds

var client = new StreamSDKClient(props);
PropertyEnv VariableDefaultDescription
io.getstream.timeoutSTREAM_API_TIMEOUT10000Request timeout in milliseconds (OkHttp callTimeout).

The Java SDK uses OkHttp with a connection pool of 5 idle connections and 59-second idle timeout. For custom pooling, provide a configured StreamHTTPClient instance.

PHP

use GuzzleHttp\Client as GuzzleClient;

// Custom Guzzle client with tuned settings
$httpClient = new GuzzleClient([
    'timeout' => 15,           // Request timeout in seconds
    'connect_timeout' => 5,    // Connection timeout in seconds
]);

$client = ClientBuilder::apiKey('YOUR_API_KEY')
    ->apiSecret('YOUR_API_SECRET')
    ->httpClient($httpClient)
    ->build();
SettingDefaultDescription
timeout30sRequest timeout in seconds.
connect_timeout10sTCP connection timeout in seconds.
Retry on 4293 attemptsAutomatic exponential backoff with jitter on rate limit responses.

Ruby

client = GetStream::Client.new(
  api_key: "YOUR_API_KEY",
  api_secret: "YOUR_API_SECRET",
  timeout: 15,  # Request timeout in seconds
)
ParameterDefaultDescription
timeout30sRequest timeout in seconds.
Retry3 attemptsExponential backoff (0.05s base, 2x factor, 0.5 randomness).

.NET

// The .NET SDK uses HttpClient with framework defaults.
// For production tuning, configure via IHttpClientFactory:
builder.Services.AddHttpClient("stream", client =>
{
    client.Timeout = TimeSpan.FromSeconds(15);
})
.ConfigurePrimaryHttpMessageHandler(() => new SocketsHttpHandler
{
    PooledConnectionLifetime = TimeSpan.FromMinutes(2),
    PooledConnectionIdleTimeout = TimeSpan.FromMinutes(1),
    MaxConnectionsPerServer = 50,
});
SettingDefaultDescription
Timeout100s.NET HttpClient framework default.
PooledConnectionLifetimeUnlimitedHow long a connection lives before being replaced.
MaxConnectionsPerServerUnlimitedMax connections per server.

Recommendations for High-Traffic Applications

  • Increase MaxIdleConnsPerHost (Go) or equivalent — the default of 2 per host is too low for high-throughput moderation workloads.
  • Set explicit timeouts — don't rely on framework defaults (especially .NET's 100s default). 10-30 seconds is a good range for moderation API calls.
  • Enable connection reuse — all SDKs enable keep-alive by default. Avoid creating new client instances per request.
  • Monitor for connection exhaustion — if you see connection errors under load, increase pool sizes.
  • Use a single client instance — instantiate the Stream client once and reuse it across your application. All SDKs are thread-safe / goroutine-safe.