HttpClientConfig class provides typed, immutable configuration for the HTTP client. Every setting has a sensible default, so you only need to specify what you want to change.
Configuration Options
The constructor accepts the following parameters:| Option | Type | Default | Description |
|---|---|---|---|
driver | string | 'curl' | Which driver to use (curl, guzzle, symfony) |
connectTimeout | int | 3 | Maximum seconds to wait for connection establishment |
requestTimeout | int | 30 | Maximum seconds for the entire request-response cycle |
idleTimeout | int | -1 | Maximum seconds between data packets (-1 disables) |
streamChunkSize | int | 256 | Bytes per chunk when streaming responses |
streamHeaderTimeout | int | 5 | Seconds to wait for the initial response headers during streaming |
failOnError | bool | false | Throw exceptions on 4xx/5xx responses |
Understanding Timeouts
Getting timeouts right is critical for production reliability:- connectTimeout controls how long the client waits to establish a TCP connection. Set this low (1-3 seconds) for services that should respond quickly. Set it higher (5-10 seconds) for services behind slow DNS or distant networks.
- requestTimeout is the maximum total time for the request, from connection initiation to receiving the complete response. For quick API calls, 10-30 seconds is typical. For LLM inference or large file downloads, you may need 60-300 seconds.
-
idleTimeout applies to the gap between data packets. Setting this to
-1disables it, which is appropriate for long-lived streaming connections. For non-streaming requests, a value like30seconds catches stalled connections. -
streamHeaderTimeout is specific to streaming: it controls how long to wait for the first response headers before giving up. This is separate from
connectTimeoutbecause some APIs take time to start generating content.
Using Config with the Builder
Pass your config to the builder to create a fully configured client:Presets
HttpClientConfig ships with YAML preset files for common driver configurations. Use fromPreset() to load one by name:
curl, guzzle, symfony, http-ollama.
The HttpClient facade offers a shorthand:
DSN Strings
For environments where configuration comes from environment variables or strings, you can use DSN format:failOnError, and strings for driver.
Overriding an Existing Config
ThewithOverrides() method creates a new config from an existing one with selective changes:
Creating Config from Arrays
When loading configuration from external sources (files, environment, etc.), use thefromArray() factory:
Debug Configuration
TheDebugConfig class controls what gets logged during HTTP interactions. It is separate from HttpClientConfig and is passed to the builder independently:
| Option | Default | Description |
|---|---|---|
httpEnabled | false | Master switch for debug output |
httpTrace | false | Dump HTTP trace information |
httpRequestUrl | true | Log the request URL |
httpRequestHeaders | true | Log request headers |
httpRequestBody | true | Log the request body |
httpResponseHeaders | true | Log response headers |
httpResponseBody | true | Log the response body |
httpResponseStream | true | Log streaming response data |
httpResponseStreamByLine | true | Log stream as complete lines vs. raw chunks |
EventSourceMiddleware with console and event listeners. You can also load presets from YAML files using DebugConfig::fromPreset('on').
Configuration Patterns
Different Profiles for Different Use Cases
Create distinct configs for different scenarios:Environment-Based Configuration
Adjust settings based on the runtime environment:See Also
- Changing Client — switch between drivers.
- Making Requests — construct and send requests.
- Handling Responses — read response data.